JuliaDiff / JuliaDiff/ForwardDiff.jl
derivative of `norm` at 0
Nobody has claimed this yet.
- Dominant language
- Julia
- Stars
- 1k
- Forks
- 160
- PR merge metrics
- No merged PRs in 30d
Description
norm is not differentiable at 0, so at best you can return a subgradient. It appears that the subgradient is 1.0 at 0.0 (and -1.0 at -0.0).
julia> ForwardDiff.gradient(norm, [0.0, 0.0])
2-element Array{Float64,1}:
0.0
1.0
julia> ForwardDiff.gradient(norm, [0.0, -0.0])
2-element Array{Float64,1}:
-0.0
-1.0
I'm wondering if it would be worth it to define Base.norm on ForwardDiff.Dual, and return a subgradient of 0.0 at both 0.0 and -0.0
Also perhaps I missed this, but I think it would be nice to mention somewhere that in generic auto-diffable code sqrt(sum(v.^2)) should be replaced with norm, since sqrt is singular at 0, and produces a NaN when composed with a function with 0 gradient (0*Inf = NaN).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the ForwardDiff.gradient examples for norm at 0.0 and -0.0, then inspect the ForwardDiff.gradient path and the proposed Base.norm behavior for Dual values. Done means the zero cases have a deliberate subgradient behavior and the guidance about replacing sqrt(sum(v.^2)) with norm is addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- julia
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100