Module regpy.util.functional_tests
Functions
def test_moreaus_identity(func, u=None, tau=1.0, tolerance=1e-10)
-
Numerically test validity of moreaus identity for a given functional
Checks if: u=prox_{\tau F}(u)+\tau prox_{\frac{1}{\tau}F(\frac{u}{\tau}).
Parameters
func
:Functional
- The functional.
u
:np.ndarray
- Element in domain of func, if None it is chosen at random. Defaults to None.
tau
:float
, optional- Positive number tau in prox
tolerance
:float
, optional- The maximum allowed error in norm. Defaults to 1e-10.
Raises
AssertionError
- If the test fails.
def test_subgradient(func, u=None, v=None, v_length=1e-05, tolerance=1e-10)
-
Numerically test validity of subgradient for a given functional
Checks if: 0\geq F(u)-F(v)+\langle \grad F(u),v-u \rangle.
Parameters
func
:Functional
- The functional.
u
:np.ndarray
, optional- Element in essential domain of func, where gradient is computed. If None it is chosen at random. Defaults to None.
v
:np.ndarray
, optional- Element in domain of func, where gradient is computed. If None it is chosen at random with length given by v_length. Defaults to None.
v_length
:float
, optional- Positive number determining the length of v if it is not given explicitly. Defaults to 1e-5.
tolerance
:float
, optional- The maximum allowed error. Defaults to 1e-10.
Raises
AssertionError
- If the test fails.
def test_young_equality(func, u=None, tolerance=1e-10)
-
Numerically test validity of young equality for a given functional
Checks if: F(u)+F*(u*)=\langle u*,u \rangle. where u* is in the subradient of F at u.
Parameters
func
:Functional
- The functional.
u
:np.ndarray
, optional- Element in essential domain of func, where gradient is computed. If None it is chosen at random. Defaults to None.
tolerance
:float
, optional- The maximum allowed error. Defaults to 1e-10.
Raises
AssertionError
- If the test fails.
def test_functional(func, u_s=None, sample_N=5, test_conj=True, u_stars=None, sample_conj_N=5, print_results=False, tolerance=1e-10)
-
Runs all implemented tests for a given functional. By default tests that cannot be verified because of missing implementations are ignored.
Parameters
func
:Functional
- The functional.
u_s
:list
ofnp.ndarray
, optional- List of elements in essential domain of func. If None it they chosen at random. Defaults to None.
sample_N
:int
, optional- If u_s i None this is the number of randomly generated elements in u_s. Defaults to 5.
test_conj
:bool
, optional- Determines wether the conjugate functional should be tested aswell. Defaluts to True.
u_stars
:list
ofnp.ndarray
, optional- Same as u_s but for conjugate functional. Defaults to None.
sample_conj_N
:int
, optional- Same as sample_N but for conjugate functional. Defaults to 5.
print_results
:bool
, optional- If set to True, further information about test that could not be evaluated because of missing implementations are printed. Defaults to False.
tolerance
:float
, optional- The maximum allowed error. Defaults to 1e-10.
Raises
AssertionError
- If the test fails.