gemseo.utils.derivatives.base_gradient_approximator module#
Gradient approximation.
- class BaseGradientApproximator(f_pointer, step=0.0, design_space=None, normalize=True, parallel=False, **parallel_args)[source]#
Bases:
objectA base class for gradient approximation.
- Parameters:
f_pointer (Callable[[ndarray, Any, ...], ndarray]) -- The pointer to the function to derive.
step (complex | ndarray) --
The default differentiation step. If
0.0, use a default value specific to the gradient approximation method.By default it is set to 0.0.
design_space (DesignSpace | None) -- The design space containing the upper bounds of the input variables. If
None, consider that the input variables are unbounded.normalize (bool) --
Whether to normalize the function.
By default it is set to True.
parallel (bool) --
Whether to differentiate the function in parallel.
By default it is set to False.
**parallel_args (Any) -- The parallel execution options, see
gemseo.core.parallel_execution.
- f_gradient(x_vect, step=None, x_indices=(), **kwargs)[source]#
Approximate the gradient of the function for a given input vector.
- Parameters:
x_vect (ndarray) -- The input vector.
step (float | None) -- The differentiation step. If
None, use the default differentiation step.x_indices (Sequence[int]) --
The components of the input vector to be used for the differentiation. If empty, use all the components.
By default it is set to ().
**kwargs (Any) -- The optional arguments for the function.
- Returns:
The approximated gradient.
- Return type:
ndarray
- generate_perturbations(n_dim, x_vect, x_indices=(), step=None)[source]#
Generate the input perturbations from the differentiation step.
These perturbations will be used to compute the output ones.
- Parameters:
n_dim (int) -- The input dimension.
x_vect (ndarray) -- The input vector.
x_indices (Sequence[int]) --
The components of the input vector to be used for the differentiation. If empty, use all the components.
By default it is set to ().
step (float | None) -- The differentiation step. If
None, use the default differentiation step.
- Returns:
The input perturbations.
The differentiation step, either one global step or one step by input component.
- Return type:
- f_pointer: Callable[[ndarray, Any, ...], ndarray]#
The pointer to the function to derive.