class RANN::Optimisers::AdaGrad

Public Class Methods

new(opts = {}) click to toggle source
# 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

Public Instance Methods

load_state(state) click to toggle source
# 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() click to toggle source

anything that gets modified over the course of training

# File lib/rann/optimisers/adagrad.rb, line 21
def state
  {
    historical_gradient: @historical_gradient,
  }
end
update(grad, cid) click to toggle source
# 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