Skip to content
This repository was archived by the owner on Jul 1, 2023. It is now read-only.

Commit 0794ac4

Browse files
authored
NFC: style changes.
1 parent 6a74464 commit 0794ac4

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

Sources/TensorFlow/Optimizers/MomentumBased.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -377,10 +377,10 @@ public class AMSGrad<Model: Differentiable & KeyPathIterable>: Optimizer
377377
}
378378
}
379379

380-
/// RAdam Optimizer
380+
/// RAdam optimizer.
381381
///
382-
/// Recitified Adam optimizer, a variant of Adam that introduces a term to rectify
383-
/// variance of adaptive learning rate
382+
/// Rectified Adam, a variant of Adam that introduces a term to rectify the adaptive learning rate
383+
/// variance.
384384
///
385385
/// Reference: ["On the Variance of the Adaptive Learning Rate and Beyond"]
386386
/// https://arxiv.org/pdf/1908.03265.pdf
@@ -431,24 +431,24 @@ public class RAdam<Model: Differentiable>: Optimizer
431431
let step = Float(self.step)
432432
let beta1Power = pow(beta1, step)
433433
let beta2Power = pow(beta2, step)
434-
// let stepSize = self.learningRate * step / (1 - beta1Power)
435434
secondMoments = beta2 * secondMoments + direction .* direction * (1 - beta2)
436435
firstMoments = beta1 * firstMoments + direction * (1 - beta1)
437-
// Compute maximum length SMA, bias-corrected moving average and approximate length
438-
// SMA
436+
// Compute maximum length SMA, bias-corrected moving average and approximate length.
439437
let N_sma_inf = 2 / (1 - beta2) - 1
440-
let N_sma_t = N_sma_inf - 2*step*beta2Power / (1 - beta2Power)
438+
let N_sma_t = N_sma_inf - 2 * step * beta2Power / (1 - beta2Power)
441439

442440
if N_sma_t > 5 {
443-
// Compute Bias corrected second moments, rectification and adapted momentum
441+
// Compute bias-corrected second moments, rectification and adapted momentum.
444442
let secondMoments_h = Model.TangentVector.sqrt(secondMoments) + epsilon
445-
let stepSize = sqrt((N_sma_t-4)*(N_sma_t-2)*N_sma_inf/((N_sma_inf-4)*(N_sma_inf-2)*(N_sma_t)))
446-
model.move(along: -stepSize*sqrt(1 - beta2Power)*firstMoments./secondMoments_h)
447-
}
448-
else {
449-
// Update with un-adapted momentum
443+
let stepSize = sqrt(
444+
(N_sma_t - 4) * (N_sma_t - 2) * N_sma_inf / (
445+
(N_sma_inf - 4) * (N_sma_inf - 2) * (N_sma_t)
446+
))
447+
model.move(along: -stepSize * sqrt(1 - beta2Power) * firstMoments ./ secondMoments_h)
448+
} else {
449+
// Update with un-adapted momentum.
450450
let stepSize = self.learningRate * step / (1 - beta1Power)
451-
model.move(along: -stepSize*firstMoments)
451+
model.move(along: -stepSize * firstMoments)
452452
}
453453
}
454454
}

0 commit comments

Comments
 (0)