Class: DNN::Optimizers::RMSProp
- Defined in:
- lib/dnn/core/optimizers.rb
Instance Attribute Summary collapse
-
#alpha ⇒ Object
Returns the value of attribute alpha.
Attributes inherited from Optimizer
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(learning_rate = 0.001, alpha: 0.9) ⇒ RMSProp
constructor
A new instance of RMSProp.
- #to_hash ⇒ Object
- #update(layer) ⇒ Object
Constructor Details
#initialize(learning_rate = 0.001, alpha: 0.9) ⇒ RMSProp
Returns a new instance of RMSProp.
104 105 106 107 108 |
# File 'lib/dnn/core/optimizers.rb', line 104 def initialize(learning_rate = 0.001, alpha: 0.9) super(learning_rate) @alpha = alpha @g = {} end |
Instance Attribute Details
#alpha ⇒ Object
Returns the value of attribute alpha.
98 99 100 |
# File 'lib/dnn/core/optimizers.rb', line 98 def alpha @alpha end |
Class Method Details
.load_hash(hash) ⇒ Object
100 101 102 |
# File 'lib/dnn/core/optimizers.rb', line 100 def self.load_hash(hash) self.new(hash[:learning_rate], alpha: hash[:alpha]) end |
Instance Method Details
#to_hash ⇒ Object
119 120 121 |
# File 'lib/dnn/core/optimizers.rb', line 119 def to_hash super({alpha: @alpha}) end |
#update(layer) ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/dnn/core/optimizers.rb', line 110 def update(layer) @g[layer] ||= {} layer.params.each_key do |key| @g[layer][key] ||= 0 @g[layer][key] = @alpha * @g[layer][key] + (1 - @alpha) * layer.grads[key]**2 layer.params[key] -= (@learning_rate / Xumo::NMath.sqrt(@g[layer][key] + 1e-7)) * layer.grads[key] end end |