-
Notifications
You must be signed in to change notification settings - Fork 27
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
add polynomial kernel #298
Merged
dlinzner-bcs
merged 10 commits into
main
from
286-add-surrogate-models-that-can-extrapolate
Oct 6, 2023
+115
−0
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e3fe5e8
add polynomial kernel
342c3bc
add polynomial kernel
300c656
add polynomial kernel
1092002
add polynomial kernel
4ea3a08
add quadratic surrogate
2a2baec
adding linear kernel not necessary
c95f26c
adding linear kernel not necessary
6e0fbc9
adding linear kernel not necessary
26be3f6
fix test
dab5f7f
change kernel tzpe hint
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 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 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 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 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,21 @@ | ||
from typing import Literal | ||
|
||
from pydantic import Field | ||
|
||
from bofire.data_models.kernels.api import ( | ||
PolynomialKernel, | ||
) | ||
from bofire.data_models.priors.api import BOTORCH_NOISE_PRIOR, AnyPrior | ||
|
||
# from bofire.data_models.strategies.api import FactorialStrategy | ||
from bofire.data_models.surrogates.botorch import BotorchSurrogate | ||
from bofire.data_models.surrogates.scaler import ScalerEnum | ||
from bofire.data_models.surrogates.trainable import TrainableSurrogate | ||
|
||
|
||
class QuadraticSurrogate(BotorchSurrogate, TrainableSurrogate): | ||
type: Literal["QuadraticSurrogate"] = "QuadraticSurrogate" | ||
|
||
kernel: PolynomialKernel = Field(default_factory=lambda: PolynomialKernel(power=2)) | ||
noise_prior: AnyPrior = Field(default_factory=lambda: BOTORCH_NOISE_PRIOR()) | ||
scaler: ScalerEnum = ScalerEnum.NORMALIZE |
This file contains 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 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 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 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,43 @@ | ||
import numpy as np | ||
from pandas.testing import assert_frame_equal | ||
|
||
import bofire.surrogates.api as surrogates | ||
from bofire.data_models.domain.api import Inputs, Outputs | ||
from bofire.data_models.features.api import ContinuousInput, ContinuousOutput | ||
from bofire.data_models.kernels.api import PolynomialKernel | ||
from bofire.data_models.surrogates.api import QuadraticSurrogate | ||
|
||
|
||
def test_QuadraticSurrogate(): | ||
N_EXPERIMENTS = 10 | ||
|
||
inputs = Inputs( | ||
features=[ | ||
ContinuousInput(key="a", bounds=(0, 40)), | ||
ContinuousInput(key="b", bounds=(20, 60)), | ||
] | ||
) | ||
outputs = Outputs(features=[ContinuousOutput(key="c")]) | ||
|
||
experiments = inputs.sample(N_EXPERIMENTS) | ||
experiments["c"] = ( | ||
experiments["a"] * 2.2 | ||
+ experiments["b"] * -0.05 | ||
+ experiments["b"] | ||
+ np.random.normal(loc=0, scale=5, size=N_EXPERIMENTS) | ||
) | ||
experiments["valid_c"] = 1 | ||
|
||
surrogate_data = QuadraticSurrogate(inputs=inputs, outputs=outputs) | ||
surrogate = surrogates.map(surrogate_data) | ||
|
||
assert isinstance(surrogate, surrogates.SingleTaskGPSurrogate) | ||
assert isinstance(surrogate.kernel, PolynomialKernel) | ||
|
||
# check dump | ||
surrogate.fit(experiments=experiments) | ||
preds = surrogate.predict(experiments) | ||
dump = surrogate.dumps() | ||
surrogate.loads(dump) | ||
preds2 = surrogate.predict(experiments) | ||
assert_frame_equal(preds, preds2) |
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.
Rather
PolynomialSurrogate
?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.
This specific one has power=2. So its quadratic.