threshold.py¶
Utilities for thresholding matrices based on different criteria
author: Stefan McCabe (stefanmccabe at gmail dot com)
Submitted as part of the 2019 NetSI Collabathon.

netrd.utilities.threshold.
threshold
(mat, rule, **kwargs)[source]¶ A flexible interface to other thresholding functions.
 Parameters:
 mat (np.ndarray)
A numpy array.
 rule (str)
A string indicating which thresholding function to invoke.
 kwargs (dict)
Named arguments to pass to the underlying threshold function.
 Returns:
 thresholded_mat
the thresholded numpy array

netrd.utilities.threshold.
threshold_in_range
(mat, **kwargs)[source]¶ Threshold by setting values not within a list of ranges to zero.
 Parameters:
 mat (np.ndarray)
A numpy array.
 cutoffs (list of tuples)
When thresholding, include only edges whose correlations fall within a given range or set of ranges. The lower value must come first in each tuple. For example, to keep those values whose absolute value is between \(0.5\) and \(1\), pass
cutoffs=[(1, 0.5), (0.5, 1)]
.
 Returns:
 thresholded_mat (np.ndarray)
the thresholded numpy array

netrd.utilities.threshold.
threshold_on_degree
(mat, **kwargs)[source]¶ Threshold by setting values below a given quantile to zero.
 Parameters:
 mat (np.ndarray)
A numpy array.
 avg_k (float)
The average degree to target when thresholding the matrix.
 Returns:
 thresholded_mat
the thresholded numpy array

netrd.utilities.threshold.
threshold_on_quantile
(mat, **kwargs)[source]¶ Threshold by setting values below a given quantile to zero.
 Parameters:
 mat (np.ndarray)
A numpy array.
 quantile (float)
The threshold above which to keep an element of the array, e.g., set to zero elements below the 90th quantile of the array.
 Returns:
 thresholded_mat
the thresholded numpy array