Skip to content

Add a variant of Adam called "PAdam" #148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
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
36 changes: 36 additions & 0 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,42 @@ function apply!(o::AdaBelief, state, x, dx)
return (mt, st, βt .* β), dx′
end

"""
PAdam(η = 1f-2, β = (9f-1, 9.99f-1), ρ = 2.5f-1, eps(typeof(η)))

The partially adaptive momentum estimation method (PADAM) [https://arxiv.org/pdf/1806.06763v1.pdf]

# Parameters
- Learning rate (`η`): Amount by which gradients are discounted before updating
the weights.
- Decay of momentums (`β::Tuple`): Exponential decay for the first (β1) and the
second (β2) momentum estimate.
- Partially adaptive parameter (`p`): Varies between 0 and 0.5.
- Machine epsilon (`ϵ`): Constant to prevent division by zero
(no need to change default)
"""
struct PAdam{T} <: AbstractRule
eta::T
beta::Tuple{T, T}
rho::T
epsilon::T
end
PAdam(η = 1f-2, β = (9f-1, 9.99f-1), ρ = 2.5f-1, ϵ = eps(typeof(η))) = PAdam{typeof(η)}(η, β, ρ, ϵ)

init(o::PAdam, x::AbstractArray) = (onevalue(o.epsilon, x), onevalue(o.epsilon, x), onevalue(o.epsilon, x))

function apply!(o::PAdam, state, x, dx)
η, β, ρ, ϵ = o.eta, o.beta, o.rho, o.epsilon
mt, vt, v̂t = state

@.. mt = β[1] * mt + (1 - β[1]) * dx
@.. vt = β[2] * vt + (1 - β[2]) * abs2(dx)
@.. v̂t = max(v̂t, vt)
dx′ = @lazy η * mt / (v̂t ^ ρ + ϵ)

return (mt, vt, v̂t), dx′
end

"""
WeightDecay(γ = 5f-4)

Expand Down