Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions src/optimise/optimisers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ mutable struct OADAM
state::IdDict
end

OADAM(η = 0.0001, β = (0.5, 0.9)) = OADAM(η, β, IdDict())
OADAM(η = 0.001, β = (0.5, 0.9)) = OADAM(η, β, IdDict())

function apply!(o::OADAM, x, Δ)
η, β = o.eta, o.beta
Expand Down Expand Up @@ -357,7 +357,9 @@ function apply!(o::ADADelta, x, Δ)
ρ = o.rho
acc, Δacc = get!(o.state, x, (zero(x), zero(x)))
@. acc = ρ * acc + (1 - ρ) * Δ^2
@. Δ *= √Δacc/ (√acc + ϵ)
# DON'T remove epsilon from numerator
# or even out of the square roots
@. Δ *= √(Δacc + ϵ) / √(acc + ϵ)
@. Δacc = ρ * Δacc + (1 - ρ) * Δ^2
return Δ
end
Expand Down Expand Up @@ -599,4 +601,4 @@ function apply!(o::ClipNorm, x, Δ)
rmul!(Δ, o.thresh / Δnrm)
end
return Δ
end
end
7 changes: 7 additions & 0 deletions test/optimise.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,17 @@ using Flux.Optimise
using Flux.Optimise: runall
using Flux: Params, gradient
using Test
using Random

@testset "Optimise" begin
# Ensure rng has different state inside and outside the inner @testset
# so that w and w' are different
Random.seed!(84)
w = randn(10, 10)
@testset for opt in [ADAMW(), ADAGrad(0.1), AdaMax(), ADADelta(0.9), AMSGrad(),
NADAM(), RADAM(), Descent(0.1), ADAM(), OADAM(), Nesterov(), RMSProp(),
Momentum()]
Random.seed!(42)
w′ = randn(10, 10)
loss(x) = Flux.Losses.mse(w*x, w′*x)
for t = 1: 10^5
Expand All @@ -21,8 +26,10 @@ using Test
end

@testset "Optimiser" begin
Random.seed!(84)
w = randn(10, 10)
@testset for Opt in [InvDecay, WeightDecay, ExpDecay]
Random.seed!(42)
w′ = randn(10, 10)
loss(x) = Flux.Losses.mse(w*x, w′*x)
opt = Optimiser(Opt(), ADAM(0.001))
Expand Down