Precision loss in Hessian computation
维护者通常 1 天内回复
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 15/100
- Issue 类型
- 缺陷
- 描述清晰度
- 需要澄清
- 活跃度
- 活跃
- 领域
- backend
调研方向
Start by running the included MWE, which compares the sparse Hessian from MOI.eval_hessian_lagrangian on MOI.Nonlinear.SparseReverseMode() with ForwardDiff.hessian, and check the entry H[4, 3] (about 1.2e-11 versus 1.2e-11 with a larger absolute error). The cause is the coloring-based Hessian recovery, not the derivative formulas. The maintainers have not chosen a fix among the three options (document, Double64 intermediates, or SparseMatrixColorings star coloring), so decide on the approach with them before writing code.
由索引模型根据 Issue 内容生成。
描述
I'm not sure this is actionable, but it also seems worth doing something about: maybe just documentation, but there are a couple of other options I'll detail below.
This came up while analyzing (with Claude's help) a standard benchmark problem, the CUTEst problem nondquar at n = 5:
(x1 - x2)^2 + (x4 - x5)^2 + Σ_{i=1}^{3} (x_i + x_{i+1} + x_5)^4
Here's the MWE to demonstrate the precision loss:
import MathOptInterface as MOI
import ForwardDiff
# MOI implementation
n = 5
x = [1.0, -1.0, 1.0, -1.0, 1e-6]
v = MOI.VariableIndex.(1:n)
obj = Expr(:call, :+, :(($(v[1]) - $(v[2]))^2), :(($(v[n-1]) - $(v[n]))^2),
(:(($(v[i]) + $(v[i+1]) + $(v[n]))^4) for i in 1:n-2)...)
model = MOI.Nonlinear.Model()
MOI.Nonlinear.set_objective(model, obj)
ev = MOI.Nonlinear.Evaluator(model, MOI.Nonlinear.SparseReverseMode(), v)
MOI.initialize(ev, [:Hess, :HessVec])
st = MOI.hessian_lagrangian_structure(ev)
vals = zeros(length(st))
MOI.eval_hessian_lagrangian(ev, vals, x, 1.0, Float64[])
H = zeros(n, n)
for ((i, j), w) in zip(st, vals)
H[i, j] += w
i == j || (H[j, i] += w)
end
# ForwardDiff implementation
f(z) = (z[1] - z[2])^2 + (z[n-1] - z[n])^2 + sum((z[i] + z[i+1] + z[n])^4 for i in 1:n-2)
Hf = ForwardDiff.hessian(f, x)
Now compare the two Hessians:
julia> H - Hf
5×5 Matrix{Float64}:
0.0 0.0 0.0 0.0 0.0
0.0 4.44089e-16 -4.3416e-17 0.0 0.0
0.0 -4.3416e-17 0.0 4.3416e-17 0.0
0.0 0.0 4.3416e-17 0.0 0.0
0.0 0.0 0.0 0.0 4.44089e-16
You might think everything is fine: errors are ~eps. But they are against a baseline of 1e-11:
julia> H[4, 3]
1.2000043416036534e-11
julia> Hf[4, 3]
1.2e-11
And that's a very large error indeed. At x = [1, -1, 1, -1, 1e-6] every inner sum equals 1e-6 exactly in floating point, so the cross partial ∂²f/∂x3∂x4 = 12·(1e-6)² = 1.2e-11; ForwardDiff's answer is the correct one.
It seems pretty clear this comes from the coloring, and because your coloring is both good and important the paths to fix this are narrow. I currently see three possible options:
- don't fix, just document
- support
Double64, if the user requests it, for intermediate storage - support SparseMatrixColorings (xref #3806), which would allow one to use star coloring
Any thoughts on what you prefer? The documentation or Double64 might be something I could try; I'd probably defer to others for SparseMatrixColorings if they'd be willing to pitch in.
- 主要语言
- Julia
- 星标
- 506
- 派生
- 103
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 9
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
jump-dev/MathOptInterface.jl 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
jump-dev/MathOptInterface.jl#3113 ·
维护者通常 1 天内回复
-
[Bridges] MultirowChange in set_map.jl drops zero coefficients可能已有人在做 @odow 于 6 天前认领。 未关闭
jump-dev/MathOptInterface.jl#3106 · 2 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 35/100
jump-dev/MathOptInterface.jl#2986 · 3 条评论 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 25/100
jump-dev/MathOptInterface.jl#2969 · 2 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
-
Type: Set Request
难度 5/5 一周以上 新手友好度 35/100
jump-dev/MathOptInterface.jl#2904 · 15 条评论 · 7 个 reaction ·
维护者通常 1 天内回复
查看 jump-dev/MathOptInterface.jl 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 83/100
JuliaMath/Polynomials.jl#647 ·
-
难度 2/5 1-3 小时 新手友好度 74/100
OpenSourceAWE/SymbolicAWEModels.jl#431 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
-
难度 2/5 1-3 小时 新手友好度 75/100
JuliaArrays/StaticArrays.jl#1365 ·
-
`@fastmath` reductions are 2–5× slower: no `neutral_element` for `Base.FastMath.max_fast` and co.未关闭
难度 2/5 1-3 小时 新手友好度 86/100
JuliaGPU/GPUArrays.jl#833 ·
维护者通常 1 天内回复