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 (Callable) – The function to be differentiated.
theta0 (array-like) – The parameter vector at which the gradient is evaluated.
method – Method name or alias (e.g., “adaptive”, “finite”). If None, the DerivativeKit default (“adaptive”) is used.
n_workers (int) – Number of workers used by DerivativeKit.adaptive.differentiate. This setting does not parallelize across parameters. Default is 1.
dk_kwargs (dict, optional) – Additional keyword arguments passed to DerivativeKit.differentiate.
- Returns:
A 1D array representing the gradient.
- Raises:
TypeError – If
functiondoes not return a scalar value.