jijzepttools.blackbox_optimization.factorization_machine#

Classes#

FactorizationMachine

Factorization Machine model

FMTrainer

Module Contents#

class FactorizationMachine(n_features: int, latent_dim: int)#

Bases: torch.nn.Module

Factorization Machine model

`math f(x|w, v) = w0 + Σwi*xi + ΣΣ<vj, vk>xj*xk = w0 + Σwi*xi + 1/2*(Σ(vi*xi)^2 - Σ(vi^2*xi^2)) `

n_features#
latent_dim#
linear#
quad#
forward(x)#
property v#
property w#
property w0#
class FMTrainer(n_features: int, latent_dim: int, optimizer_params: dict | None = None)#
n_features#
latent_dim#
optimizer_params#
setup_initial_state()#
fit(x_numpy: numpy.ndarray, y_numpy: numpy.ndarray, n_epochs: int = 1000, batch_size: int = 32, early_stopping: bool = True, es_min_epochs: int = 10, es_patience: int = 10, es_threshold_of_loss_rel_imp: float = 0.0005, es_verbose: bool = False)#

Fit the Factorization Machine for surrogate model.

サロゲートモデル構築が目的なので、train_lossベースでのearly stoppingを行っており 予測目的に利用すると過学習する可能性がある。

Parameters:
  • x_numpy (np.ndarray) – input features, shape (n_samples, n_features)

  • y_numpy (np.ndarray) – target values, shape (n_samples,)

  • n_epochs (int) – number of epochs, default 1000

  • batch_size (int) – batch size, default 32

  • early_stopping (bool) – whether to use early stopping, default True

  • es_min_epochs (int) – minimum number of epochs for early stopping, default 10

  • es_patience (int) – patience for early stopping, default 10

  • es_threshold_of_loss_rel_imp (float) – threshold of loss relative improvement for early stopping, default 5e-4

  • es_verbose (bool) – whether to print early stopping message, default False

predict(x: numpy.ndarray) numpy.ndarray#
property x#
property y#
get_qubo() tuple[numpy.ndarray, float]#