-
Notifications
You must be signed in to change notification settings - Fork 77
GP Criterion #789
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
Open
AdrianSosic
wants to merge
11
commits into
dev/gp
Choose a base branch
from
feature/gp_criterion
base: dev/gp
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
GP Criterion #789
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
8679dba
Add configurable GP optimization criterion component
AdrianSosic d76d452
Fix circular import
AdrianSosic 15e9dbb
Update CHANGELOG.md
AdrianSosic 920dd88
Fix typing
AdrianSosic 887c6bc
Extend preset tests
AdrianSosic f213893
Make preset factory exports consistent instances with UPPER_CASE naming
AdrianSosic 79f3604
Drop unnecessary isinstance check
AdrianSosic 2f847b6
Rename Criterion to FitCriterion
AdrianSosic 19d6b3b
Make FitCriterion a BayBEGPComponent
AdrianSosic 0538b72
Rename LEAVE_ONE_OUT to LEAVE_ONE_OUT_PSEUDOLIKELIHOOD
AdrianSosic 4d41104
Rename criterion.py to fit_criterion.py
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
Some comments aren't visible on the classic Files Changed page.
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
46 changes: 46 additions & 0 deletions
46
baybe/surrogates/gaussian_process/components/fit_criterion.py
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,46 @@ | ||
| """Fitting criteria for the Gaussian process surrogate.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from enum import Enum | ||
| from typing import TYPE_CHECKING | ||
|
|
||
| if TYPE_CHECKING: | ||
| from gpytorch.likelihoods import Likelihood as GPyTorchLikelihood | ||
| from gpytorch.mlls import MarginalLogLikelihood | ||
| from gpytorch.models import GP as GPyTorchModel | ||
|
|
||
|
|
||
| class FitCriterion(Enum): | ||
| """Available fitting criteria for GP hyperparameter optimization.""" | ||
|
|
||
| MARGINAL_LOG_LIKELIHOOD = "MARGINAL_LOG_LIKELIHOOD" | ||
| """Exact marginal log-likelihood.""" | ||
|
|
||
| LEAVE_ONE_OUT_PSEUDOLIKELIHOOD = "LEAVE_ONE_OUT_PSEUDOLIKELIHOOD" | ||
| """Leave-one-out cross-validation pseudo-likelihood.""" | ||
|
|
||
| def to_gpytorch( | ||
| self, likelihood: GPyTorchLikelihood, model: GPyTorchModel | ||
| ) -> MarginalLogLikelihood: | ||
| """Create the corresponding GPyTorch MLL object.""" | ||
| import gpytorch | ||
|
|
||
| mll_class = { | ||
| FitCriterion.MARGINAL_LOG_LIKELIHOOD: gpytorch.ExactMarginalLogLikelihood, | ||
| FitCriterion.LEAVE_ONE_OUT_PSEUDOLIKELIHOOD: gpytorch.mlls.LeaveOneOutPseudoLikelihood, # noqa: E501 | ||
| }[self] | ||
| return mll_class(likelihood, model) | ||
|
|
||
|
|
||
| # Delayed import to avoid circular dependency | ||
| from baybe.surrogates.gaussian_process.components.generic import ( # noqa: E402 | ||
| GPComponentFactoryProtocol, | ||
| PlainGPComponentFactory, | ||
| ) | ||
|
|
||
| FitCriterionFactoryProtocol = GPComponentFactoryProtocol[FitCriterion] | ||
| """A protocol defining the interface for fit criterion factories.""" | ||
|
|
||
| PlainFitCriterionFactory = PlainGPComponentFactory[FitCriterion] | ||
| """A trivial factory that returns a fixed fit criterion.""" | ||
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
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.