ModelKernelTrainer¶
- class ModelKernelTrainer¶
Bases:
TrainerBase
A class for training a polynomial- and kernel-based surrogate model.
Methods
Constructor.
Initialize with a random seed.
Set a model class.
Set model parameters to initialize the model class with (
TorchFM
by default).Set training parameters.
Train a polynomial- and kernel-based model.
- __init__(model_class: type[~amplify_bbopt.model.ModelKernel] = <class 'amplify_bbopt.model.ModelKernel'>) None ¶
Constructor.
- Parameters:
model_class (Type[ModelKernel], optional) – A model class to train. By calling the constructor, default training parameters are set with
ModelKernelTrainer.set_train_params
. Defaults toModelKernel
.
- __str__() str ¶
Return human-readable training information.
- Returns:
Human-readable training information.
- Return type:
- init_seed(seed: int) None ¶
Initialize with a random seed.
- Parameters:
seed (int) – A random seed.
- set_model_class(model_class: type[~amplify_bbopt.model.ModelKernel] = <class 'amplify_bbopt.model.ModelKernel'>) None ¶
Set a model class.
- Parameters:
model_class (Type[ModelKernel]) – A model class. Defaults to
ModelKernel
.
- set_model_params(**model_params: dict) None ¶
Set model parameters to initialize the model class with (
TorchFM
by default).The following parameters can be set for the default model class:
beta (float | list[float], optional): A weight for ‘sigma’ in the lower confidence bound (LCB). If multiple values of beta are given as a list, a value in the list is chosen and used in a cyclic manner each time the model is constructed (=in each optimization cycle). When beta = 0 or min(beta) = 0,
ModelKernel.is_sigma_required = False
, meaning the model uncertainty is not considered. Defaults to 0.0.gamma (float, optional): A constant in the kernel function to define a linear term in the model. gamma = 0 means no linear term is considered in the model. Note that when the a priori encoding methods (()[conversion.ipynb]) are chosen for all decision variables, linear terms are expected to be modeled naturally in the quadratic terms. Defaults to 0.0.
- set_train_params(reg_param: float = 1) None ¶
Set training parameters.
- Parameters:
reg_param (float, optional) – A regularization parameter. Defaults to 1.
- train( ) ModelKernel ¶
Train a polynomial- and kernel-based model.
- Parameters:
x_values (list[list[bool | int | float]]) – A list of the input value vectors in the training data (with the last element being a newly added input value vector since the last training).
y_values (list[int | float]) – A list of the corresponding output values in the training data.
logger (Logger | None) – A logger.
- Raises:
RuntimeError – If a regularization parameter is not set.
- Returns:
A trained model.
- Return type:
- __abstractmethods__ = frozenset({})¶
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.trainer', '__doc__': 'A class for training a polynomial- and kernel-based surrogate model.', '__init__': <function ModelKernelTrainer.__init__>, 'train': <function ModelKernelTrainer.train>, '_corrcoef': <function ModelKernelTrainer._corrcoef>, 'set_model_class': <function ModelKernelTrainer.set_model_class>, 'set_model_params': <function ModelKernelTrainer.set_model_params>, 'set_train_params': <function ModelKernelTrainer.set_train_params>, '__str__': <function ModelKernelTrainer.__str__>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_model_params': 'dict[str, Any]', '_reg_param': 'float | None', '_beta': 'float | list[float] | None', '_beta_array': 'np.ndarray | None', '_matrix_handler': 'PolyCoefMatrixHandler | None'}})¶
- __slots__ = ()¶
- __weakref__¶
list of weak references to the object (if defined)