@@ -54,19 +54,15 @@ def format_matrix(data,s,b,lk,co,idc = [],costlist=[],nouptri = False):
54
54
costlist = list (size num_edges) with ordered values used to find
55
55
threshold to control number of edges
56
56
nouptri = if False only keeps upper tri, True yields symmetric matrix
57
- """
58
-
57
+ """
59
58
cmat = data [b ,s ]
60
59
th = cost2thresh (co ,s ,b ,lk ,idc ,costlist ) #get the right threshold
61
-
62
- #cmat = replace_diag(cmat) #replace diagonals with zero
63
60
cmat = thresholded_arr (cmat ,th ,fill_val = 0 )
64
-
65
61
if not nouptri :
66
62
cmat = np .triu (cmat ,1 )
67
-
68
63
return cmat
69
64
65
+
70
66
def format_matrix2 (data ,s ,sc ,c ,lk ,co ,idc = [],costlist = [],nouptri = False ):
71
67
""" Function which formats matrix for a particular subject and
72
68
particular block (thresholds, upper-tris it) so that we can
@@ -92,28 +88,28 @@ def format_matrix2(data,s,sc,c,lk,co,idc = [],costlist=[],nouptri = False):
92
88
list of possible costs
93
89
nouptri : bool
94
90
False zeros out diag and below, True returns symmetric matrix
95
- """
91
+ """
96
92
cmat = slice_data (data , s , c , sc )
97
- #cmat = data[sc,c,s]
98
93
th = cost2thresh2 (co ,s ,sc ,c ,lk ,[],idc ,costlist ) #get the right threshold
99
-
100
- #cmat = replace_diag(cmat) #replace diagonals with zero
101
94
cmat = thresholded_arr (cmat ,th ,fill_val = 0 )
102
-
103
95
if not nouptri :
104
96
cmat = np .triu (cmat ,1 )
105
-
106
97
# return boolean mask
107
98
return ~ (cmat == 0 )
108
99
109
100
def threshold_adjacency_matrix (adj_matrix , cost ):
110
101
"""docstring for threshold_adjacency_matrix(adj_matrix, cost"""
111
-
112
- pass
102
+ nnodes , _ = adj_matrix .shape
103
+ ind = np .triu_indices (nnodes , 1 )
104
+ nedges = adj_matrix [ind ].shape [0 ]
105
+ lookup = make_cost_thresh_lookup (adj_matrix )
106
+ cost_index = np .round (cost * float (nedges ))
107
+ thresh , actual_cost , round_cost = lookup [cost_index ]
108
+ return adj_matrix > thresh , actual_cost
113
109
114
110
115
111
def all_positive (adjacency_matrix ):
116
- """ checks if edge value sin adjacency matrix are all positive
112
+ """ checks if edge values in adjacency matrix are all positive
117
113
or positive and negative
118
114
Returns
119
115
-------
0 commit comments