Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The Hessian of x-> dot(x,H,x) should be H+H', not zero #551

Closed
wmkoolen opened this issue Oct 22, 2021 · 1 comment · Fixed by #481
Closed

The Hessian of x-> dot(x,H,x) should be H+H', not zero #551

wmkoolen opened this issue Oct 22, 2021 · 1 comment · Fixed by #481

Comments

@wmkoolen
Copy link

Hi all,

ForwardDiff incorrectly computes the Hessian of three-argument-dot.

Cook up some (any) square matrix
julia> H = [1 2 3; 4 5 6; 7 8 9];

Compute Hessian of three-argument dot. Yields all zeros. Should yield H+H'.
julia> ForwardDiff.hessian(x->dot(x,H,x), zeros(3))
3×3 Array{Float64,2}:
0.0 0.0 0.0
0.0 0.0 0.0
0.0 0.0 0.0

Manually expand that three argument dot call. Now result is the expected H+H':
julia> ForwardDiff.hessian(x->x'H*x, zeros(3))
3×3 Array{Float64,2}:
2.0 6.0 10.0
6.0 10.0 14.0
10.0 14.0 18.0

Curious!

Cheers,

Wouter

@mcabbott
Copy link
Member

mcabbott commented Oct 22, 2021

Notice that if you give slightly nonzero arguments, you get different results:

julia> H = [1 2 3; 4 5 6; 7 8 9];

julia> ForwardDiff.hessian(x->dot(x,H,x), zeros(3))
3×3 Matrix{Float64}:
 0.0  0.0  0.0
 0.0  0.0  0.0
 0.0  0.0  0.0

julia> ForwardDiff.hessian(x->dot(x,H,x), [0,0,0.0001])
3×3 Matrix{Float64}:
 0.0  0.0   3.0
 0.0  0.0   6.0
 3.0  6.0  18.0

julia> ForwardDiff.hessian(x->dot(x,H,x), fill(0.00001, 3))
3×3 Matrix{Float64}:
  2.0   6.0  10.0
  6.0  10.0  14.0
 10.0  14.0  18.0

So dot must be taking shortcuts when it knows x is zero. This is fixed by #481.

mcabbott added a commit to mcabbott/ForwardDiff.jl that referenced this issue Nov 2, 2021
mcabbott added a commit to mcabbott/ForwardDiff.jl that referenced this issue Nov 2, 2021
mcabbott added a commit to mcabbott/ForwardDiff.jl that referenced this issue Nov 9, 2021
mcabbott added a commit to mcabbott/ForwardDiff.jl that referenced this issue Apr 23, 2022
mcabbott added a commit to mcabbott/ForwardDiff.jl that referenced this issue Apr 24, 2022
mcabbott added a commit to mcabbott/ForwardDiff.jl that referenced this issue May 16, 2022
mcabbott added a commit to mcabbott/ForwardDiff.jl that referenced this issue May 31, 2022
mcabbott added a commit to mcabbott/ForwardDiff.jl that referenced this issue Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants