-
Notifications
You must be signed in to change notification settings - Fork 77
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
Calculus.hessian is not symmetric #91
Comments
Same problem after updating to the latest Julia 0.4 code.
|
So the result of |
Digging into this to find the exact source of asymmetry would lead to a great pull request. |
Using Debug and StackTraces (is there a better way?) I think I may see the problem. The call seems to be routed to the evaluation of the Jacobian of the numerical gradient. The apparent fix would be to send it to There are a number of function definitions for hessian in derivative.jl that have no gradient argument and create one numerically. If the suggested fix is safe, it probably should be done for all. Even if the use of the jacobian worked it appears to involve almost twice as much work as necessary, since it evaluates the derivates for both i, j and j,i. And even if one is using a real gradient, isn't using the current jacobian evaluation likely to be inefficient and probably asymmetric? It looks as if the call goes to
The qualification is that the jacobian function does not appear in the stack trace. I put the breakpoint in the start of my objective function, as a result of which it's called in the first evaluation of the gradient. So I think the stack is that for the closure in which the gradient function is defined via
At the top of |
Moving on to solutions... |
I've been testing the finite difference functionality for Hessians in JuliaNLSolvers/Optim.jl#337 and I agree that there's a problem. https://gist.github.com/pkofod/b4e0338265fac7ab1f4aa87a7d3d655f So the problem I posted has a diagonal matrix as its Hessian, so something is off here. How can it create off-diagonal entries (larger in magnitude than the "real" entries"), when the cross derivatives should be exactly zero? My guess is that the Hessian is not calculated according to the usual method of calculating all combinations, but it rather uses some method where it changes many values at a time? Then maybe it should be possible to switch to the naïve/slow method. I don't have time to look through the Calculus code right now, sorry. If it doesn't get resolved for a while, I might be able to set some time aside at some point. |
Closer inspection of h10 shows all the errors are extremely small; the largest is 4e-8.
My original assumption was that this was the result of numerical noise from calculating the derivatives in different orders. But the code (
finite_difference_hessian!
infinite_difference.jl
) appears to compute only the upper triangle,and then ends with
So maybe the problem is in
copytri!
.The text was updated successfully, but these errors were encountered: