# [Scipy-tickets] [SciPy] #1510: Add Hessian method to Scipy

SciPy Trac scipy-tickets@scipy....
Fri Sep 9 04:53:18 CDT 2011

```#1510: Add Hessian method to Scipy
---------------------------------------------------------------+------------
Reporter:  deil                                               |       Owner:  somebody
Type:  enhancement                                        |      Status:  new
Priority:  normal                                             |   Milestone:  Unscheduled
Component:  scipy.optimize                                     |     Version:  0.9.0
Keywords:  Hesse, Hessian, numerical differentiationrical di  |
---------------------------------------------------------------+------------

Comment(by pbrod):

I am the coauthor of numdifftools and I can not guarantee that
numdifftools is bugfree.
There are some situations where the result from numdifftools is not as
accurate as requested. You will find
one  example in this post:

[http://www.mail-archive.com/numpy-discussion@scipy.org/msg28633.html]

Numdifftools does by default determine the best step-size in an
automatic way.  This is not foolproof, but works in most situations for
well behaved functions.
In the example referred to above the automatic stepsize broke down
resulting in that the final stepsize was too big to give an accurate
correctly in the above-mentioned example, but there can always be
constructed examples where numdifftools will not calculate the correct
derivative.)

In the same post
[http://www.mail-archive.com/numpy-discussion@scipy.org/msg28642.html]
Sebastian Walter made me aware of automatic differentiation tools, which
are more robust and more stable than numerical differentiation.  The con
is (as it seems to me) that the call syntax is more complicated.  Here is
software libraries:

[http://en.wikipedia.org/wiki/Automatic_differentiation#Software]

In numdifftools I have made an easy-to-use interface to ScientificPython
and algopy

and compared them to numdifftools for this function (for dimensions of the
problem (N) ranging from 1 to 100):

{{{
import numpy as np

class F:
def __init__(self,N):
A = np.arange(N*N,dtype=float).reshape((N,N))
self.A = np.dot(A.T,A)

def __call__(self, xi):
x = np.array(xi)

tmp = np.dot(self.A,x) #np.array([(x*self.A[i]).sum() for i in
range(self.A.shape[0])])
return 0.5*np.dot(x*x, tmp)

}}}

The accuracy and speed results are shown in the attached files.

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1510#comment:1>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```