complex_step module¶
Gradient approximation by complex step.
Classes:
|
Complex step approximator, performing a second-order gradient calculation. |
- class gemseo.utils.derivatives.complex_step.ComplexStep(f_pointer, step=1e-20, parallel=False, design_space=None, normalize=True, **parallel_args)[source]¶
Bases:
gemseo.utils.derivatives.gradient_approximator.GradientApproximator
Complex step approximator, performing a second-order gradient calculation.
Enable a much lower step than real finite differences, typically 1e-30, since there is no cancellation error due to a difference calculation.
\[\begin{split}\frac{df(x)}{dx} \approx Im\left( \frac{f(x+j*\\delta x)}{\\delta x} \right)\end{split}\]See Martins, Joaquim RRA, Peter Sturdza, and Juan J. Alonso. “The complex-step derivative approximation.” ACM Transactions on Mathematical Software (TOMS) 29.3 (2003): 245-262.
- f_pointer¶
The pointer to the function to derive.
- Type
Callable
Initialize self. See help(type(self)) for accurate signature.
- Parameters
f_pointer (Callable[[ndarray],ndarray]) – The pointer to the function to derive.
step (complex) –
The default differentiation step.
By default it is set to 1e-20.
parallel (bool) –
Whether to differentiate the function in parallel.
By default it is set to False.
design_space (Optional[DesignSpace]) –
The design space containing the upper bounds of the input variables. If None, consider that the input variables are unbounded.
By default it is set to None.
normalize (bool) –
If True, then the functions are normalized.
By default it is set to True.
**parallel_args (Union[int,bool,float]) – The parallel execution options, see
gemseo.core.parallel_execution
.
- Return type
None
Attributes:
The default approximation step.
Methods:
f_gradient
(x_vect[, step, x_indices])Approximate the gradient of the function for a given input vector.
generate_perturbations
(n_dim, x_vect[, ...])Generate the input perturbations from the differentiation step.
- ALIAS = 'complex_step'¶
- f_gradient(x_vect, step=None, x_indices=None, **kwargs)[source]¶
Approximate the gradient of the function for a given input vector.
- Parameters
x_vect (numpy.ndarray) – The input vector.
step (Optional[complex]) –
The differentiation step. If None, use the default differentiation step.
By default it is set to None.
x_indices (Optional[Sequence[int]]) –
The components of the input vector to be used for the differentiation. If None, use all the components.
By default it is set to None.
**kwargs (Any) – The optional arguments for the function.
- Returns
The approximated gradient.
- Return type
numpy.ndarray
- generate_perturbations(n_dim, x_vect, x_indices=None, step=None)¶
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 (numpy.ndarray) – The input vector.
x_indices (Optional[Sequence[int]]) –
The components of the input vector to be used for the differentiation. If None, use all the components.
By default it is set to None.
step (Optional[float]) –
The differentiation step. If None, use the default differentiation step.
By default it is set to None.
- Returns
The input perturbations.
The differentiation step, either one global step or one step by input component.
- Return type
Tuple[numpy.ndarray, Union[float, numpy.ndarray]]
- property step¶
The default approximation step.