TorchFMTrainer¶
- class TorchFMTrainer¶
Bases:
TrainerTrainer for Factorization Machine models using PyTorch.
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
The batch size for training.
The number of epochs for training.
The loss function class used for training.
Returns the lower percentile correlation coefficients of the last trained model.
The learning rate scheduler class used for training.
The parameters for the learning rate scheduler used for training.
The trained Factorization Machine model.
The number of factors in the model.
The optimizer class used for training.
The parameters for the optimizer used for training.
Returns the lower percentile cutoffs for the trainer.
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.
- Returns:
The resulting QUBO polynomial.
- Return type:
amplify.Poly
- 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.
- 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._torch_trainer', '__doc__': 'Trainer for Factorization Machine models using PyTorch.', '__init__': <function TorchFMTrainer.__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 TorchFMTrainer.train>, 'to_poly': <function TorchFMTrainer.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¶
The learning rate scheduler class used for training.
- property lr_scheduler_params: dict[str, Any]¶
The parameters for the learning rate scheduler used for training.