gemseo / utils / derivatives

Show inherited members

complex_step module

Gradient approximation by complex step.

class gemseo.utils.derivatives.complex_step.ComplexStep(f_pointer, step=None, design_space=None, normalize=True, parallel=False, **parallel_args)[source]

Bases: BaseGradientApproximator

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.

Parameters:
  • f_pointer (Callable[[ndarray, Any, ...], ndarray]) – The pointer to the function to derive.

  • step (complex | ndarray | None) – The default differentiation step.

  • 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 (complex | 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

f_pointer: Callable[[ndarray, Any, ...], ndarray]

The pointer to the function to derive.

property step: float

The default approximation step.