finite_difference_hessian is not an exported function in Calculus.jl (yet) If you want to call it directly, you need to use the fully qualified name
Calculus.finite_difference_hessian kl. 13:59:49 UTC+1 tirsdag 21. januar 2014 skrev Hans W Borchers følgende: > > Sorry, but I don't see it. Using Calculus it says > > julia> finite_difference_hessian(sin, 1.0) > ERROR: finite_difference_hessian not defined > > and calling hessian alone returns the old, inaccurate result: > > julia> hessian(sin, 1.0) > -0.841471649579559 > > Looking at the definition of hessian, I'd say it calls > "finite_difference_hessian(f, derivative(f), x, :central)" > so basing the calculation on a derivative function and not on a formula > derived from the Taylor series. > > What did I misunderstand? > Thanks, Hans Werner > > > On Tuesday, January 21, 2014 3:52:37 AM UTC+1, Tim Holy wrote: >> >> Most of the second_derivative stuff in derivative.jl could probably be >> ripped >> out, and have it directly call finite_difference_hessian(f, x). Indeed, >> that >> gets you those two extra orders of magnitude in precision, because >> finite_difference_hessian uses exactly this kind of scaling rule. >> >> --Tim >> >> On Monday, January 20, 2014 10:40:28 AM Hans W Borchers wrote: >> > I looked into the *Calculus* package and its derivative functions. >> First, I >> > got errors when running examples from the README file: >> > >> > julia> second_derivative(x -> sin(x), pi) >> > ERROR: no method eps(DataType,) >> > in finite_difference at >> > /Users/HwB/.julia/Calculus/src/finite_difference.jl:27 >> > in second_derivative at >> /Users/HwB/.julia/Calculus/src/derivative.jl:67 >> > >> > Then I was a bit astonished to see not too accurate results such as >> > >> > julia> abs(second_derivative(sin, 1.0) + sin(1.0)) >> > 6.647716624952338e-7 >> > >> > while, when applying the standard central formula for second >> derivatives, >> > (f(x+h) - 2*f(x) + f(x-h)) / h^2 with the (by theory) suggested step >> length >> > eps^0.25 (for second derivatives) will result in a much better value: >> > >> > julia> h = eps()^0.25; >> > >> > julia> f = sin; x = 1.0; >> > >> > julia> df = (sin(x+h) - 2*sin(x) + sin(x-h)) / h^2 >> > -0.8414709866046906 >> > >> > julia> abs(df + sin(1.0)) >> > 1.7967940468821553e-9 >> > >> > The functions for numerical differentiation in *Calculus* look quite >> > involved, maybe it would be preferable to apply known approaches >> derived >> > from Taylor series. Even the fourth order derivative will in this case >> lead >> > to an absolute error below 1e-05! >> >
