derivkit.calculus.gradient module#

Contains functions used to construct the gradient of scalar-valued functions.

derivkit.calculus.gradient.build_gradient(function: Callable, theta0: ndarray, method: str | None = None, n_workers=1, **dk_kwargs: dict) ndarray#

Returns the gradient of a scalar-valued function.

Parameters:
  • function – The function to be differentiated.

  • theta0 – The parameter vector at which the gradient is evaluated.

  • method – Method name or alias (e.g., "adaptive", "finite"). If None, the derivkit.derivative_kit.DerivativeKit default ("adaptive") is used.

  • n_workers – Number of workers used by derivkit.derivative_kit.DerivativeKit.differentiate(). This setting does not parallelize across parameters. Default is 1.

  • dk_kwargs – Additional keyword arguments passed to derivkit.derivative_kit.DerivativeKit.differentiate().

Returns:

A 1D array representing the gradient.

Raises:

TypeError – If function does not return a scalar value.