GradientPerturbation#
- class GradientPerturbation(func, grad, func_args, grad_args, n_red=1)[source]#
Bases:
ObjectivePerturbation,ABCA class for perturbations performed by decreasing an objective function using the gradient.
- Parameters:
func (
Callable) – The objective function to be perturbed.grad (
Callable) – The gradient function of the objective function.func_args (
List) – The arguments to be passed to the objective function.grad_args (
List) – The arguments to be passed to the gradient function.n_red (
int) – The reduction factor, by default 1.
- Attributes:
- funcFuncWrapper
A wrapped version of the objective function with its arguments.
- gradFuncWrapper
A wrapped gradient function with its arguments.
- n_redint
The number of reduction steps to perform.
- _kint
Keeps track of the number of performed perturbations.
Methods
Perform n_red perturbation steps on the input array.
post_step(x, *args, **kwargs)If required perform any form of step after each perturbation in each iteration.
pre_step(x, *args, **kwargs)If required perform any form of step previous to each perturbation in each iteration.
reset()Reset the perturbation to its initial state.
- perturbation_step(x)#
Perform n_red perturbation steps on the input array.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – The input array to be perturbed.- Return type:
ndarray- Returns:
The perturbed array after applying the reduction steps.
- post_step(x, *args, **kwargs)#
If required perform any form of step after each perturbation in each iteration.
This method is intended to be overridden by subclasses to implement specific post-step logic. By default, it does nothing.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Current iterate.- Return type:
None
- pre_step(x, *args, **kwargs)#
If required perform any form of step previous to each perturbation in each iteration.
This method is intended to be overridden by subclasses to implement specific pre-step logic. By default, it does nothing.
- Parameters:
x (
ndarray[tuple[Any,...],dtype[TypeVar(_ScalarT, bound=generic)]]) – Current iterate.- Return type:
None
- reset()#
Reset the perturbation to its initial state.
- Return type:
None