polykin.math.derivatives¤
hessian_forward ¤
hessian_forward(
f: Callable[[FloatVector], float],
x: FloatVector,
*,
fx: float | None = None,
sclx: FloatVector | None = None,
epsf: float | None = None
) -> FloatSquareMatrix
Calculate the numerical Hessian of a scalar function \(f(\mathbf{x})\) using the forward finite-difference scheme.
The step size \(h_j\) is optimally determined according to the machine precision of the function values. Typically, the Hessian is accurate to about a third of the number of reliable digits returned by the function.
References
- J.E. Dennis Jr., R.B. Schnabel, "Numerical Methods for Unconstrained Optimization and Nonlinear Equations", SIAM, 1996, p. 321.
| PARAMETER | DESCRIPTION |
|---|---|
f
|
Function to be differentiated.
TYPE:
|
x
|
Differentiation point.
TYPE:
|
fx
|
Function value at
TYPE:
|
sclx
|
Scaling factors for
TYPE:
|
epsf
|
Machine precision of the function values. If
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
FloatSquareMatrix
|
Hessian matrix. |
Examples:
Evaluate the numerical hessian of f(x) = x1**2 * x2**3 at (2, -2).
>>> from polykin.math import hessian_forward
>>> import numpy as np
>>> def f(x): return x[0]**2 * x[1]**3
>>> hessian_forward(f, np.array([2.0, -2.0]))
array([[-16.00001242, 47.99984347],
[ 47.99984347, -47.99972236]])
Source code in src/polykin/math/derivatives/ndiff.py
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 | |