-
Notifications
You must be signed in to change notification settings - Fork 15
Feat/forecast on date #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
915fa76
add test for date question
alex-costea fc6bc51
add date question forecasting
alex-costea 40f5ca2
add DateStringPercentile
alex-costea 853322d
fix
alex-costea 01e73a6
fix formatting
alex-costea d0793c2
fix for NumericDistribution.from_question
alex-costea 73ddbc2
timezone fix
alex-costea 5fbc003
fix for from_question
alex-costea f3b5100
nits
alex-costea 3562a73
Added hourly parsing and readable date distribution
CodexVeritas 09f8303
Updated uniform probability bot and moved date forecast function
CodexVeritas b6b1766
reorganized functions
CodexVeritas d4b5547
Date questions pulled in via run_on_tournament
CodexVeritas d3349c4
Added date support for researchonly bot
CodexVeritas 6012ba9
Fixed tests
CodexVeritas f4c05cc
Removed a redunant date question test
CodexVeritas 425862a
Incorporated final AI code review
CodexVeritas 9383935
Removed abstractclass
CodexVeritas 52a2104
Slight update in prompting - handle non chronological
CodexVeritas File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |
|
|
||
| import logging | ||
| from collections import Counter | ||
| from datetime import datetime, timezone | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| import numpy as np | ||
|
|
@@ -12,6 +13,7 @@ | |
|
|
||
| if TYPE_CHECKING: | ||
| from forecasting_tools.data_models.questions import ( | ||
| DateQuestion, | ||
| DiscreteQuestion, | ||
| NumericQuestion, | ||
| ) | ||
|
|
@@ -61,6 +63,25 @@ def validate_percentile(self: Percentile) -> Percentile: | |
| return self | ||
|
|
||
|
|
||
| class DatePercentile(BaseModel): | ||
| percentile: float = Field( | ||
| description="A number between 0 and 1 (e.g. '90% likelihood of AGI by 2040-01-01' translates to '0.9')", | ||
| ) | ||
| value: datetime = Field( | ||
| description="The date matching the percentile (e.g. '90% likelihood of AGI by 2040-01-01' translates to '2040-01-01')", | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think making it a datetime directly would work, because it's not an instance of BaseClass. |
||
|
|
||
| @model_validator(mode="after") | ||
| def validate_percentile(self: DatePercentile) -> DatePercentile: | ||
| if self.percentile < 0 or self.percentile > 1: | ||
| raise ValueError( | ||
| f"Percentile must be between 0 and 1, but was {self.percentile}" | ||
| ) | ||
| if np.isnan(self.percentile): | ||
| raise ValueError(f"Percentile must be a number, but was {self.percentile}") | ||
| return self | ||
|
|
||
|
|
||
| class NumericDistribution(BaseModel): | ||
| declared_percentiles: list[Percentile] | ||
| open_upper_bound: bool | ||
|
|
@@ -73,6 +94,7 @@ class NumericDistribution(BaseModel): | |
| ) | ||
| standardize_cdf: bool = True | ||
| strict_validation: bool = True | ||
| is_date: bool = False | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_percentiles(self: NumericDistribution) -> NumericDistribution: | ||
|
|
@@ -231,29 +253,42 @@ def _check_distribution_too_tall(self, cdf: list[Percentile]) -> None: | |
| def from_question( | ||
| cls, | ||
| percentiles: list[Percentile], | ||
| question: NumericQuestion, | ||
| question: NumericQuestion | DateQuestion, | ||
| standardize_cdf: bool | None = None, | ||
| ) -> NumericDistribution: | ||
| from forecasting_tools.data_models.questions import DateQuestion | ||
|
|
||
| is_date = isinstance(question, DateQuestion) | ||
|
|
||
| if is_date: | ||
| upper_bound_float: float = question.upper_bound.timestamp() | ||
| lower_bound_float: float = question.lower_bound.timestamp() | ||
| else: | ||
| upper_bound_float = question.upper_bound | ||
| lower_bound_float = question.lower_bound | ||
|
|
||
| if standardize_cdf is None: | ||
| return NumericDistribution( | ||
| declared_percentiles=percentiles, | ||
| open_upper_bound=question.open_upper_bound, | ||
| open_lower_bound=question.open_lower_bound, | ||
| upper_bound=question.upper_bound, | ||
| lower_bound=question.lower_bound, | ||
| upper_bound=upper_bound_float, | ||
| lower_bound=lower_bound_float, | ||
| zero_point=question.zero_point, | ||
| cdf_size=question.cdf_size, | ||
| is_date=is_date, | ||
| ) | ||
| else: | ||
| return NumericDistribution( | ||
| declared_percentiles=percentiles, | ||
| open_upper_bound=question.open_upper_bound, | ||
| open_lower_bound=question.open_lower_bound, | ||
| upper_bound=question.upper_bound, | ||
| lower_bound=question.lower_bound, | ||
| upper_bound=upper_bound_float, | ||
| lower_bound=lower_bound_float, | ||
| zero_point=question.zero_point, | ||
| cdf_size=question.cdf_size, | ||
| standardize_cdf=standardize_cdf, | ||
| is_date=is_date, | ||
| ) | ||
|
|
||
| def get_representative_percentiles( | ||
|
|
@@ -562,7 +597,9 @@ class NumericReport(ForecastReport): | |
|
|
||
| @classmethod | ||
| async def aggregate_predictions( | ||
| cls, predictions: list[NumericDistribution], question: NumericQuestion | ||
| cls, | ||
| predictions: list[NumericDistribution], | ||
| question: NumericQuestion | DateQuestion, | ||
| ) -> NumericDistribution: | ||
| assert predictions, "No predictions to aggregate" | ||
| cdfs = [prediction.get_cdf() for prediction in predictions] | ||
|
|
@@ -604,7 +641,13 @@ def make_readable_prediction(cls, prediction: NumericDistribution) -> str: | |
| ) | ||
| readable = "Probability distribution:\n" | ||
| for percentile in representative_percentiles: | ||
| readable += f"- {percentile.percentile:.2%} chance of value below {round(percentile.value,6)}\n" | ||
| if prediction.is_date: | ||
| formatted_value = datetime.fromtimestamp( | ||
| percentile.value, tz=timezone.utc | ||
| ).strftime("%Y-%m-%d %H:%M:%S UTC") | ||
| else: | ||
| formatted_value = str(round(percentile.value, 6)) | ||
| readable += f"- {percentile.percentile:.2%} chance of value below {formatted_value}\n" | ||
| return readable | ||
|
|
||
| async def publish_report_to_metaculus(self) -> None: | ||
|
|
@@ -639,3 +682,8 @@ async def publish_report_to_metaculus(self) -> None: | |
| class DiscreteReport(NumericReport): | ||
| question: DiscreteQuestion | ||
| prediction: NumericDistribution | ||
|
|
||
|
|
||
| class DateReport(NumericReport): | ||
| question: DateQuestion | ||
| prediction: NumericDistribution | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.