Class: SVMKit::LinearModel::SGDLinearEstimator

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

Overview

SGDLinearEstimator 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, random_seed: nil) ⇒ SGDLinearEstimator

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.

  • random_seed (Integer) (defaults to: nil)

    The seed value using to initialize the random generator.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/svmkit/linear_model/sgd_linear_estimator.rb', line 24

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