pyproximal.utils.gradtest.gradtest_bilinear#

pyproximal.utils.gradtest.gradtest_bilinear(Op, delta=1e-06, rtol=1e-06, atol=1e-21, complexflag=False, raiseerror=True, verb=False, backend='numpy')[source]#

Gradient test for Bilinear 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 either the x or y vectors.

Parameters
Oppyproximal.utils.BilinearOperator

Bilinear operator to test.

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 bilinear operators.

More specifically, a correct implementation of the gradient for a bilinear operator should verify the following equalities within a numerical tolerance:

\[\frac{\partial Op(\mathbf{x})}{\partial \mathbf{x}} = \frac{Op(\mathbf{x}+\delta \mathbf{x}, \mathbf{y})- Op(\mathbf{x})}{\delta \mathbf{x}, \mathbf{y}}\]

and

\[\frac{\partial Op(\mathbf{x}, \mathbf{y})}{\partial \mathbf{y}} = \frac{Op(\mathbf{x}, \mathbf{y}+\delta \mathbf{y})- Op(\mathbf{x}, \mathbf{y})}{\delta \mathbf{y}}\]