-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Add .predict function to optimizer
#593
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
Open
till-m
wants to merge
1
commit into
bayesian-optimization:master
Choose a base branch
from
till-m:predict-fct
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+332
−47
Open
Changes from all commits
Commits
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
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
predict(): tighten input validation, clarify typing/docs, and guard std vs cov
A few points here:
Invalid
paramstypes lead toUnboundLocalError.If
paramsis neitherdictnorlist,params_array/single_paramare never set and you’ll get an unhelpful runtime error. Consider explicitly validating and raising aTypeError:Return type annotation doesn’t match behavior.
The function sometimes returns just
mean(float /NDArray) and sometimes a(mean, std_or_cov)tuple. The annotation-> tuple[...]is misleading for callers and type checkers. Consider something like:or using
typing.overloadfor the main common combinations.Docstring default for
return_stdis wrong.The signature uses
return_std=False, but the docstring saysoptional(default=True). That will confuse users. Please fix the docstring tooptional(default=False).return_stdandreturn_covshould be mutually exclusive.GaussianProcessRegressor.predictonly allows one ofreturn_stdorreturn_covto beTrueat a time; otherwise it raises.It would be clearer to check upfront and raise a user-facing
ValueError:Shape handling vs. list-of-one semantics.
For
paramsgiven as a single dict you correctly return scalars (or scalar-like) when possible viasingle_param=True. Forparamsas a list with a single element (e.g.[{"p1": 0, "p2": 0}]),single_paramisFalsesomean/std_or_covstay 1D arrays. Several new tests callpredict([point])and then do scalar-style checks likenp.isclose(means, 0, ...)orstds < 0.02, which will raiseValueErrorifmeans/stdsare arrays. You probably want either:.item(), orparamsis a list of length 1, treat it like a single param (single_param=True) sopredict([point])behaves likepredict(point)in terms of scalar vs array output.Whichever you decide, aligning implementation, tests, and docstring explicitly around “single dict vs list, including length-1 lists” will avoid confusing shape bugs.
Minor: handling of
single_paramwithreturn_cov.When
return_cov=Trueandparamsis a single dict,std_or_covstarts as a(1, 1)covariance matrix and becomes(1,)afterstd_or_cov = std_or_cov[0]. If you intend a scalar variance for a single point, consider also unwrapping the remaining dimension to a float for the single-parameter case, or documenting that you return a 1‑element array for covariance.I need to verify the concerns in the review comment against the actual codebase. Let me gather information:
Length of output: 3434
🏁 Script executed:
Length of output: 30
🏁 Script executed:
Length of output: 279
🏁 Script executed:
Length of output: 462
🏁 Script executed:
Length of output: 779
I need to check the test file and verify the GP behavior:
🏁 Script executed:
Length of output: 3252
🏁 Script executed:
Length of output: 1468
🏁 Script executed:
Length of output: 660
🏁 Script executed:
Length of output: 0
🏁 Script executed:
Length of output: 0
I need to verify the mutual exclusivity behavior with sklearn's GaussianProcessRegressor:
🌐 Web query:
💡 Result:
Yes — they are mutually exclusive. The docs state the predict method may return the mean and optionally either the standard deviation (return_std=True) or the joint covariance (return_cov=True), and "at most one of the two can be requested." [1][2]
Sources:
predict(): fix input validation, return type annotation, docstring, and std/cov mutual exclusivity; resolve shape handling ambiguity
Several issues require fixes:
Invalid
paramstypes lead toUnboundLocalError.If
paramsis neitherdictnorlist,params_arrayandsingle_paramare never set. Add anelseclause:Return type annotation is incorrect.
Line 180 declares
-> tuple[...]but line 245 returns justmean(non-tuple) whenreturn_stdandreturn_covare bothFalse. Fix to:Docstring default for
return_stdcontradicts signature.Line 188 says
optional(default=True)but line 179 hasreturn_std=False. Fix docstring tooptional(default=False).return_stdandreturn_covare mutually exclusive but not validated.sklearn's GaussianProcessRegressor allows at most one of return_std or return_cov to be requested. Add upfront validation:
Shape handling for single-element lists is ambiguous.
Tests at lines 628–642 call
predict([single_point])with scalar assertions likenp.isclose(means, 0)andstds < 0.02, which fail if the output is an array. Yet lines 664–667 treat the same call as returning an array withlen(means) == 1andmeans[0]indexing. Clarify whetherpredict([point])should:.item()), orAlign implementation, docstring, and tests once decided.
🤖 Prompt for AI Agents