5.1.6.4. numdifftools.nd_algopy.Hessdiag¶
-
class
Hessdiag
(f, method='forward', full_output=False)[source]¶ Calculate Hessian diagonal with Algorithmic Differentiation method
Parameters: - fun : function
function of one array fun(x, *args, **kwds)
- method : string, optional {‘forward’, ‘reverse’}
defines method used in the approximation
Returns: - hessdiag : ndarray
Hessian diagonal array of partial second order derivatives.
See also
Notes
Algorithmic differentiation is a set of techniques to numerically evaluate the derivative of a function specified by a computer program. AD exploits the fact that every computer program, no matter how complicated, executes a sequence of elementary arithmetic operations (addition, subtraction, multiplication, division, etc.) and elementary functions (exp, log, sin, cos, etc.). By applying the chain rule repeatedly to these operations, derivatives of arbitrary order can be computed automatically, accurately to working precision, and using at most a small constant factor more arithmetic operations than the original program.
References
Sebastian F. Walter and Lutz Lehmann 2013, “Algorithmic differentiation in Python with AlgoPy”, in Journal of Computational Science, vol 4, no 5, pp 334 - 344, http://www.sciencedirect.com/science/article/pii/S1877750311001013
https://en.wikipedia.org/wiki/Automatic_differentiation
Examples
>>> import numdifftools.nd_algopy as nda
# Rosenbrock function, minimized at [1,1]
>>> rosen = lambda x : (1.-x[0])**2 + 105*(x[1]-x[0]**2)**2 >>> Hfun = nda.Hessdiag(rosen) >>> h = Hfun([1, 1]) # h =[ 842, 210] >>> np.allclose(h, [ 842., 210.]) True
# cos(x-y), at (0,0)
>>> cos = np.cos >>> fun = lambda xy : cos(xy[0]-xy[1]) >>> Hfun2 = nda.Hessdiag(fun) >>> h2 = Hfun2([0, 0]) # h2 = [-1, -1] >>> np.allclose(h2, [-1., -1.]) True
>>> Hfun3 = nda.Hessdiag(fun, method='reverse') >>> h3 = Hfun3([0, 0]) # h2 = [-1, -1]; >>> np.allclose(h3, [-1., -1.]) True
Methods
__call__
(x, *args, **kwds)Call self as a function. -
__init__
(f, method='forward', full_output=False)¶ Initialize self. See help(type(self)) for accurate signature.
Methods
__init__
(f[, method, full_output])Initialize self. computational_graph
(x, *args, **kwds)Attributes
fun