confused by this root finding example
还没有人认领这个 Issue。
评估
调研方向
使用 issue 中所示的 Roots、ForwardDiff 和 FiniteDiff 调用,重现 MWE 入口点 g1、g2 和 ForwardDiff.derivative。比较两个 find_zero 界限如何影响微分,并确定不同的导数是否符合预期;完成标准是记录原因或确定一项针对性修正。
由索引模型根据 Issue 内容生成。
描述
I have some code which calls a root finding step, via the Roots package that I'd like to be able to differentiate. It appears that whether ForwardDiff "works" in this setting depends on some subtlety that I don't quite understand.
For an MWE, consider finding the (unique) root of the cubic function f(x, k) = (x-k)^3 which has a root at x = k. Let g1(k) = find_zero(x -> f(x, k), [k-1.0,k+1.0]) and similarly let g2(k) = find_zero(x -> f(x, k), [10.0,+10.0]). Note that for values of k between -10 to +10, g1(k) == g2(k). In this range, the only difference between g1 and g2 is that the root finding step in g1 is "aware" of the value of k to look for, via the bounds I have provided, whereas it is ignorant of them in g2. For values of k in this range, the derivatives of g1 and g2 are identical, and equal to 1.0. However, I am seeing that ForwardDiff thinks the derivative of g2 is zero, while it finds the derivative of g1 to be 1.0:
Using Roots, ForwardDiff, FiniteDiff
g0(x,k) = (x-k)^3
g1(k) = find_zero(x -> g0(x,k), [-10.0, +10.0])
g2(k) = find_zero(x -> g0(x,k), [-1.0 * k, +1.0 * k])
Julia reports that the functions are the same, and do vary with the input in the expected way:
ulia> g1(3)
3.0
julia> g2(3)
3.0
julia> g1(4)
4.0
julia> g2(4)
4.0
However, the ForwardDiff gradients are different:
julia> ForwardDiff.derivative(g1, 3.0)
0.0
julia> ForwardDiff.derivative(g2, 3.0)
1.0
Note that FiniteDiff works fine here (up to numerical approximation):
julia> FiniteDiff.finite_difference_derivative(g1, 3.0)
0.9999999999991082
julia> FiniteDiff.finite_difference_derivative(g2, 3.0)
0.9999999999991082
Thanks in advance for any suggestions the ForwardDiff team has in understanding this difference.
- 主要语言
- Julia
- 星标
- 1k
- 派生
- 162
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
JuliaDiff/ForwardDiff.jl 的其他 Issue
-
missing floatmin, floatmax, and issubnormal for Dual可能已有人在做 @devmotion 于 19 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
JuliaDiff/ForwardDiff.jl#852 · 6 条评论 ·
-
`fma` and `muladd` ignore NaN-safe mode可能已有人在做 @devmotion 于 5 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 55/100
JuliaDiff/ForwardDiff.jl#860 ·
-
Enable NaN-safe mode by default可能已有人在做 @devmotion 于 7 天前认领。 未关闭
难度 5/5 一周以上 新手友好度 25/100
JuliaDiff/ForwardDiff.jl#857 · 1 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 52/100
JuliaDiff/ForwardDiff.jl#854 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 75/100
JuliaDiff/ForwardDiff.jl#849 ·
查看 JuliaDiff/ForwardDiff.jl 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 83/100
JuliaGenAI/HuggingFaceDatasets.jl#96 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
JuliaData/DBFTables.jl#50 ·
-
code-review
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 72/100
JuliaNLSolvers/Optim.jl#1296 ·
-
OptimizationCUTEst jobs fail: gfortran not installed on the runner可能已有人在做 @ChrisRackauckas-Claude 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
SciML/SciMLBenchmarks.jl#1946 · 1 条评论 ·
维护者通常 1 天内回复