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 於 17 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 68/100
JuliaDiff/ForwardDiff.jl#852 · 6 則留言 ·
-
`fma` and `muladd` ignore NaN-safe mode可能已有人在做 @devmotion 於 3 天前認領。 未關閉
難度 3/5 1-2 天 新手友好度 55/100
JuliaDiff/ForwardDiff.jl#860 ·
-
Enable NaN-safe mode by default可能已有人在做 @devmotion 於 5 天前認領。 未關閉
難度 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
-
TSDAE's docstring implies a theta argument it does not take可能已有人在做 @singhharsh1708 今天認領。 未關閉documentation
難度 1/5 1 小時以內 新手友好度 74/100
SciML/PETScDiffEq.jl#282 ·
維護者通常 1 天內回覆
-
enhancement good first issue help wanted
難度 2/5 半天 新手友好度 82/100
-
難度 2/5 1-3 小時 新手友好度 78/100
SciML/SciMLBase.jl#1643 ·
維護者通常 2 天內回覆
-
authority-vechtstromen ready-for-agent
難度 1/5 1 小時以內 新手友好度 75/100
Deltares/Ribasim-NL#890 ·
維護者通常 1 天內回覆
-
難度 1/5 1 小時以內 新手友好度 88/100
維護者通常 1 天內回覆