[Numpy-discussion] any interest in including a second-ordergradient?

David Warde-Farley dwf at cs.toronto.edu
Wed Oct 29 00:14:34 EDT 2008


On 28-Oct-08, at 5:57 PM, Fabrice Silva wrote:

> Are there some parts of the code that may be used only once to  
> calculate
> both the gradient and the second derivative (isn't it called the
> hessian, at least in the N-d case) ?

Probably.  I'd imagine depends on your differencing scheme; central  
differences on the second derivative might imply a need to do two non- 
central differences to sample the gradient at +eps and -eps on each  
axis, respectively.

And yes, the square matrix of second derivatives of an N-d scalar  
function is typically called the Hessian, but some of the properties  
one typically expects from a "Hessian" (i.e. symmetry) are not  
necessarily true unless all of the the partial second derivatives are  
continuous.

> If a common function would fasten the computation of the gradient and
> the hessian with a single call to a new function gradients(), it is
> worth...
> If the intent is just a reduction of the total length of the file
> containing the gradient and gradient2 functions, I do not understand  
> why
> modifying the existent code. Why not creating a new function hessian()
> having the same signature than gradient?

As Stefan mentioned, the number of functions that get included when  
you type "from numpy import *" is already pretty large, and it'd be  
nice not to make it larger. Though you do raise a good point -- if  
it's known that the user wants both the gradient and the Hessian, and  
you can get the first for free while computing the second, then that's  
preferable to having to make two calls and duplicate work.

David



More information about the NumPy-Discussion mailing list