FMTrainer¶
- class FMTrainer¶
Bases:
Trainer
Trainer for Factorization Machine models.
Methods
Initializes the trainer for Factorization Machine models.
Converts a trained model to QUBO model as amplify.Poly.
Trains the model using the provided dataset.
Attributes
Returns the batch size for training.
Returns the number of epochs for training.
Returns the loss function class used for training.
Returns the lower percentile correlation coefficients of the last trained model.
Returns the learning rate scheduler class used for training.
Returns the parameters for the learning rate scheduler used for training.
Returns the trained Factorization Machine model.
Returns the number of factors in the model.
Returns the optimizer class used for training.
Returns the parameters for the optimizer used for training.
Returns the lower percentile cutoffs for the trainer.
Returns the ratio of training data split for validation.
- __init__(num_threads: int | None = 8) None ¶
Initializes the trainer for Factorization Machine models.
- Parameters:
num_threads (int | None, optional) – The number of threads to use for training. Defaults to 8.
- to_poly(x: amplify.PolyArray[amplify.Dim1]) amplify.Poly ¶
Converts a trained model to QUBO model as amplify.Poly.
- Parameters:
x (amplify.PolyArray[amplify.Dim1]) – The variables in amplify.PolyArray.
- Raises:
ValueError – If the input array is not 1D.
ValueError – If the input length does not match the number of features.
ValueError – If the surrogate model has not been trained.
- Returns:
The resulting QUBO polynomial.
- Return type:
amplify.Poly
- train(dataset: Dataset) None ¶
Trains the model using the provided dataset.
- Parameters:
dataset (Dataset) – The dataset to train on.
- 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', '__doc__': 'Trainer for Factorization Machine models.', '__init__': <function FMTrainer.__init__>, 'model': <property object>, 'num_factors': <property object>, 'batch_size': <property object>, 'epochs': <property object>, 'loss_class': <property object>, 'optimizer_class': <property object>, 'optimizer_params': <property object>, 'lr_scheduler_class': <property object>, 'lr_scheduler_params': <property object>, 'train_data_split_ratio': <property object>, 'train': <function FMTrainer.train>, 'to_poly': <function FMTrainer.to_poly>, '__abstractmethods__': frozenset(), '_abc_impl': <_abc._abc_data object>, '__annotations__': {'_fm': 'TorchFM | None', '_num_factors': 'int', '_batch_size': 'int', '_epochs': 'int', '_loss': 'type[torch.nn.modules.loss._Loss]', '_optimizer': 'type[torch.optim.optimizer.Optimizer]', '_optimizer_params': 'dict[str, Any]', '_lr_scheduler': 'type[torch.optim.lr_scheduler.LRScheduler] | None', '_lr_scheduler_params': 'dict[str, Any]', '_train_data_split_ratio': 'float', '_percentile_cutoffs': 'list[int]', '_low_percentile_corrcoefs': 'dict[int, float] | None'}})¶
- __slots__ = ()¶
- __weakref__¶
list of weak references to the object (if defined)
- property low_percentile_corrcoefs: dict[int, float] | None¶
Returns the lower percentile correlation coefficients of the last trained model.
- property lr_scheduler_class: type[LRScheduler] | None¶
Returns the learning rate scheduler class used for training.
- property lr_scheduler_params: dict[str, Any]¶
Returns the parameters for the learning rate scheduler used for training.
- property optimizer_class: type[torch.optim.optimizer.Optimizer]¶
Returns the optimizer class used for training.