polykin.math.derivatives¤
hessian_forward ¤
hessian_forward(
f: Callable[[FloatVector], float],
x: FloatVector,
*,
fx: float | None = None,
sclx: FloatVector | None = None,
ndigit: int | 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 number of reliable digits of \(f\) and the magnitude and scale of each \(\mathbf{x}\) component.
Typically, the first ndigit/3 digits of the Hessian are accurate.
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 diferentiated.
TYPE:
|
x
|
Differentiation point.
TYPE:
|
fx
|
Function values at
TYPE:
|
sclx
|
Scaling factors for
TYPE:
|
ndigit
|
Number of reliable base-10 digits in the values returned by
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.0001093 , 47.99984347],
[ 47.99984347, -47.99979503]])
Source code in src/polykin/math/derivatives/ndiff.py
205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | |