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 Op using both the provided method and a numerical approximation with a perturbation delta applied to a single, randomly selected parameter of the input vector.

Parameters
Oppyproximal.Proximal

Proximal operator to test.

nint

Size of input vector

xnumpy.ndarray, optional

Input vector (if None, randomly drawn from a Normal distribution)

dtypestr, optional

Dtype of vector x to generate (only used when x=None)

deltafloat, optional

Perturbation

rtolfloat, optional

Relative gradtest tolerance

atolfloat, optional

Absolute gradtest tolerance

complexflagbool, optional

Generate random vectors with real (False) or complex (True) entries

raiseerrorbool, optional

Raise error or simply return False when dottest fails

verbbool, optional

Verbosity

backendstr, optional

Backend used for dot test computations (numpy or cupy). This parameter will be used to choose how to create the random vectors.

Returns
passedbool

Passed flag.

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}}\]