Skip to content

Commit

Permalink
Revert "testing equivalence of mixed gp and single gp with custom ker…
Browse files Browse the repository at this point in the history
…nel"

This reverts commit 4a2a547.
  • Loading branch information
e-dorigatti committed Dec 19, 2024
1 parent 01a01e1 commit 1cd2776
Showing 1 changed file with 0 additions and 89 deletions.
89 changes: 0 additions & 89 deletions tests/bofire/surrogates/test_gps.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
AdditiveKernel,
HammingDistanceKernel,
MaternKernel,
MultiplicativeKernel,
RBFKernel,
ScaleKernel,
)
Expand Down Expand Up @@ -618,91 +617,3 @@ def test_MixedSingleTaskGPModel_mordred(kernel, scaler, output_scaler):
model2.loads(dump)
preds2 = model2.predict(experiments.iloc[:-1])
assert_frame_equal(preds, preds2)


def test_SingleTaskGP_with_categoricals_is_equivalent_to_MixedSingleTaskGP():
inputs = Inputs(
features=[
ContinuousInput(
key=f"x_{i+1}",
bounds=(-4, 4),
)
for i in range(2)
]
+ [
CategoricalInput(key="x_cat_1", categories=["mama", "papa"]),
CategoricalInput(key="x_cat_2", categories=["cat", "dog"]),
]
)
outputs = Outputs(features=[ContinuousOutput(key="y")])
experiments = inputs.sample(n=10, seed=194387)
experiments.eval("y=((x_1**2 + x_2 - 11)**2+(x_1 + x_2**2 -7)**2)", inplace=True)
experiments.loc[experiments.x_cat_1 == "mama", "y"] *= 5.0
experiments.loc[experiments.x_cat_1 == "papa", "y"] /= 2.0
experiments.loc[experiments.x_cat_2 == "cat", "y"] *= -2.0
experiments.loc[experiments.x_cat_2 == "dog", "y"] /= -5.0
experiments["valid_y"] = 1

gp_data = SingleTaskGPSurrogate(
inputs=inputs,
outputs=outputs,
kernel=AdditiveKernel( # use the same kernel as botorch.models.MixedSingleTaskGP
kernels=[
ScaleKernel(
base_kernel=HammingDistanceKernel(
ard=True,
features=["x_cat_1", "x_cat_2"],
)
),
ScaleKernel(
base_kernel=RBFKernel(
ard=True,
lengthscale_prior=HVARFNER_LENGTHSCALE_PRIOR(),
features=[f"x_{i+1}" for i in range(2)],
)
),
ScaleKernel(
base_kernel=MultiplicativeKernel(
kernels=[
HammingDistanceKernel(
ard=True,
features=["x_cat_1", "x_cat_2"],
),
RBFKernel(
ard=True,
lengthscale_prior=HVARFNER_LENGTHSCALE_PRIOR(),
features=[f"x_{i+1}" for i in range(2)],
),
]
)
),
]
),
)

gp_mapped = surrogates.map(gp_data)
gp_mapped.fit(experiments)
pred = gp_mapped.predict(experiments)
single_task_gp_mse = ((pred["y_pred"] - experiments["y"]) ** 2).mean()
assert single_task_gp_mse < 3.5

model = MixedSingleTaskGPSurrogate(
inputs=inputs,
outputs=outputs,
input_preprocessing_specs={
"x_cat_1": CategoricalEncodingEnum.ONE_HOT,
"x_cat_2": CategoricalEncodingEnum.ONE_HOT,
},
continuous_kernel=RBFKernel(
ard=True,
lengthscale_prior=HVARFNER_LENGTHSCALE_PRIOR(),
),
categorical_kernel=HammingDistanceKernel(ard=True),
)
model = surrogates.map(model)
model.fit(experiments)
pred = model.predict(experiments)
mixed_single_task_gp_mse = ((pred["y_pred"] - experiments["y"]) ** 2).mean()
assert mixed_single_task_gp_mse < 3.5

assert abs(single_task_gp_mse - mixed_single_task_gp_mse) < 0.005

0 comments on commit 1cd2776

Please sign in to comment.