Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_threshold_absolute(x, thr, cp):
s = thresholding.threshold_absolute(x, thr, copy=cp)
s_test = [val for arr in s for val in arr if val >= thr] # search for value > thr
assert round(np.sum(s), 10) == round(np.sum(s_test), 10)
def test_thr2prob(x, thr):
s = thresholding.threshold_absolute(thresholding.normalize(x), thr)
s[0][0] = 0.0000001
t = thresholding.thr2prob(s)
assert float(len(t[np.logical_and(t < 0.001, t > 0)])) == float(0.0)
def test_density(x, thr):
d_known = thresholding.est_density(thresholding.threshold_absolute(x, thr, copy=True))
x = thresholding.density_thresholding(x, d_known)
d_test = thresholding.est_density(x)
assert np.equal(np.round(d_known, 1), np.round(d_test, 1))
Thresholded connectivity matrix
References
----------
.. Adapted from Adapted from bctpy
"""
from pynets.core import thresholding
np.fill_diagonal(conn_matrix, 0)
work_thr = 0
i = 1
density = nx.density(nx.from_numpy_matrix(conn_matrix))
if float(thr) < float(density):
while float(i) < max_iters and float(work_thr) < float(1):
work_thr = float(work_thr) + float(interval)
density = nx.density(nx.from_numpy_matrix(thresholding.threshold_absolute(conn_matrix, work_thr)))
print("%s%d%s%.2f%s%.2f%s" % ('Iteration ', i, ' -- with Thresh: ', float(work_thr), ' and Density: ',
float(density), '...'))
if float(thr) >= float(density):
conn_matrix = thresholding.threshold_absolute(conn_matrix, work_thr)
break
i = i + 1
else:
print('Density of raw matrix is already greater than or equal to the target density requested')
return conn_matrix