Class: RANN::Optimisers::RMSProp

Inherits:
Object
  • Object
show all
Defined in:
lib/rann/optimisers/rmsprop.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ RMSProp

Returns a new instance of RMSProp.



8
9
10
11
12
13
# File 'lib/rann/optimisers/rmsprop.rb', line 8

def initialize opts = {}
  @decay               = opts[:decay] || 0.9.to_d
  @fudge_factor        = opts[:fudge_factor] || 0.00000001.to_d
  @learning_rate       = opts[:learning_rate] || 0.01.to_d
  @historical_gradient = {}.tap{ |h| h.default = 0.to_d }
end

Instance Method Details

#load_state(state) ⇒ Object



28
29
30
31
32
# File 'lib/rann/optimisers/rmsprop.rb', line 28

def load_state state
  state.each do |name, value|
    instance_variable_set("@#{name}", value)
  end
end

#stateObject

anything that gets modified over the course of training



22
23
24
25
26
# File 'lib/rann/optimisers/rmsprop.rb', line 22

def state
  {
    historical_gradient: @historical_gradient,
  }
end

#update(grad, cid) ⇒ Object



15
16
17
18
19
# File 'lib/rann/optimisers/rmsprop.rb', line 15

def update grad, cid
  @historical_gradient[cid] = @decay * @historical_gradient[cid] + (1 - @decay) * grad ** 2

  grad * - @learning_rate / (@fudge_factor + @historical_gradient[cid].sqrt(0))
end