Class: DNN::Optimizers::Adam

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

Direct Known Subclasses

AdaBound

Instance Attribute Summary collapse

Attributes inherited from Optimizer

#clip_norm, #status

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Optimizer

#dump, load, #update

Constructor Details

#initialize(alpha: 0.001, beta1: 0.9, beta2: 0.999, eps: 1e-7, amsgrad: false, clip_norm: nil) ⇒ Adam

Returns a new instance of Adam.

Parameters:

  • alpha (Float) (defaults to: 0.001) —

    Value used to calculate learning rate.

  • beta1 (Float) (defaults to: 0.9) —

    Moving average index of beta1.

  • beta2 (Float) (defaults to: 0.999) —

    Moving average index of beta2.

  • eps (Float) (defaults to: 1e-7) —

    Value to avoid division by zero.

  • amsgrad (Boolean) (defaults to: false) —

    Setting the true enable amsgrad.



272
273
274
275
276
277
278
279
280
281
282
283
284
# File 'lib/dnn/core/optimizers.rb', line 272

def initialize(alpha: 0.001, beta1: 0.9, beta2: 0.999, eps: 1e-7, amsgrad: false, clip_norm: nil)
  super(clip_norm: clip_norm)
  @alpha = alpha
  @beta1 = beta1
  @beta2 = beta2
  @eps = eps
  @amsgrad = amsgrad
  @t = 0
  @m = {}
  @v = {}
  @s = amsgrad ? {} : nil
  @status = { t: @t, m: @m, v: @v, s: @s }
end

Instance Attribute Details

#alpha ⇒ Object

Returns the value of attribute alpha.



256
257
258
# File 'lib/dnn/core/optimizers.rb', line 256

def alpha
  @alpha
end

#amsgrad ⇒ Object (readonly)

Returns the value of attribute amsgrad.



260
261
262
# File 'lib/dnn/core/optimizers.rb', line 260

def amsgrad
  @amsgrad
end

#beta1 ⇒ Object

Returns the value of attribute beta1.



257
258
259
# File 'lib/dnn/core/optimizers.rb', line 257

def beta1
  @beta1
end

#beta2 ⇒ Object

Returns the value of attribute beta2.



258
259
260
# File 'lib/dnn/core/optimizers.rb', line 258

def beta2
  @beta2
end

#eps ⇒ Object

Returns the value of attribute eps.



259
260
261
# File 'lib/dnn/core/optimizers.rb', line 259

def eps
  @eps
end

Class Method Details

.from_hash(hash) ⇒ Object



262
263
264
265
# File 'lib/dnn/core/optimizers.rb', line 262

def self.from_hash(hash)
  self.new(alpha: hash[:alpha], beta1: hash[:beta1], beta2: hash[:beta2],
           eps: hash[:eps], amsgrad: hash[:amsgrad], clip_norm: hash[:clip_norm])
end

Instance Method Details

#to_hash ⇒ Object



286
287
288
289
290
291
# File 'lib/dnn/core/optimizers.rb', line 286

def to_hash
  {
    class: self.class.name, alpha: @alpha, beta1: @beta1, beta2: @beta2,
    eps: @eps, amsgrad: @amsgrad, clip_norm: @clip_norm
  }
end