pyproximal.utils.gradtest.gradtest_proximal#
- pyproximal.utils.gradtest.gradtest_proximal(Op, n, x=None, dtype='float64', delta=1e-06, rtol=1e-06, atol=1e-21, complexflag=False, raiseerror=True, verb=False, backend='numpy')[source]#
Gradient test for Proximal operator.
Compute the gradient of
Opusing both the provided method and a numerical approximation with a perturbationdeltaapplied to a single, randomly selected parameter of the input vector.- Parameters
- Op
pyproximal.Proximal Proximal operator to test.
- n
int Size of input vector
- x
numpy.ndarray, optional Input vector (if
None, randomly drawn from a Normal distribution)- dtype
str, optional Dtype of vector
xto generate (only used whenx=None)- delta
float, optional Perturbation
- rtol
float, optional Relative gradtest tolerance
- atol
float, optional Absolute gradtest tolerance
- complexflag
bool, optional Generate random vectors with real (
False) or complex (True) entries- raiseerror
bool, optional Raise error or simply return
Falsewhen dottest fails- verb
bool, optional Verbosity
- backend
str, optional Backend used for dot test computations (
numpyorcupy). This parameter will be used to choose how to create the random vectors.
- Op
- Returns
- passed
bool Passed flag.
- passed
- Raises
- AssertionError
If grad-test is not verified within chosen tolerances.
Notes
A gradient-test is mathematical tool used in the development of numerical nonliner operators.
More specifically, a correct implementation of the gradient for a nonlinear operator should verify the following equality within a numerical tolerance:
\[\frac{\partial Op(\mathbf{x})}{\partial \mathbf{x}} = \frac{Op(\mathbf{x}+\delta \mathbf{x})-Op(\mathbf{x})}{\delta \mathbf{x}}\]