gemseo / utils / derivatives

Classes:

 A factory to create gradient approximators. GradientApproximator(f_pointer[, step, ...]) A gradient approximator.

Bases: object

A factory to create gradient approximators.

Methods:

 create(name, f_pointer[, step, parallel]) Create a gradient approximator. is_available(class_name) Whether a gradient approximator is available.

Attributes:

 gradient_approximators The gradient approximators.
Return type

None

create(name, f_pointer, step=None, parallel=False, **parallel_args)[source]

Parameters
• name (str) – Either the name of the class implementing the gradient approximator or its alias.

• f_pointer (Callable) – The pointer to the function to differentiate.

• step (Optional[float]) –

The differentiation step. If None, use a default differentiation step.

By default it is set to None.

• parallel (bool) –

Whether to differentiate the function in parallel.

By default it is set to False.

• **parallel_args – The parallel execution options, see gemseo.core.parallel_execution.

Returns

Return type

is_available(class_name)[source]

Whether a gradient approximator is available.

Parameters

class_name – The name of the class implementing the gradient approximator.

Returns

Whether the gradient approximator is available.

Return type

bool

Bases: object

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 (float) –

The default differentiation step.

By default it is set to 1e-06.

• 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:

 ALIAS step 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 = None

Approximate the gradient of the function for a given input vector.

Parameters
• x_vect (numpy.ndarray) – The input vector.

• step (Optional[float]) –

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

Return type

numpy.ndarray

generate_perturbations(n_dim, x_vect, x_indices=None, 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 (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.