Class: Rumale::LinearModel::BaseLinearModel

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

Overview

BaseLinearModel is an abstract class for implementation of linear estimator with mini-batch stochastic gradient descent optimization. This class is used for internal process.

Direct Known Subclasses

Lasso, LinearRegression, LogisticRegression, Ridge, SVC, SVR

Instance Attribute Summary

Attributes included from Base::BaseEstimator

#params

Instance Method Summary collapse

Constructor Details

#initialize(reg_param: 1.0, fit_bias: false, bias_scale: 1.0, max_iter: 1000, batch_size: 10, optimizer: nil, n_jobs: nil, random_seed: nil) ⇒ BaseLinearModel

Initialize a linear estimator.

Parameters:

  • reg_param (Float) (defaults to: 1.0)

    The regularization parameter.

  • fit_bias (Boolean) (defaults to: false)

    The flag indicating whether to fit the bias term.

  • bias_scale (Float) (defaults to: 1.0)

    The scale of the bias term.

  • 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.

  • random_seed (Integer) (defaults to: nil)

    The seed value using to initialize the random generator.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/rumale/linear_model/base_linear_model.rb', line 27

def initialize(reg_param: 1.0, fit_bias: false, bias_scale: 1.0,
               max_iter: 1000, batch_size: 10, optimizer: nil, n_jobs: nil, random_seed: nil)
  @params = {}
  @params[:reg_param] = reg_param
  @params[:fit_bias] = fit_bias
  @params[:bias_scale] = bias_scale
  @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
  @weight_vec = nil
  @bias_term = nil
  @rng = Random.new(@params[:random_seed])
end