Skip to content

Commit 2d9ba0f

Browse files
committed
Do changes
1 parent d8eb2d3 commit 2d9ba0f

2 files changed

Lines changed: 27 additions & 13 deletions

File tree

baybe/surrogates/gaussian_process/core.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
from baybe.surrogates.gaussian_process.presets import (
4141
GaussianProcessPreset,
4242
)
43-
from baybe.surrogates.gaussian_process.presets.baybe import (
44-
BayBEFitCriterionFactory,
45-
BayBEKernelFactory,
46-
BayBELikelihoodFactory,
47-
BayBEMeanFactory,
43+
from baybe.surrogates.gaussian_process.presets.hvarfner import (
44+
FIT_CRITERION_FACTORY,
45+
KERNEL_FACTORY,
46+
LIKELIHOOD_FACTORY,
47+
MEAN_FACTORY,
4848
)
4949
from baybe.utils.boolean import strtobool
5050
from baybe.utils.conversion import to_string
@@ -115,7 +115,7 @@ def _mark_custom_kernel(
115115
value: Kernel | KernelFactoryProtocol, self: GaussianProcessSurrogate
116116
) -> Kernel | KernelFactoryProtocol:
117117
"""Mark the surrogate as using a custom kernel (for deprecation purposes)."""
118-
if type(value) is not BayBEKernelFactory:
118+
if type(value) is not type(KERNEL_FACTORY):
119119
self._custom_kernel = True
120120

121121
return value
@@ -152,7 +152,7 @@ class GaussianProcessSurrogate(Surrogate):
152152
Converter(_mark_custom_kernel, takes_self=True), # type: ignore[call-overload]
153153
partial(to_component_factory, component_type=GPComponentType.KERNEL),
154154
),
155-
factory=BayBEKernelFactory,
155+
default=KERNEL_FACTORY,
156156
validator=is_callable(),
157157
)
158158
"""The factory used to create the kernel for the Gaussian process.
@@ -165,7 +165,7 @@ class GaussianProcessSurrogate(Surrogate):
165165

166166
mean_factory: MeanFactoryProtocol = field(
167167
alias="mean_or_factory",
168-
factory=BayBEMeanFactory,
168+
default=MEAN_FACTORY,
169169
converter=partial(to_component_factory, component_type=GPComponentType.MEAN), # type: ignore[misc]
170170
validator=is_callable(),
171171
)
@@ -178,7 +178,7 @@ class GaussianProcessSurrogate(Surrogate):
178178

179179
likelihood_factory: LikelihoodFactoryProtocol = field(
180180
alias="likelihood_or_factory",
181-
factory=BayBELikelihoodFactory,
181+
default=LIKELIHOOD_FACTORY,
182182
converter=partial( # type: ignore[misc]
183183
to_component_factory, component_type=GPComponentType.LIKELIHOOD
184184
),
@@ -193,7 +193,7 @@ class GaussianProcessSurrogate(Surrogate):
193193

194194
fit_criterion_factory: FitCriterionFactoryProtocol = field(
195195
alias="fit_criterion_or_factory",
196-
factory=BayBEFitCriterionFactory,
196+
default=FIT_CRITERION_FACTORY,
197197
converter=partial( # type: ignore[misc]
198198
to_component_factory, component_type=GPComponentType.CRITERION
199199
),

baybe/surrogates/gaussian_process/presets/hvarfner.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,14 @@ class HvarfnerKernelFactory(_PureKernelFactory):
4747
def _make(
4848
self, searchspace: SearchSpace, objective: Objective, measurements: pd.DataFrame
4949
) -> Kernel | GPyTorchKernel:
50+
import math
51+
5052
from botorch.models.kernels.positive_index import PositiveIndexKernel
5153
from botorch.models.utils.gpytorch_modules import (
5254
get_covar_module_with_dim_scaled_prior,
5355
)
56+
from gpytorch.kernels import ScaleKernel as GPyTorchScaleKernel
57+
from gpytorch.priors import LogNormalPrior
5458

5559
parameter_names = self.get_parameter_names(searchspace)
5660

@@ -70,16 +74,27 @@ def _make(
7074
ard_num_dims=ard_num_dims, active_dims=active_dims
7175
)
7276

77+
# Wrap in ScaleKernel with Hvarfner-consistent LogNormal outputscale prior
78+
outputscale_prior = LogNormalPrior(
79+
loc=math.sqrt(2) + math.log(ard_num_dims) * 0.5,
80+
scale=math.sqrt(3),
81+
)
82+
scaled_kernel = GPyTorchScaleKernel(
83+
base_kernel,
84+
outputscale_prior=outputscale_prior,
85+
)
86+
scaled_kernel.outputscale = outputscale_prior.mode.detach().clone()
87+
7388
# Single-task case
7489
if (task_idx := searchspace.task_idx) is None:
75-
return base_kernel
90+
return scaled_kernel
7691

7792
index_kernel = PositiveIndexKernel(
7893
num_tasks=searchspace.n_tasks,
7994
rank=searchspace.n_tasks,
8095
active_dims=[task_idx],
8196
)
82-
return ICMKernelFactory(base_kernel, index_kernel)(
97+
return ICMKernelFactory(scaled_kernel, index_kernel)(
8398
searchspace, objective, measurements
8499
)
85100

@@ -113,7 +128,6 @@ class HvarfnerLikelihoodFactory(LikelihoodFactoryProtocol):
113128
def __call__(
114129
self, searchspace: SearchSpace, objective: Objective, measurements: pd.DataFrame
115130
) -> GPyTorchLikelihood:
116-
117131
if searchspace.n_tasks == 1:
118132
from botorch.models.utils.gpytorch_modules import (
119133
get_gaussian_likelihood_with_lognormal_prior,

0 commit comments

Comments
 (0)