5.1.8.1. numdifftools.nd_statsmodels.Hessian¶
- class Hessian(fun, step=None, method='central', order=None)[source]¶
Calculate Hessian with finite difference approximation
- Parameters
- funfunction
function of one array fun(x, *args, **kwds)
- stepfloat, optional
Stepsize, if None, optimal stepsize is used, i.e., x * _EPS**(1/3) for method==`forward`, complex or central2 x * _EPS**(1/4) for method==`central`.
- method{‘central’, ‘complex’, ‘forward’, ‘backward’}
defines the method used in the approximation.
Examples
>>> import numpy as np >>> import numdifftools.nd_statsmodels as nd
# Rosenbrock function, minimized at [1,1]
>>> rosen = lambda x : (1.-x[0])**2 + 105*(x[1]-x[0]**2)**2 >>> Hfun = nd.Hessian(rosen) >>> h = Hfun([1, 1]) >>> np.allclose(h, [[ 842., -420.], [-420., 210.]]) True
# cos(x-y), at (0,0)
>>> cos = np.cos >>> fun = lambda xy : cos(xy[0]-xy[1]) >>> Hfun2 = nd.Hessian(fun) >>> h2 = Hfun2([0, 0]) >>> np.allclose(h2, [[-1., 1.], [ 1., -1.]]) True
- __init__(fun, step=None, method='central', order=None)¶
Methods
__init__
(fun[, step, method, order])Attributes
method
order