Skip to content

Commit

Permalink
add comments from PR46 (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott authored Mar 7, 2022
1 parent 3858611 commit c1c8beb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Optimisers"
uuid = "3bd65402-5787-11e9-1adc-39752487f4e2"
authors = ["Mike J Innes <mike.j.innes@gmail.com>"]
version = "0.2.2"
version = "0.2.1"

[deps]
ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4"
Expand Down
10 changes: 7 additions & 3 deletions src/rules.jl
Original file line number Diff line number Diff line change
Expand Up @@ -442,20 +442,24 @@ end
"""
WeightDecay(γ = 5f-4)
Decay weights by `γ`.
Decay weights by ``γ``, that is, add `γ .* x` to the gradient `x̄` which will be
subtracted from `x`.
Typically composed with other optimisers as the first transformation in an [`OptimiserChain`](@ref).
This is equivalent to adding ``L_2`` regularization with coefficient ``γ`` to the loss.
# Parameters
- Weight decay (`γ`): Decay applied to weights during optimisation.
"""
struct WeightDecay{T}
wd::T
gamma::T
end
WeightDecay() = WeightDecay(5f-4)

init(o::WeightDecay, x::AbstractArray) = nothing

function apply!(o::WeightDecay, state, x, dx)
dx′ = @lazy dx + o.wd * x
dx′ = @lazy dx + o.gamma * x

return state, dx′
end
Expand Down

2 comments on commit c1c8beb

@mcabbott
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/56146

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.2.1 -m "<description of version>" c1c8bebabf826b3b658c65435e09ae40363f2cd7
git push origin v0.2.1

Please sign in to comment.