Module regpy.util.operator_tests
Functions
def test_linearity(op, tolerance=1e-10)
-
Numerically tests if operator is linear.
Checks if :: op(x+y) == op(x)+op(y) rop(x) == op(rx) for random choices of
x
andy
.Parameters
op
:Operator
- The operator.
tolerance
:float
, optional- The maximum allowed difference between the results. Defaults to 1e-10.
Raises
AssertionError
- If the test fails.
def test_adjoint(op, tolerance=1e-10)
-
Numerically test validity of :meth:
adjoint
method.Checks if ::
inner(y, op(x)) == inner(op.adjoint(x), y)
in :math:
L^2
up to some tolerance for random choices ofx
andy
.Parameters
op
:Operator
- The operator.
tolerance
:float
, optional- The maximum allowed difference between the inner products. Defaults to 1e-10.
Raises
AssertionError
- If the test fails.
def test_derivative(op, steps=[0.1, 0.01, 0.001, 0.0001, 1e-05, 1e-06, 1e-07], ret_sequence=False)
-
Numerically test derivative of operator.
Computes ||\frac{F(x+tv)-F(x)}{t}-F'(x)v|| for randomly chosen
x
andv
and differentt
given in steps.Parameters
op
:Operator
- The operator.
steps
:float
, optional- The used steps. Defaults to [1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7].
ret_sequence
:bool
, optional- If set to true the sequence of errors is returned else it is asserted that this sequence is decreasing. Defaults to False.
Returns
list
offloat (optional)
- List of computed differences, one for each step. Only if ret_sequence is True.
def test_adjoint_derivative(op, tolerance=1e-10)
def test_operator(op, sample_N=5, tolerance=1e-10, steps=[0.1, 0.01, 0.001, 0.0001, 1e-05, 1e-06, 1e-07], adjoint_derivative=False)
-
Numerically tests if operator is computed correctly.
Checks if operator is linear and if adjoint is correct for linear operators. Checks if derivative is correct by computing sequence of difference quotients and checking if they are decreasing. Checks if derivative is linear with correct adjoint. Optionally checks correctness of adjoint derivative.
Parameters
op
:Operator
- The operator.
tolerance
:float
, optional- The maximum allowed difference between the results. Defaults to 1e-10.
steps
:list
offloat
, optional- Steps used for the computation for the difference quotients. Should be chosen according to the expected regularity of the operator. Defaults to [1e-1,1e-2,1e-3,1e-4,1e-5,1e-6,1e-7].
adjoint_derivative
:bool
, optional- If true the adjoint_derivative is also checked. Defaults to False.
Raises
AssertionError
- If the test fails.