ModelKernel¶
- class ModelKernel¶
Bases:
QUBOConvertibleBase
Class to define a surrogate/acquisition function model based on second order polynomial kernels.
Methods
Initialize the kernel based model class.
Generate polynomial kernel functions for k_mu (for mean) and k_sigma (for sigma).
Update the model coefficient matrices and vectors.
Convert a kernel-based model to the Amplify SDK-compatible QUBO based on the optimized FM parameters.
Attributes
The beta value(s) for the sigma terms in LCB.
The coefficient matrix combined for the mean and for sigma with beta used for the current model.
The coefficient matrix for the mean used for the current model.
The coefficient matrix for the sigma used for the current model.
The coefficient vector combined for the mean and for sigma with beta used for the current model.
The coefficient vector for the mean used for the current model.
The coefficient vector for sigma used for the current model.
The value of beta used for the current model.
The gamma value for the kernel functions that corresponds to the linear terms in the model.
Whether the sigma is considered in the model.
- __call__(x: list[list[Any]] | list[Any]) list[float] | float ¶
Perform prediction based on the current model.
- Parameters:
x (list[list[Any]] | list[Any]) – An input vector or a list of input vectors.
- Raises:
RuntimeError – If the coefficient matrix combined for the mean and for sigma is not set.
- Returns:
A predicted value or a list of the predicted values (in case of multiple input vectors are given).
- Return type:
- __init__(beta: float | list[float] = 0.0, gamma: float = 0.0) None ¶
Initialize the kernel based model class.
- Parameters:
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.
- generate_kernel_functions() tuple[Callable, Callable] ¶
Generate polynomial kernel functions for k_mu (for mean) and k_sigma (for sigma).
- Returns:
The kernel functions, k_mu and k_sigma in a tuple in this order.
- Return type:
tuple[Callable, Callable]
- set_coefficient(
- matrix_mu: ndarray,
- vector_mu: ndarray | None = None,
- matrix_lxx: ndarray | None = None,
- vector_sigma: ndarray | None = None,
- i_cycle: int = 0,
Update the model coefficient matrices and vectors.
- Parameters:
matrix_mu (np.ndarray) – The coefficient matrix for the mean
vector_mu (np.ndarray | None, optional) – The coefficient vector for the mean. This is required when gamma > 0 is passed in
ModelKernel.__init__
. Defaults to None.matrix_lxx (np.ndarray | None, optional) – The matrix (L_ij X X) to be used to construct the coefficient matrix for sigma. This is required when current_beta > 0. Defaults to None.
vector_sigma (np.ndarray | None, optional) – The coefficient vector for the sigma. This is required when gamma > 0 and current_beta > 0. Defaults to None.
i_cycle (int, optional) – The cycle number from starting from 0 to be used for the cyclic beta. Defaults to 0.
- to_qubo(x: PolyArray) Poly ¶
Convert a kernel-based model to the Amplify SDK-compatible QUBO based on the optimized FM parameters.
- Parameters:
x (amplify.PolyArray) – The Amplify SDK variables relevant to the
Variables
instance involved in the FM.- Raises:
RuntimeError – If the coefficient matrix combined for the mean and sigma is not set.
- Returns:
The Amplify SDK’s QUBO polynomial.
- Return type:
amplify.Poly
- __abstractmethods__ = frozenset({})¶
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.model', '__doc__': 'Class to define a surrogate/acquisition function model based on second order polynomial kernels.', '__init__': <function ModelKernel.__init__>, 'generate_kernel_functions': <function ModelKernel.generate_kernel_functions>, 'is_sigma_required': <property object>, 'gamma': <property object>, 'beta': <property object>, 'current_beta': <property object>, 'coef_matrix_mu': <property object>, 'coef_matrix_sigma': <property object>, 'coef_matrix_combined': <property object>, 'coef_vector_mu': <property object>, 'coef_vector_sigma': <property object>, 'coef_vector_combined': <property object>, 'set_coefficient': <function ModelKernel.set_coefficient>, 'to_qubo': <function ModelKernel.to_qubo>, '_predict': <function ModelKernel._predict>, '__call__': <function ModelKernel.__call__>, '__str__': <function ModelKernel.__str__>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_coef_matrix_combined': 'np.ndarray | None', '_coef_vector_combined': 'np.ndarray | None', '_coef_matrix_mu': 'np.ndarray | None', '_coef_vector_mu': 'np.ndarray | None', '_coef_matrix_sigma': 'np.ndarray | None'}})¶
- __slots__ = ()¶
- __weakref__¶
list of weak references to the object (if defined)
- property coef_matrix_combined: ndarray | None¶
The coefficient matrix combined for the mean and for sigma with beta used for the current model. If the matrix is not set yet, return None.
- property coef_matrix_mu: ndarray | None¶
The coefficient matrix for the mean used for the current model. If the matrix is not set yet, return None.
- property coef_matrix_sigma: ndarray | None¶
The coefficient matrix for the sigma used for the current model. If the matrix is not set yet, return None.
- property coef_vector_combined: ndarray | None¶
The coefficient vector combined for the mean and for sigma with beta used for the current model. If the vector is not set yet, return None.
- property coef_vector_mu: ndarray | None¶
The coefficient vector for the mean used for the current model. If the vector is not set yet, return None.
- property coef_vector_sigma: ndarray | None¶
The coefficient vector for sigma used for the current model. If the vector is not set yet, return None.
- property current_beta: float¶
The value of beta used for the current model. When beta is given as a list in
ModelKernel.__init__
, a value in the list is chosen and used in a cyclic manner each time the model is constructed, and this value will be returned.