Class: DNN::Optimizers::SGD

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

Direct Known Subclasses

Nesterov

Instance Attribute Summary collapse

Attributes inherited from Optimizer

#clip_norm, #status

Instance Method Summary collapse

Methods inherited from Optimizer

from_hash, #update, #update_layers

Constructor Details

#initialize(lr: 0.01, momentum: 0, clip_norm: nil) ⇒ SGD

Returns a new instance of SGD.

Parameters:

  • lr (Float) (defaults to: 0.01)

    Learning rate.

  • momentum (Float) (defaults to: 0)

    Momentum coefficient.



70
71
72
73
74
75
76
# File 'lib/dnn/core/optimizers.rb', line 70

def initialize(lr: 0.01, momentum: 0, clip_norm: nil)
  super(clip_norm: clip_norm)
  @lr = lr
  @momentum = momentum
  @v = {}
  @status = { v: @v }
end

Instance Attribute Details

#lrObject

Returns the value of attribute lr.



65
66
67
# File 'lib/dnn/core/optimizers.rb', line 65

def lr
  @lr
end

#momentumObject

Returns the value of attribute momentum.



66
67
68
# File 'lib/dnn/core/optimizers.rb', line 66

def momentum
  @momentum
end

Instance Method Details

#load_hash(hash) ⇒ Object



94
95
96
# File 'lib/dnn/core/optimizers.rb', line 94

def load_hash(hash)
  initialize(lr: hash[:lr], momentum: hash[:momentum], clip_norm: hash[:clip_norm])
end

#to_hashObject



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

def to_hash
  super(lr: @lr, momentum: @momentum)
end