Class: Chainer::Optimizers::MomentumSGD

Inherits:
GradientMethod show all
Defined in:
lib/chainer/optimizers/momentum_sgd.rb

Overview

Momentum SGD optimizer

Instance Attribute Summary collapse

Attributes inherited from Chainer::Optimizer

#target

Instance Method Summary collapse

Methods inherited from GradientMethod

#call_hooks, #reallocate_cleared_grads, #setup, #update

Methods inherited from Chainer::Optimizer

#_call_hook, #add_hook, #call_hooks, #serialize, #setup

Constructor Details

#initialize(lr: nil, momentum: nil) ⇒ MomentumSGD

Returns a new instance of MomentumSGD.

Parameters:

  • lr (Float) (defaults to: nil)

    Learning rate

  • momentum (Float) (defaults to: nil)

    Exponential decay rate of the first order moment



36
37
38
39
40
41
42
# File 'lib/chainer/optimizers/momentum_sgd.rb', line 36

def initialize(lr: nil, momentum: nil)
  super()
  @hyperparam.instance_variable_set('@lr', lr || 0.01)
  @hyperparam.instance_variable_set('@momentum', momentum || 0.9)
  Chainer::HyperparameterProxy.new(self, "lr")
  Chainer::HyperparameterProxy.new(self, "momentum")
end

Instance Attribute Details

#lrObject

Returns the value of attribute lr.



33
34
35
# File 'lib/chainer/optimizers/momentum_sgd.rb', line 33

def lr
  @lr
end

#momentumObject

Returns the value of attribute momentum.



33
34
35
# File 'lib/chainer/optimizers/momentum_sgd.rb', line 33

def momentum
  @momentum
end

Instance Method Details

#create_update_ruleObject



44
45
46
# File 'lib/chainer/optimizers/momentum_sgd.rb', line 44

def create_update_rule
  MomentumSGDRule.new(parent_hyperparam: @hyperparam)
end