-
Notifications
You must be signed in to change notification settings - Fork 113
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
Hessian fails for function of two variables #122
Comments
Recently using this package, I ran into the same error as well. Do we have to manually edit in the fix for these lines, and what is it? Or, would it be fixed in an update to the package? |
I run into a similar, related problem: julia> A = rand(5,5)
5×5 Array{Float64,2}:
0.368021 0.440408 0.659274 0.629533 0.215752
0.0122785 0.74314 0.192229 0.77579 0.937559
0.0333598 0.757276 0.00512945 0.923899 0.312257
0.479558 0.59737 0.238214 0.812611 0.882245
0.25881 0.341119 0.384092 0.239488 0.797613
julia> itp = interpolate(A, BSpline(Cubic(Natural())), OnGrid())
5×5 interpolate(::Array{Float64,2}, BSpline(Cubic(Line())), OnGrid()) with element type Float64:
0.368021 0.440408 0.659274 0.629533 0.215752
0.0122785 0.74314 0.192229 0.77579 0.937559
0.0333598 0.757276 0.00512945 0.923899 0.312257
0.479558 0.59737 0.238214 0.812611 0.882245
0.25881 0.341119 0.384092 0.239488 0.797613
julia> itp[2.5, 2.5]
0.38246048600552157
julia> gradient(itp, 2.5, 2.5)
2-element Array{Float64,1}:
-0.158142
-1.03777
julia> hessian(itp, 2.5, 2.5)
ERROR: UndefVarError: TH not defined
in hessian(::Interpolations.BSplineInterpolation{Float64,2,Array{Float64,2},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,1}, ::Float64, ::Float64) at /home/keaton/.julia/v0.5/Interpolations/src/b-splines/indexing.jl:160 |
The |
Sorry. Use the |
Aha! Clearly I need to learn something about metaprogramming. Still get an error though. Maybe this is what you were referring to with @sglyon 's comment? hessian(itp, 2.5 2.5)
UndefVarError: dim not defined
in hessian_coefficients(::Type{Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}}}, ::Int64, ::Int64, ::Int64) at indexing.jl:19
in hessian_impl(::Type{Interpolations.BSplineInterpolation{Float64,2,Array{Float64,2},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,1}}) at indexing.jl:129
in hessian!(...) at indexing.jl:151
in hessian(::Interpolations.BSplineInterpolation{Float64,2,Array{Float64,2},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,1}, ::Float64, ::Float64) at indexing.jl:160
in include_string(::String, ::String) at loading.jl:441
in eval(::Module, ::Any) at boot.jl:234
in (::Atom.##65#68)() at eval.jl:102
in withpath(::Atom.##65#68, ::Void) at utils.jl:30
in withpath(::Function, ::Void) at eval.jl:38
in macro expansion at eval.jl:101 [inlined]
in (::Atom.##64#67{Dict{String,Any}})() at task.jl:60 I tried it on a one-dimensional interpolation and got this: hessian(sitp, 3.1415)
MethodError: no method matching hessian!(::Array{Float64,2}, ::Interpolations.ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,1},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,Tuple{FloatRange{Float64}}}, ::Float64)
Closest candidates are:
hessian!{T,N}(::AbstractArray{T,2}, !Matched::Interpolations.BSplineInterpolation{T,N,TCoefs<:AbstractArray,IT<:Union{Interpolations.BSpline,Interpolations.NoInterp,Tuple{Vararg{Union{Interpolations.BSpline,Interpolations.NoInterp},N}}},GT<:Union{Interpolations.GridType,Interpolations.NoInterp,Tuple{Vararg{Union{Interpolations.GridType,Interpolations.NoInterp},N}}},pad}, ::Number...) at /home/keaton/.julia/v0.5/Interpolations/src/b-splines/indexing.jl:150
hessian!{T,N}(::AbstractArray{T,2}, !Matched::Interpolations.BSplineInterpolation{T,N,TCoefs<:AbstractArray,IT<:Union{Interpolations.BSpline,Interpolations.NoInterp,Tuple{Vararg{Union{Interpolations.BSpline,Interpolations.NoInterp},N}}},GT<:Union{Interpolations.GridType,Interpolations.NoInterp,Tuple{Vararg{Union{Interpolations.GridType,Interpolations.NoInterp},N}}},pad}, !Matched::CartesianIndex{N}) at /home/keaton/.julia/v0.5/Interpolations/src/b-splines/indexing.jl:155
in hessian(::Interpolations.ScaledInterpolation{Float64,1,Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,1},Interpolations.BSpline{Interpolations.Cubic{Interpolations.Line}},Interpolations.OnGrid,Tuple{FloatRange{Float64}}}, ::Float64) at indexing.jl:160
in include_string(::String, ::String) at loading.jl:441
in eval(::Module, ::Any) at boot.jl:234
in (::Atom.##65#68)() at eval.jl:102
in withpath(::Atom.##65#68, ::Void) at utils.jl:30
in withpath(::Function, ::Void) at eval.jl:38
in macro expansion at eval.jl:101 [inlined]
in (::Atom.##64#67{Dict{String,Any}})() at task.jl:60 |
Yep, that's what I was referring to. Looks like the hessian stuff isn't as well tested as it needs to be. I've not used hessians myself because the optimization routines I use for my problems only exploit the gradient. |
In converting over some code that currently uses Grid.jl, I need to compute the curvature of a surface. The following REPL transcript illustrates the problem I'm having:
This was run using Julia 0.5.0 and Interpolations 0.3.6. Note: I get the same error using OnCell() and when checking out the master version of Interpolations. Is hessian supposed to work for surfaces?
Thanks,
--Peter
The text was updated successfully, but these errors were encountered: