Class: ML::Learner::CyclicDescentLearner

Inherits:
Object
  • Object
show all
Includes:
LinearToolbox, Toolbox
Defined in:
lib/method/cyclic_descent.rb

Overview

Implementation of cyclic coordinate descent learner

Instance Attribute Summary

Attributes included from LinearToolbox

#current_vector

Instance Method Summary collapse

Methods included from LinearToolbox

#line, #predict

Methods included from Toolbox

#classify_error, #predict

Constructor Details

#initialize(dim, model = :basis) ⇒ CyclicDescentLearner

Initialize a learner

Parameters:

  • dim (Integer)

    dimension



13
14
15
16
# File 'lib/method/cyclic_descent.rb', line 13

def initialize dim, model = :basis
  @dim = dim
  @model = model
end

Instance Method Details

#train!(data, iteration = 1000) ⇒ Object

Train with a supervised data

Parameters:

  • data (Hash)

    supervised input data (mapping from array to integer)

  • iteration (Integer) (defaults to: 1000)

    the desired iteration number



22
23
24
25
26
27
28
29
# File 'lib/method/cyclic_descent.rb', line 22

def train! data, iteration = 1000
  self.current_vector = Matrix.column_vector(Array.new(@dim + 1, 0))
  iteration.times do |i|
    v = calc_v i
    eta = calc_eta data, v
    self.current_vector += eta * v
  end
end