gemseo.utils.derivatives.finite_differences module#

Gradient approximation by finite differences.

class FirstOrderFD(f_pointer, step=0.0, design_space=None, normalize=True, parallel=False, **parallel_args)[source]#

Bases: BaseGradientApproximator

First-order finite differences approximator.

\[\frac{df(x)}{dx}\approx\frac{f(x+\delta x)-f(x)}{\delta x}\]
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.

compute_optimal_step(x_vect, numerical_error=np.float64(2.220446049250313e-16), **kwargs)[source]#

Compute the gradient by real step.

Parameters:
  • x_vect (ndarray) -- The input vector.

  • numerical_error (float) --

    The numerical error associated to the calculation of \(f\). By default, machine epsilon (appx 1e-16), but can be higher. when the calculation of \(f\) requires a numerical resolution.

    By default it is set to 2.220446049250313e-16.

  • **kwargs -- The additional arguments passed to the function.

Returns:

The optimal steps. The errors.

Return type:

tuple[ndarray, ndarray]