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

Instance Method Summary collapse

Methods inherited from Optimizer

from_hash, #update, #update_layers

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.



258
259
260
261
262
263
264
265
266
267
268
269
# File 'lib/dnn/core/optimizers.rb', line 258

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
end

Instance Attribute Details

#alphaObject

Returns the value of attribute alpha.



247
248
249
# File 'lib/dnn/core/optimizers.rb', line 247

def alpha
  @alpha
end

#amsgradObject (readonly)

Returns the value of attribute amsgrad.



251
252
253
# File 'lib/dnn/core/optimizers.rb', line 251

def amsgrad
  @amsgrad
end

#beta1Object

Returns the value of attribute beta1.



248
249
250
# File 'lib/dnn/core/optimizers.rb', line 248

def beta1
  @beta1
end

#beta2Object

Returns the value of attribute beta2.



249
250
251
# File 'lib/dnn/core/optimizers.rb', line 249

def beta2
  @beta2
end

#epsObject

Returns the value of attribute eps.



250
251
252
# File 'lib/dnn/core/optimizers.rb', line 250

def eps
  @eps
end

Instance Method Details

#load_hash(hash) ⇒ Object



296
297
298
299
# File 'lib/dnn/core/optimizers.rb', line 296

def load_hash(hash)
  initialize(alpha: hash[:alpha], beta1: hash[:beta1], beta2: hash[:beta2],
             eps: hash[:eps], amsgrad: hash[:amsgrad], clip_norm: hash[:clip_norm])
end

#to_hashObject



271
272
273
274
275
276
# File 'lib/dnn/core/optimizers.rb', line 271

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