Python Sparse data Analysis Package external MRI plugin.
Source code for mri.operators.gradient.utils
# -*- coding: utf-8 -*-
##########################################################################
# pySAP - Copyright (C) CEA, 2017 - 2018
# Distributed under the terms of the CeCILL-B license, as published by
# the CEA-CNRS-INRIA. Refer to the LICENSE file or to
# http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
# for details.
##########################################################################
"""
This module contains all the utils tools needed in the p_MRI reconstruction.
"""
# System import
# Package import
# Third party import
import numpy as np
[docs]def check_lipschitz_cst(f, x_shape, lipschitz_cst, max_nb_of_iter=10):
"""
This methods check that for random entrees the lipschitz constraint are
statisfied:
* ||f(x)-f(y)|| < lipschitz_cst ||x-y||
Parameters
----------
f: callable
This lipschitzien function
x_shape: tuple
Input data shape
lipschitz_cst: float
The Lischitz constant for the function f
max_nb_of_iter: int
The number of time the constraint must be satisfied
Returns
-------
out: bool
If is True than the lipschitz_cst given in argument seems to be an
upper bound of the real lipschitz constant for the function f
"""
is_lips_cst = True
n = 0
while is_lips_cst and n < max_nb_of_iter:
n += 1
x = np.random.randn(*x_shape)
y = np.random.randn(*x_shape)
is_lips_cst = (np.linalg.norm(f(x)-f(y)) <= (lipschitz_cst *
np.linalg.norm(x-y)))
return is_lips_cst
Follow us