Class: PaLearner::DistRegressor

Inherits:
Object
  • Object
show all
Includes:
PaLearner
Defined in:
lib/pa_learner.rb

Constant Summary

Constants included from PaLearner

EPS_TO_AVOID_ZERO_DIV, VERSION

Instance Attribute Summary

Attributes included from PaLearner

#w

Instance Method Summary collapse

Methods included from PaLearner

#bin_classify, #estimate

Constructor Details

#initialize(n, eps = 0.001) ⇒ DistRegressor

Returns a new instance of DistRegressor.



41
42
43
44
# File 'lib/pa_learner.rb', line 41

def initialize( n, eps=0.001)
  pa_kickstart( n )
  @eps = eps
end

Instance Method Details

#update!(x, y) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/pa_learner.rb', line 46

def update!(x,y)
  rate = sign( estimate(x) - y ) * (   loss( estimate(x), y ) / ( inner_product(x, x) + EPS_TO_AVOID_ZERO_DIV )   ) 
  rate_x = x.map {|v| -Math::log(v) * rate }
  @w = @w.zip( rate_x ).map{ |v| v.first + v.last }
  project_to_simplex!(@w)
  self
end