Class: NekonekoGen::Arow
- Inherits:
-
Object
- Object
- NekonekoGen::Arow
- Defined in:
- lib/nekoneko_gen/arow.rb
Constant Summary collapse
- R =
6.0
Instance Attribute Summary collapse
-
#k ⇒ Object
Returns the value of attribute k.
-
#w ⇒ Object
Returns the value of attribute w.
Instance Method Summary collapse
-
#initialize(k, options = {}) ⇒ Arow
constructor
A new instance of Arow.
- #strip! ⇒ Object
- #update(vec, label) ⇒ Object
Constructor Details
#initialize(k, options = {}) ⇒ Arow
Returns a new instance of Arow.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/nekoneko_gen/arow.rb', line 6 def initialize(k, = {}) @r = [:r] || R @k = k @cov = [] @w = [] if (@k == 2) @cov[0] = Hash.new(1.0) @w[0] = Hash.new(0.0) else k.times do |i| @cov[i] = Hash.new(1.0) @w[i] = Hash.new(0.0) end end end |
Instance Attribute Details
#k ⇒ Object
Returns the value of attribute k.
5 6 7 |
# File 'lib/nekoneko_gen/arow.rb', line 5 def k @k end |
#w ⇒ Object
Returns the value of attribute w.
5 6 7 |
# File 'lib/nekoneko_gen/arow.rb', line 5 def w @w end |
Instance Method Details
#strip! ⇒ Object
37 38 39 40 41 42 |
# File 'lib/nekoneko_gen/arow.rb', line 37 def strip! @w.each do |w| w.reject!{|k,v| v.abs <= Float::EPSILON } end @w end |
#update(vec, label) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/nekoneko_gen/arow.rb', line 21 def update(vec, label) loss = 0.0 if (@k == 2) loss = update_at(0, vec, label) else nega = rand(@k - 1) if (nega == label) nega += 1 end s = 1.0 / @k @k.times do |i| loss += update_at(i, vec, label) * s end end loss end |