KMTrainer¶
- class KMTrainer¶
Bases:
Trainer
Methods
Initializes the trainer for kernel models.
Converts a trained kernel model to QUBO model as amplify.Poly.
Trains the kernel model using the provided dataset.
Attributes
Returns the weight for 'sigma' in the lower confidence bound (LCB).
Returns the weight for a linear term in the model.
Returns the lower percentile correlation coefficients of the last trained model.
Returns the trained kernel model.
Returns the lower percentile cutoffs for the trainer.
Returns the regularization parameter for the kernel model.
- class GramMatrixHandler¶
Bases:
object
Compute and update the inverse of a Gram matrix sequentially with addition of a new data set.
- __init__(kernel_func: Callable, init_x: np.ndarray, reg_param: float) None ¶
Initialize a Gram matrix with the initial training data.
- Parameters:
kernel_func (Callable) – A kernel function for Gram matrix.
init_x (np.ndarray) – Input value vectors in the initial training data.
reg_param (float) – A regularization parameter.
- update(x: ndarray) None ¶
Update a Gram matrix and related intermediate variables sequentially with addition of a new data set.
- Parameters:
x (np.ndarray) – Input value vectors in the training data (with the last element being a newly added input value vector).
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.trainer', '__doc__': 'Compute and update the inverse of a Gram matrix sequentially with addition of a new data set.', '__init__': <function KMTrainer.GramMatrixHandler.__init__>, 'inv_gram_matrix': <property object>, 's': <property object>, 'v': <property object>, 'sum_vx': <property object>, 'update': <function KMTrainer.GramMatrixHandler.update>, '__dict__': <attribute '__dict__' of 'GramMatrixHandler' objects>, '__weakref__': <attribute '__weakref__' of 'GramMatrixHandler' objects>, '__annotations__': {'_scalar': 'float', '_vector': 'np.ndarray', '_sum_vx': 'np.ndarray'}})¶
- __weakref__¶
list of weak references to the object (if defined)
- class PolyCoefMatrixHandler¶
Bases:
object
Compute and update polynomial coefficient matrices and vectors sequentially with addition of a new data set for the kernel-QA optimization.
- __init__(
- init_x: np.ndarray,
- init_y: np.ndarray,
- kernel_func_mu: Callable,
- kernel_func_sigma: Callable | None,
- reg_param: float,
Initialize coefficient matrices and vectors with the initial training data.
- Parameters:
init_x (np.ndarray) – A list of the input value vectors in the initial training data.
init_y (np.ndarray) – Corresponding output values.
kernel_func_mu (Callable) – A kernel function for the mean.
kernel_func_sigma (Callable | None) – A kernel function for the sigma. When sigma is not considered throughout the optimization (beta = 0 or min(beta) = 0 in
ModelKernel
), set None.reg_param (float) – A regularization parameter.
- update(x: ndarray, y: ndarray) None ¶
Update polynomial coefficient matrices and vectors sequentially with addition of a new data set.
- Parameters:
x (np.ndarray) – All input value vectors in the training data (with the last element being a newly added input value vector).
y (np.ndarray) – Corresponding output values.
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.trainer', '__doc__': 'Compute and update polynomial coefficient matrices and vectors sequentially with addition of a new data set for the kernel-QA optimization.', '__init__': <function KMTrainer.PolyCoefMatrixHandler.__init__>, 'coef_matrix_mu': <property object>, 'coef_vector_mu': <property object>, 'coef_matrix_lxx': <property object>, 'coef_vector_sigma': <property object>, 'update': <function KMTrainer.PolyCoefMatrixHandler.update>, '__dict__': <attribute '__dict__' of 'PolyCoefMatrixHandler' objects>, '__weakref__': <attribute '__weakref__' of 'PolyCoefMatrixHandler' objects>, '__annotations__': {'_gram_matrix_handler_sigma': 'KMTrainer.GramMatrixHandler | None', '_coef_matrix_lxx': 'np.ndarray | None', '_coef_vector_sigma': 'np.ndarray | None'}})¶
- __weakref__¶
list of weak references to the object (if defined)
- to_poly(x: amplify.PolyArray[amplify.Dim1]) amplify.Poly ¶
Converts a trained kernel model to QUBO model as amplify.Poly.
- Parameters:
x (amplify.PolyArray[amplify.Dim1]) – The variables in amplify.PolyArray.
- Raises:
ValueError – If the kernel model has not been trained.
ValueError – If the input length does not match the number of features.
ValueError – If the input shape is not 1-dimensional.
- Returns:
The resulting QUBO polynomial.
- Return type:
amplify.Poly
- train(dataset: Dataset) None ¶
Trains the kernel model using the provided dataset.
- Parameters:
dataset (Dataset) – The dataset to train the model.
- Raises:
ValueError – If the dataset is empty.
ValueError – If the number of input values and output values are not the same.
ValueError – If the input dataset is not 2D.
- __abstractmethods__ = frozenset({})¶
- __dict__ = mappingproxy({'__module__': 'amplify_bbopt.trainer', 'GramMatrixHandler': <class 'amplify_bbopt.trainer.KMTrainer.GramMatrixHandler'>, 'PolyCoefMatrixHandler': <class 'amplify_bbopt.trainer.KMTrainer.PolyCoefMatrixHandler'>, '__init__': <function KMTrainer.__init__>, 'model': <property object>, 'reg_param': <property object>, 'beta': <property object>, 'gamma': <property object>, 'train': <function KMTrainer.train>, 'to_poly': <function KMTrainer.to_poly>, '__doc__': None, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_km': 'KernelModel | None', '_reg_param': 'float', '_beta': 'float', '_gamma': 'float', '_matrix_handler': 'KMTrainer.PolyCoefMatrixHandler | None', '_percentile_cutoffs': 'list[int]', '_low_percentile_corrcoefs': 'dict[int, float] | None'}})¶
- __slots__ = ()¶
- __weakref__¶
list of weak references to the object (if defined)