-
Notifications
You must be signed in to change notification settings - Fork 47
Ship PairwiseGP from Botorch into BoFire #768
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
24 commits
Select commit
Hold shift + click to select a range
457ab02
vanilla claude stuff
jduerholt 6821f42
fix(surrogates): noise_prior and noise_constraint on SingleTaskGPSurr…
R-M-Lee af1404c
roundtrip for bug
jduerholt 7e7b003
generalize
jduerholt 2aad969
add priors, some refactor
Jimbo994 f9a01e1
fixes and addittions
Jimbo994 2f6541e
add tests
Jimbo994 65b7152
update mutltiask gp to botorch defaults
jduerholt 45fb402
Merge remote-tracking branch 'origin/main' into feature/pairwise
Jimbo994 73481ac
added docs
Jimbo994 efa3a6c
add to changelog
Jimbo994 45d5278
fix hypeopt
jduerholt 27a5538
some changes
jduerholt 92c648d
cleaning up the api
jduerholt bdad654
make test less flaky
jduerholt 7d81545
fix seruialization
jduerholt 6bcab72
changelog updated
jduerholt 2b381c0
Merge branch 'hotfix/noiseprior' into feature/pairwise
Jimbo994 2b11a81
Address PR #768 review comments (#4, #6, #7, #9)
Jimbo994 bb4d1fd
Wire features_to_idx_mapper for PairwiseGPSurrogate (#5)
Jimbo994 5485c0c
Merge remote-tracking branch 'origin/main' into feature/pairwise
Jimbo994 b478663
Hoist engineered_features to BotorchSurrogate; share get_feature_indi…
Jimbo994 897abd0
rename validators
Jimbo994 e912190
Merge remote-tracking branch 'origin/main' into feature/pairwise
Jimbo994 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -162,3 +162,5 @@ notebook_test_stats.csv | |
| **/*.quarto_ipynb | ||
|
|
||
| **/.jupyter_cache | ||
|
|
||
| scripts/* | ||
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 |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| from typing import Literal | ||
|
|
||
| from pydantic import PositiveFloat, model_validator | ||
|
|
||
| from bofire.data_models.priors.prior import Prior | ||
|
|
||
|
|
||
| class SmoothedBoxPrior(Prior): | ||
| """A smoothed approximation of a uniform prior. | ||
|
|
||
| .. math:: | ||
|
|
||
| \begin{equation*} | ||
| B = {x: a_i <= x_i <= b_i} | ||
| d(x, B) = min_{x' in B} |x - x'| | ||
| pdf(x) \\sim exp(- d(x, B)**2 / sqrt(2 * sigma^2)) | ||
| \\end{equation*} | ||
|
|
||
| Attributes: | ||
| lower_bound: lower bound of the uniform prior | ||
| upper_bound: upper bound of the uniform prior | ||
| sigma: related to pdf(x) | ||
|
|
||
| """ | ||
|
|
||
| type: Literal["SmoothedBoxPrior"] = "SmoothedBoxPrior" | ||
| lower_bound: float | ||
| upper_bound: float | ||
| sigma: PositiveFloat = 0.01 | ||
|
|
||
| @model_validator(mode="after") | ||
| def validate_bounds(self): | ||
| if self.lower_bound >= self.upper_bound: | ||
| raise ValueError( | ||
| "The lower bound must be less than the upper bound for an interval." | ||
| ) | ||
| return self |
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 |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| from typing import Literal, Type | ||
|
|
||
| from pydantic import Field, model_validator | ||
|
|
||
| from bofire.data_models.features.api import AnyOutput, ContinuousOutput | ||
| from bofire.data_models.kernels.api import AnyKernel, RBFKernel, ScaleKernel | ||
| from bofire.data_models.priors.api import ( | ||
| PAIRWISEGP_LENGTHSCALE_CONSTRAINT, | ||
| PAIRWISEGP_LENGTHSCALE_PRIOR, | ||
| PAIRWISEGP_OUTPUTSCALE_CONSTRAINT, | ||
| PAIRWISEGP_OUTPUTSCALE_PRIOR, | ||
| ) | ||
| from bofire.data_models.surrogates.botorch import BotorchSurrogate | ||
| from bofire.data_models.surrogates.scaler import AnyScaler, Normalize | ||
| from bofire.data_models.surrogates.trainable import TrainableSurrogate | ||
|
|
||
|
|
||
| class PairwiseGPSurrogate(BotorchSurrogate, TrainableSurrogate): | ||
| """Pairwise Gaussian Process surrogate built on top of BoTorch's PairwiseGP. | ||
|
|
||
| Fits a latent utility function from binary winner/loser pair labels. The | ||
| `preferences` DataFrame references rows of the standard BoFire `experiments` | ||
| DataFrame by `labcode`; the single output feature represents the latent | ||
| utility inferred from those comparisons. | ||
|
|
||
| Attributes: | ||
| likelihood: The pairwise likelihood linking latent-utility differences | ||
| to preference probabilities -- ``"probit"`` (Gaussian comparison | ||
| noise, BoTorch's default) or ``"logit"`` (logistic noise, i.e. the | ||
| Bradley-Terry model). | ||
| """ | ||
|
|
||
| type: Literal["PairwiseGPSurrogate"] = "PairwiseGPSurrogate" | ||
|
|
||
| kernel: AnyKernel = Field( | ||
| default_factory=lambda: ScaleKernel( | ||
| base_kernel=RBFKernel( | ||
| ard=True, | ||
| lengthscale_prior=PAIRWISEGP_LENGTHSCALE_PRIOR(), | ||
| lengthscale_constraint=PAIRWISEGP_LENGTHSCALE_CONSTRAINT(), | ||
| ), | ||
| outputscale_prior=PAIRWISEGP_OUTPUTSCALE_PRIOR(), | ||
| outputscale_constraint=PAIRWISEGP_OUTPUTSCALE_CONSTRAINT(), | ||
| ) | ||
| ) | ||
| scaler: AnyScaler = Field(default_factory=Normalize) | ||
| likelihood: Literal["probit", "logit"] = "probit" | ||
|
|
||
| @classmethod | ||
| def is_output_implemented(cls, my_type: Type[AnyOutput]) -> bool: | ||
| return isinstance(my_type, type(ContinuousOutput)) | ||
|
|
||
| @model_validator(mode="after") | ||
|
jduerholt marked this conversation as resolved.
|
||
| def validate_single_output(self): | ||
| if len(self.outputs) != 1: | ||
| raise ValueError( | ||
| "PairwiseGPSurrogate supports exactly one output (the latent utility)." | ||
| ) | ||
| return self | ||
|
|
||
| @model_validator(mode="after") | ||
|
jduerholt marked this conversation as resolved.
|
||
| def validate_scalekernel(self): | ||
| if not isinstance(self.kernel, ScaleKernel): | ||
| raise ValueError( | ||
| "PairwiseGPSurrogate.kernel must be a ScaleKernel " | ||
| "(BoTorch's PairwiseGP requires the covariance module to be a ScaleKernel)." | ||
| ) | ||
| return self | ||
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.
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.