CompositeSurrogate¶
- class baybe.surrogates.composite.CompositeSurrogate[source]¶
Bases:
SerialMixin,SurrogateProtocolA class for composing multi-target surrogates from single-target surrogates.
Public methods
__init__(surrogates)Method generated by attrs for class CompositeSurrogate.
fit(searchspace, objective, measurements)Fit the surrogate to training data in a given modelling context.
from_dict(dictionary)Create an object from its dictionary representation.
from_json(source, /)Create an object from its JSON representation.
from_replication(surrogate)Replicate a given single-target surrogate logic for multiple targets.
posterior(candidates)Compute the posterior for candidates in experimental representation.
posterior_stats(candidates[, stats])Create the botorch-ready representation of the fitted model.
to_dict()Create an object's dictionary representation.
to_json([sink, overwrite])Create an object's JSON representation.
Public attributes and properties
An index-based mapping from target names to single-target surrogates.
- __init__(surrogates: _SurrogateGetter)¶
Method generated by attrs for class CompositeSurrogate.
For details on the parameters, see Public attributes and properties.
- fit(searchspace: SearchSpace, objective: Objective, measurements: DataFrame)[source]¶
Fit the surrogate to training data in a given modelling context.
For details on the expected method arguments, see
baybe.recommenders.base.RecommenderProtocol().- Return type:
- classmethod from_json(source: str | Path | SupportsRead[str], /)¶
Create an object from its JSON representation.
- Parameters:
source (str | Path | SupportsRead[str]) –
The JSON source. Can be:
A string containing JSON content.
A file path or
Pathobject pointing to a JSON file.A file-like object with a
read()method.
- Raises:
ValueError – If
sourceis not one of the allowed types.- Return type:
_T
- Returns:
The reconstructed object.
- classmethod from_replication(surrogate: SurrogateProtocol)[source]¶
Replicate a given single-target surrogate logic for multiple targets.
- Return type:
- posterior(candidates: pd.DataFrame)[source]¶
Compute the posterior for candidates in experimental representation.
The (independent joint) posterior is represented as a collection of individual posterior models computed per target of the involved objective. For details, see
baybe.surrogates.base.Surrogate.posterior().- Return type:
PosteriorList
- posterior_stats(candidates: DataFrame, stats: Sequence[float | Literal['mean', 'std', 'var', 'mode']] = ('mean', 'std'))[source]¶
See
baybe.surrogates.base.Surrogate.posterior_stats().- Return type:
- to_botorch()[source]¶
Create the botorch-ready representation of the fitted model.
The
botorch.models.model.Modelcreated by this method needs to be configured such that it can be called with candidate points in computational representation, that is, input of the form as obtained viabaybe.searchspace.core.SearchSpace.transform().- Return type:
ModelList
- to_dict()¶
Create an object’s dictionary representation.
- Return type:
- Returns:
The dictionary representation of the object.
- to_json(sink: str | Path | SupportsWrite[str] | None = None, /, *, overwrite: bool = False, **kwargs: Any)¶
Create an object’s JSON representation.
- Parameters:
sink (str | Path | SupportsWrite[str] | None) –
The JSON sink. Can be:
None(only returns the JSON string).A file path or
Pathobject pointing to a location where to write the JSON content.A file-like object with a
write()method.
overwrite (bool) – Boolean flag indicating if to overwrite the file if it already exists. Only relevant if
sinkis a file path orPathobject.**kwargs (Any) – Additional keyword arguments to pass to
json.dumps().
- Raises:
FileExistsError – If
sinkpoints to an already existing file butoverwriteisFalse.- Return type:
str
- Returns:
The JSON representation as a string.
-
surrogates:
_SurrogateGetter¶ An index-based mapping from target names to single-target surrogates.