magni.cs.reconstruction.it._threshold_operators module

Module providing thresholding operators used in Iterative Thresholding algorithms.

Routine listings

get_function_handle(method)
Return a function handle to a given threshold operator.
threshold_hard(var)
The hard threshold operator.
threshold_none(var)
The “no” threshold operator.
threshold_soft(var)
The soft threshold operator.
threshold_weighted_hard(var)
The weighted hard threshold operator.
threshold_weighted_soft(var)
The weighted soft threshold operator.
magni.cs.reconstruction.it._threshold_operators.get_function_handle(method)[source]

Return a function handle to a given threshold operator method.

Parameters:method (str) – Identifier of the threshold operator to return a handle to.
Returns:f_handle (function) – Handle to threshold method defined in this globals scope.
magni.cs.reconstruction.it._threshold_operators.threshold_hard(var)[source]

Threshold the entries of a vector using the hard threshold.

Parameters:var (dict) – Local variables used in the threshold operation.

Notes

This threshold operation works “in-line” on the variables in var. Hence, this function does not return anything.

Examples

For example, thresholding a vector of values between -1 and 1

>>> import copy, numpy as np, magni
>>> from magni.cs.reconstruction.it._threshold_operators import (
... threshold_hard)
>>> var = {'alpha': np.linspace(-1, 1, 10), 'threshold': 0.4}
>>> threshold_hard(copy.copy(var))
>>> var['alpha']
array([-1.        , -0.77777778, -0.55555556,  0.        ,  0.        ,
        0.        ,  0.        ,  0.55555556,  0.77777778,  1.        ])
magni.cs.reconstruction.it._threshold_operators.threshold_none(var)[source]

Do not threshold the entries of a vector.

Parameters:var (dict) – Local variables used in the threshold operation.

Notes

This is a dummy threshold operation that does nothing.

magni.cs.reconstruction.it._threshold_operators.threshold_soft(var)[source]

Threshold the entries of a vector using the soft threshold.

Parameters:var (dict) – Local variables used in the threshold operation.

Notes

This threshold operation works “in-line” on the variables in var. Hence, this function does not return anything.

Examples

For example, thresholding a vector of values between -1 and 1

>>> import copy, numpy as np, magni
>>> from magni.cs.reconstruction.it._threshold_operators import (
... threshold_soft)
>>> var = {'alpha': np.linspace(-1, 1, 10), 'threshold': 0.4}
>>> threshold_soft(copy.copy(var))
>>> var['alpha']
array([-0.6       , -0.37777778, -0.15555556,  0.        ,  0.        ,
        0.        ,  0.        ,  0.15555556,  0.37777778,  0.6       ])
magni.cs.reconstruction.it._threshold_operators.threshold_weighted_hard(var)[source]

Threshold the entries of a vector using a weighted hard threshold.

Parameters:var (dict) – Local variables used in the threshold operation.

Notes

This threshold operation works “in-line” on the variables in var. Hence, this function does not return anything.

Examples

For example, thresholding a vector of values between -1 and 1

>>> import copy, numpy as np, magni
>>> from magni.cs.reconstruction.it._threshold_operators import (
... threshold_weighted_hard)
>>> var = {'alpha': np.linspace(-1, 1, 10), 'threshold': 0.4,
... 'threshold_weights': 0.7 * np.ones(10)}
>>> threshold_weighted_hard(copy.copy(var))
>>> var['alpha']
array([-1.        , -0.77777778,  0.        ,  0.        ,  0.        ,
        0.        ,  0.        ,  0.        ,  0.77777778,  1.        ])
magni.cs.reconstruction.it._threshold_operators.threshold_weighted_soft(var)[source]

Threshold the entries of a vector using a weighted soft threshold.

Parameters:var (dict) – Local variables used in the threshold operation.

Notes

This threshold operation works “in-line” on the variables in var. Hence, this function does not return anything.

Examples

For example, thresholding a vector of values between -1 and 1

>>> import copy, numpy as np, magni
>>> from magni.cs.reconstruction.it._threshold_operators import (
... threshold_weighted_soft)
>>> var = {'alpha': np.linspace(-1, 1, 10), 'threshold': 0.4,
... 'threshold_weights': 0.7 * np.ones(10)}
>>> threshold_weighted_soft(copy.copy(var))
>>> var['alpha']
array([-0.42857143, -0.20634921,  0.        ,  0.        ,  0.        ,
        0.        ,  0.        ,  0.        ,  0.20634921,  0.42857143])