pyproximal.utils.gradtest.gradtest_bilinear#
- pyproximal.utils.gradtest.gradtest_bilinear(Op: BilinearOperator, delta: float = 1e-06, rtol: float = 1e-06, atol: float = 1e-21, complexflag: bool = False, raiseerror: bool = True, verb: bool = False, backend: str = 'numpy') bool[source]#
Gradient test for Bilinear operator.
Compute the gradient of
Opusing both the provided method and a numerical approximation with a perturbationdeltaapplied to a single, randomly selected parameter of either thexoryvectors.- Parameters
- Op
pyproximal.utils.BilinearOperator Bilinear operator to test.
- 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 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}}\]