gradient_approximator module¶
Gradient approximation.
Classes:
A factory to create gradient approximators. |
|
|
A gradient approximator. |
- class gemseo.utils.derivatives.gradient_approximator.GradientApproximationFactory[source]¶
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:
The gradient approximators.
- Return type
None
- create(name, f_pointer, step=None, parallel=False, **parallel_args)[source]¶
Create a gradient approximator.
- 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
The gradient approximator.
- Return type
gemseo.utils.derivatives.gradient_approximator.GradientApproximator
- property gradient_approximators¶
The gradient approximators.
- class gemseo.utils.derivatives.gradient_approximator.GradientApproximator(f_pointer, step=1e-06, parallel=False, design_space=None, normalize=True, **parallel_args)[source]¶
Bases:
object
A gradient approximator.
- 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:
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¶
- 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[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
The approximated gradient.
- 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.