Class: RANN::Optimisers::AdaGrad
- Inherits:
-
Object
- Object
- RANN::Optimisers::AdaGrad
- Defined in:
- lib/rann/optimisers/adagrad.rb
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ AdaGrad
constructor
A new instance of AdaGrad.
- #load_state(state) ⇒ Object
-
#state ⇒ Object
anything that gets modified over the course of training.
- #update(grad, cid) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ AdaGrad
Returns a new instance of AdaGrad.
8 9 10 11 12 |
# File 'lib/rann/optimisers/adagrad.rb', line 8 def initialize opts = {} @fudge_factor = opts[:fudge_factor] || 0.00000001.to_d @learning_rate = opts[:learning_rate] || 0.1.to_d @historical_gradient = {}.tap{ |h| h.default = 0.to_d } end |
Instance Method Details
#load_state(state) ⇒ Object
27 28 29 30 31 |
# File 'lib/rann/optimisers/adagrad.rb', line 27 def load_state state state.each do |name, value| instance_variable_set("@#{name}", value) end end |
#state ⇒ Object
anything that gets modified over the course of training
21 22 23 24 25 |
# File 'lib/rann/optimisers/adagrad.rb', line 21 def state { historical_gradient: @historical_gradient, } end |
#update(grad, cid) ⇒ Object
14 15 16 17 18 |
# File 'lib/rann/optimisers/adagrad.rb', line 14 def update grad, cid @historical_gradient[cid] = @historical_gradient[cid] + grad ** 2 grad * - @learning_rate / (@fudge_factor + @historical_gradient[cid].sqrt(0)) end |