Skip to content

Commit

Permalink
Merge pull request #3 from FluxML/dg/adam
Browse files Browse the repository at this point in the history
add ADAM
  • Loading branch information
DhairyaLGandhi authored Nov 27, 2020
2 parents 77aa33c + f0780c1 commit 7c78a5b
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,26 @@ end
function (o::Descent)(m, m̄, st)
update(o, m, m̄, st)
end

struct ADAM{T,K}
eta::T
beta::Tuple{K,K}
end

const ϵ = 1f-8

function (o::ADAM)(m, m̄, state)
update(o, m, m̄, state)
end

init(o::ADAM, x::AbstractArray) = (zero(x), zero(x), o.beta)
init(o::ADAM, x) = nothing

function apply(o::ADAM, x, Δ, st)
η, β = o.eta, o.beta
mt, vt, βp = st
mt = β[1] .* mt .+ (1f0 .- β[1]) .* Δ
vt = β[2] .* vt .+ (1f0 .- β[2]) .* Δ .^ 2
Δ = mt ./ (1 .- βp[1]) ./ (.√(vt ./ (1f0 .- βp[2])) .+ ϵ) .* η
return Δ, (mt, vt, βp .* β)
end

0 comments on commit 7c78a5b

Please sign in to comment.