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

Instance Method Summary collapse

Methods inherited from Optimizer

#dump, from_hash, load, #update

Constructor Details

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



276
277
278
279
280
281
282
283
284
285
286
287
288
# File 'lib/dnn/core/optimizers.rb', line 276

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

#alphaObject

Returns the value of attribute alpha.



265
266
267
# File 'lib/dnn/core/optimizers.rb', line 265

def alpha
  @alpha
end

#amsgradObject (readonly)

Returns the value of attribute amsgrad.



269
270
271
# File 'lib/dnn/core/optimizers.rb', line 269

def amsgrad
  @amsgrad
end

#beta1Object

Returns the value of attribute beta1.



266
267
268
# File 'lib/dnn/core/optimizers.rb', line 266

def beta1
  @beta1
end

#beta2Object

Returns the value of attribute beta2.



267
268
269
# File 'lib/dnn/core/optimizers.rb', line 267

def beta2
  @beta2
end

#epsObject

Returns the value of attribute eps.



268
269
270
# File 'lib/dnn/core/optimizers.rb', line 268

def eps
  @eps
end

Instance Method Details

#load_hash(hash) ⇒ Object



315
316
317
318
# File 'lib/dnn/core/optimizers.rb', line 315

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



290
291
292
293
294
295
# File 'lib/dnn/core/optimizers.rb', line 290

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