-
Notifications
You must be signed in to change notification settings - Fork 77
Adaptive hyper-prior: CHENKernelFactory #752
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 9 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
8e08f83
Add CHENKernelFactory draft
emiliencgm fe1e699
Import CHENKernelFactory in __init__.py
maxfleck b2c2361
Update CONTRIBUTORS.md
tstuyver 4e81b46
Apply ruff formatting
AdrianSosic 1ad28ae
Finalize draft
AdrianSosic 6eb566e
Add proper paper references
AdrianSosic 55c3852
Update GaussianProcessPreset enum
AdrianSosic c43d73b
Update CHANGELOG.md
AdrianSosic ff10272
Apply minor cosmetics
AdrianSosic 344263a
Hardcode mean and likelihood for CHEN preset
AdrianSosic 46d3749
Add permalink to EDBO prior settings
AdrianSosic f35c77b
Ignore chemrxiv link for linkcheck
AdrianSosic c16a6aa
Update linkcheck ignore for EDBO
AdrianSosic 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
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,77 @@ | ||
| """Preset for adaptive kernel hyperpriors proposed by :cite:p:`Chen2026`.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import gc | ||
| import math | ||
| from typing import TYPE_CHECKING, ClassVar | ||
|
|
||
| from attrs import define, field | ||
| from typing_extensions import override | ||
|
|
||
| from baybe.kernels.basic import MaternKernel | ||
| from baybe.kernels.composite import ScaleKernel | ||
| from baybe.parameters.categorical import TaskParameter | ||
| from baybe.parameters.selectors import ( | ||
| ParameterSelectorProtocol, | ||
| TypeSelector, | ||
| to_parameter_selector, | ||
| ) | ||
| from baybe.priors.basic import GammaPrior | ||
| from baybe.surrogates.gaussian_process.components.kernel import ( | ||
| _PureKernelFactory, | ||
| ) | ||
| from baybe.surrogates.gaussian_process.presets.baybe import ( | ||
| BayBELikelihoodFactory, | ||
| BayBEMeanFactory, | ||
| ) | ||
|
|
||
| if TYPE_CHECKING: | ||
| from torch import Tensor | ||
|
|
||
| from baybe.kernels.base import Kernel | ||
| from baybe.searchspace.core import SearchSpace | ||
|
|
||
|
|
||
| @define | ||
| class CHENKernelFactory(_PureKernelFactory): | ||
| """A factory providing adaptive hyperprior kernels as proposed by :cite:p:`Chen2026`.""" # noqa: E501 | ||
|
|
||
| _uses_parameter_names: ClassVar[bool] = True | ||
| # See base class. | ||
|
|
||
| parameter_selector: ParameterSelectorProtocol | None = field( | ||
| factory=lambda: TypeSelector([TaskParameter], exclude=True), | ||
| converter=to_parameter_selector, | ||
| ) | ||
| # TODO: Reuse base attribute (https://github.com/python-attrs/attrs/pull/1429) | ||
|
|
||
| @override | ||
| def _make( | ||
| self, searchspace: SearchSpace, train_x: Tensor, train_y: Tensor | ||
| ) -> Kernel: | ||
| lengthscale = 0.4 * math.sqrt(train_x.shape[-1]) + 4.0 | ||
| lengthscale_prior = GammaPrior(2.0 * lengthscale, 2.0) | ||
| lengthscale_initial_value = lengthscale | ||
| outputscale_prior = GammaPrior(1.0 * lengthscale, 1.0) | ||
| outputscale_initial_value = lengthscale | ||
|
AdrianSosic marked this conversation as resolved.
|
||
|
|
||
| return ScaleKernel( | ||
| MaternKernel( | ||
| nu=2.5, | ||
| lengthscale_prior=lengthscale_prior, | ||
| lengthscale_initial_value=lengthscale_initial_value, | ||
| parameter_names=self.get_parameter_names(searchspace), | ||
| ), | ||
| outputscale_prior=outputscale_prior, | ||
| outputscale_initial_value=outputscale_initial_value, | ||
| ) | ||
|
|
||
|
|
||
| # Collect leftover original slotted classes processed by `attrs.define` | ||
| gc.collect() | ||
|
|
||
| # Aliases for generic preset imports | ||
| PresetKernelFactory = CHENKernelFactory | ||
| PresetMeanFactory = BayBEMeanFactory | ||
| PresetLikelihoodFactory = BayBELikelihoodFactory | ||
|
AdrianSosic marked this conversation as resolved.
Outdated
|
||
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,4 @@ | ||
| # References | ||
|
|
||
| ```{bibliography} | ||
| ``` |
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.
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.