Class: DNN::Optimizers::RMSProp

Inherits:
Optimizer show all
Defined in:
lib/dnn/core/optimizers.rb

Instance Attribute Summary collapse

Attributes inherited from Optimizer

#learning_rate

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(learning_rate = 0.001, muse = 0.9) ⇒ RMSProp

Returns a new instance of RMSProp.



81
82
83
84
85
# File 'lib/dnn/core/optimizers.rb', line 81

def initialize(learning_rate = 0.001, muse = 0.9)
  super(learning_rate)
  @muse = muse
  @g = {}
end

Instance Attribute Details

#museObject

Returns the value of attribute muse.



75
76
77
# File 'lib/dnn/core/optimizers.rb', line 75

def muse
  @muse
end

Class Method Details

.load_hash(hash) ⇒ Object



77
78
79
# File 'lib/dnn/core/optimizers.rb', line 77

def self.load_hash(hash)
  self.new(hash[:learning_rate], hash[:muse])
end

Instance Method Details

#to_hashObject



96
97
98
# File 'lib/dnn/core/optimizers.rb', line 96

def to_hash
  super({muse: @muse})
end

#update(layer) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/dnn/core/optimizers.rb', line 87

def update(layer)
  @g[layer] ||= {}
  layer.params.each_key do |key|
    @g[layer][key] ||= 0
    @g[layer][key] = @muse * @g[layer][key] + (1 - @muse) * layer.grads[key]**2
    layer.params[key] -= (@learning_rate / NMath.sqrt(@g[layer][key] + 1e-7)) * layer.grads[key]
  end
end