Class: Rumale::PolynomialModel::BaseFactorizationMachine

Inherits:
Object
  • Object
show all
Includes:
Base::BaseEstimator
Defined in:
lib/rumale/polynomial_model/base_factorization_machine.rb

Overview

BaseFactorizationMachine is an abstract class for implementation of Factorization Machine-based estimators. This class is used internally.

Instance Attribute Summary

Attributes included from Base::BaseEstimator

#params

Instance Method Summary collapse

Constructor Details

#initialize(n_factors: 2, loss: nil, reg_param_linear: 1.0, reg_param_factor: 1.0, max_iter: 1000, batch_size: 10, optimizer: nil, n_jobs: nil, random_seed: nil) ⇒ BaseFactorizationMachine

Initialize a Factorization Machine-based estimator.

Parameters:

  • n_factors (Integer) (defaults to: 2)

    The maximum number of iterations.

  • loss (String) (defaults to: nil)

    The loss function (‘hinge’ or ‘logistic’ or nil).

  • reg_param_linear (Float) (defaults to: 1.0)

    The regularization parameter for linear model.

  • reg_param_factor (Float) (defaults to: 1.0)

    The regularization parameter for factor matrix.

  • max_iter (Integer) (defaults to: 1000)

    The maximum number of iterations.

  • batch_size (Integer) (defaults to: 10)

    The size of the mini batches.

  • optimizer (Optimizer) (defaults to: nil)

    The optimizer to calculate adaptive learning rate. If nil is given, Nadam is used.

  • n_jobs (Integer) (defaults to: nil)

    The number of jobs for running the fit and predict methods in parallel. If nil is given, the methods do not execute in parallel. If zero or less is given, it becomes equal to the number of processors. This parameter is ignored if the Parallel gem is not loaded.

  • random_seed (Integer) (defaults to: nil)

    The seed value using to initialize the random generator.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/rumale/polynomial_model/base_factorization_machine.rb', line 29

def initialize(n_factors: 2, loss: nil, reg_param_linear: 1.0, reg_param_factor: 1.0,
               max_iter: 1000, batch_size: 10, optimizer: nil, n_jobs: nil, random_seed: nil)
  @params = {}
  @params[:n_factors] = n_factors
  @params[:loss] = loss unless loss.nil?
  @params[:reg_param_linear] = reg_param_linear
  @params[:reg_param_factor] = reg_param_factor
  @params[:max_iter] = max_iter
  @params[:batch_size] = batch_size
  @params[:optimizer] = optimizer
  @params[:optimizer] ||= Optimizer::Nadam.new
  @params[:n_jobs] = n_jobs
  @params[:random_seed] = random_seed
  @params[:random_seed] ||= srand
  @factor_mat = nil
  @weight_vec = nil
  @bias_term = nil
  @rng = Random.new(@params[:random_seed])
end