Gradients¶
Utilities for approximating gradients.
-
active_subspaces.gradients.
finite_difference_gradients
(X, fun, h=1e-06)¶ Compute finite difference gradients with a given interface.
Parameters: - X (ndarray) – M-by-m matrix that contains the points to estimate the gradients with finite differences
- fun (function) – function that returns the simulation’s quantity of interest given inputs
- h (float, optional) – the finite difference step size (default 1e-6)
Returns: df – M-by-m matrix that contains estimated partial derivatives approximated by finite differences
Return type: ndarray
-
active_subspaces.gradients.
local_linear_gradients
(X, f, p=None, weights=None)¶ Estimate a collection of gradients from input/output pairs.
Given a set of input/output pairs, choose subsets of neighboring points and build a local linear model for each subset. The gradients of these local linear models comprise estimates of sampled gradients.
Parameters: - X (ndarray) – M-by-m matrix that contains the m-dimensional inputs
- f (ndarray) – M-by-1 matrix that contains scalar outputs
- p (int, optional) – how many nearest neighbors to use when constructing the local linear model (default 1)
- weights (ndarray, optional) – M-by-1 matrix that contains the weights for each observation (default None)
Returns: df – M-by-m matrix that contains estimated partial derivatives approximated by the local linear models
Return type: ndarray
Notes
If p is not specified, the default value is floor(1.7*m).