How to use the pynets.core.thresholding.threshold_proportional function in pynets

To help you get started, we’ve selected a few pynets examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github dPys / PyNets / tests / test_thresholding.py View on Github external
def test_normalize(x, thr, cp):
        x = thresholding.threshold_proportional(x, 1, copy=True) # remove diagonal
        s = thresholding.normalize(x)
        assert np.max(s) <= 1 and np.min(s) >= 0
        assert np.max(s) == 1 and np.min(s) == round(min(x.flatten())/max(x.flatten()), 1)
github dPys / PyNets / tests / test_thresholding.py View on Github external
def test_invert(x, thr, cp):
        x_cp = x.copy() # invert modifies array in place and need orig to assert.
        x_cp = thresholding.threshold_proportional(x_cp, thr, copy=cp)
        s = thresholding.invert(x_cp)
        x = x.flatten() # flatten arrays to more easily check s > x.
        s = s.flatten()
        s_gt_x = [inv_val > x[idx] for idx, inv_val in enumerate(s) if inv_val > 0]
        assert False not in s_gt_x
github dPys / PyNets / tests / test_thresholding.py View on Github external
def test_binarize(x, thr, cp):
        y = thresholding.threshold_proportional(x, thr, copy=cp)
        s = thresholding.binarize(y)
        assert np.sum(s) == np.count_nonzero(y)
github dPys / PyNets / pynets / core / thresholding.py View on Github external
elif disp_filt is True:
        thr_type = 'DISP_alpha'
        edge_threshold = "%s%s" % (str(np.abs(1 - thr_perc)), '%')
        G1 = thresholding.disparity_filter(nx.from_numpy_array(conn_matrix))
        # G2 = nx.Graph([(u, v, d) for u, v, d in G1.edges(data=True) if d['alpha'] < thr])
        print('Computing edge disparity significance with alpha = %s' % thr)
        print('Filtered graph: nodes = %s, edges = %s' % (G1.number_of_nodes(), G1.number_of_edges()))
        # print('Backbone graph: nodes = %s, edges = %s' % (G2.number_of_nodes(), G2.number_of_edges()))
        # print(G2.edges(data=True))
        conn_matrix_thr = nx.to_numpy_array(G1)
    else:
        if dens_thresh is False:
            thr_type = 'prop'
            edge_threshold = "%s%s" % (str(np.abs(thr_perc)), '%')
            print("%s%.2f%s" % ('\nThresholding proportionally at: ', thr_perc, '% ...\n'))
            conn_matrix_thr = thresholding.threshold_proportional(conn_matrix, float(thr))
        else:
            thr_type = 'dens'
            edge_threshold = "%s%s" % (str(np.abs(1 - thr_perc)), '%')
            print("%s%.2f%s" % ('\nThresholding to achieve density of: ', thr_perc, '% ...\n'))
            conn_matrix_thr = thresholding.density_thresholding(conn_matrix, float(thr))

    if not nx.is_connected(nx.from_numpy_matrix(conn_matrix_thr)):
        print('Warning: Fragmented graph')

    # Save thresholded mat
    est_path = utils.create_est_path_diff(ID, network, conn_model, thr, roi, dir_path, node_size, target_samples,
                                          track_type, thr_type, parc, directget, max_length)

    utils.save_mat(conn_matrix_thr, est_path)
    gc.collect()