FMTrainer

class FMTrainer

Bases: Trainer

Trainer for Factorization Machine models.

Methods

__init__

Initializes the trainer for Factorization Machine models.

to_poly

Converts a trained model to QUBO model as amplify.Poly.

train

Trains the model using the provided dataset.

Attributes

batch_size

Returns the batch size for training.

epochs

Returns the number of epochs for training.

loss_class

Returns the loss function class used for training.

low_percentile_corrcoefs

Returns the lower percentile correlation coefficients of the last trained model.

lr_scheduler_class

Returns the learning rate scheduler class used for training.

lr_scheduler_params

Returns the parameters for the learning rate scheduler used for training.

model

Returns the trained Factorization Machine model.

num_factors

Returns the number of factors in the model.

optimizer_class

Returns the optimizer class used for training.

optimizer_params

Returns the parameters for the optimizer used for training.

percentile_cutoffs

Returns the lower percentile cutoffs for the trainer.

train_data_split_ratio

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 batch_size: int

Returns the batch size for training.

property epochs: int

Returns the number of epochs for training.

property loss_class: type[_Loss]

Returns the loss function class used for training.

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 model: TorchFM | None

Returns the trained Factorization Machine model.

property num_factors: int

Returns the number of factors in the model.

property optimizer_class: type[torch.optim.optimizer.Optimizer]

Returns the optimizer class used for training.

property optimizer_params: dict[str, Any]

Returns the parameters for the optimizer used for training.

property percentile_cutoffs: list[int]

Returns the lower percentile cutoffs for the trainer.

property train_data_split_ratio: float

Returns the ratio of training data split for validation.