From 77781db9b2211e4f7c6488e6a28184346acdb5bf Mon Sep 17 00:00:00 2001 From: Ross Boylan Date: Sat, 25 Jun 2016 11:34:48 -0700 Subject: [PATCH 1/2] Add test for asymmetric Hessian. This currently fails, though it passes if f5 is uses instead of f6. --- test/derivative.jl | 3 +++ 1 file changed, 3 insertions(+) diff --git a/test/derivative.jl b/test/derivative.jl index c482cc1..84b1531 100644 --- a/test/derivative.jl +++ b/test/derivative.jl @@ -47,3 +47,6 @@ f4(x::Vector) = (100.0 - x[1])^2 + (50.0 - x[2])^2 f5(x) = sin(x[1]) + cos(x[2]) @test norm(Calculus.gradient(f5)([0.0, 0.0]) - [cos(0.0), -sin(0.0)]) < 10e-4 @test norm(hessian(f5)([0.0, 0.0]) - [-sin(0.0) 0.0; 0.0 -cos(0.0)]) < 10e-4 +# PR 91: Asymmetric Hessian +f6(x) = sin(x[1]^2+3x[2]^4) +@test issym(Calculus.hessian(f6, [1.0, 2.0])) From 149da9470ea3c3d484e0b1107d7bb29d89d93c77 Mon Sep 17 00:00:00 2001 From: Ross Boylan Date: Sat, 25 Jun 2016 11:59:26 -0700 Subject: [PATCH 2/2] fix asymmetry of hessian for some code paths There will still be problems if hessian is called with a gradient or with a symbolic differentiantion type argument. This solve the bug reported in PR 91, construed narrowly. That is, the specific invocation that wasn't work now works; the general problem of asymmetric Hessians remains. --- src/derivative.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/derivative.jl b/src/derivative.jl index b1d2432..ddb673e 100644 --- a/src/derivative.jl +++ b/src/derivative.jl @@ -71,13 +71,13 @@ function second_derivative(f::Function, x::Number) finite_difference_hessian(f, derivative(f), x, :central) end function hessian(f::Function, x::Number) - finite_difference_hessian(f, derivative(f), x, :central) + finite_difference_hessian(f, x) end function second_derivative{T <: Number}(f::Function, x::Vector{T}) finite_difference_hessian(f, gradient(f), x, :central) end function hessian{T <: Number}(f::Function, x::Vector{T}) - finite_difference_hessian(f, gradient(f), x, :central) + finite_difference_hessian(f, x) end second_derivative(f::Function, g::Function, dtype::Symbol) = second_derivative(f, g, :scalar, dtype) second_derivative(f::Function, g::Function) = second_derivative(f, g, :scalar, :central)