@@ -162,6 +162,7 @@ def format_matrix2(data, s, sc, c, lk, co, idc=[],
162
162
return ~ (cmat == 0 )
163
163
return cmat
164
164
165
+ < << << << HEAD
165
166
def format_matrix3 (data , s , c , b , lk , co , idc = [],
166
167
costlist = [], nouptri = False , asbool = True ):
167
168
""" Function which formats matrix for a particular subject and
@@ -202,7 +203,7 @@ def format_matrix3(data, s, c, b, lk, co, idc=[],
202
203
return ~ (cmat == 0 )
203
204
return cmat
204
205
205
- def threshold_adjacency_matrix (adj_matrix , cost , uptri = False ):
206
+ def threshold_adjacency_matrix (adj_matrix , cost , uptri = False , return_thresh = False ):
206
207
"""threshold adj_matrix at cost
207
208
208
209
Parameters
@@ -213,12 +214,16 @@ def threshold_adjacency_matrix(adj_matrix, cost, uptri=False):
213
214
user specified cost
214
215
uptri : bool
215
216
False returns symmetric matrix, True zeros out diagonal and below
217
+ return_thresh: bool
218
+ False returns thresholded correlation matrix and expected cost, True also returns the threshold value
216
219
Returns
217
220
-------
218
221
thresholded : array of bools
219
222
binary matrix thresholded to result in cost
220
223
expected_cost : float
221
224
the real cost value (closest to cost)
225
+ thresh (optional): float
226
+ the real threshold value used to result in cost
222
227
"""
223
228
nnodes , _ = adj_matrix .shape
224
229
ind = np .triu_indices (nnodes , 1 )
@@ -230,7 +235,10 @@ def threshold_adjacency_matrix(adj_matrix, cost, uptri=False):
230
235
np .fill_diagonal (adj_matrix , 0 ) #zero out diagonal
231
236
if uptri : #also zero out below diagonal
232
237
adj_matrix = np .triu (adj_matrix )
233
- return adj_matrix , expected_cost
238
+ if return_thresh : # also return threshold value
239
+ return adj_matrix , expected_cost , thresh
240
+ else :
241
+ return adj_matrix , expected_cost
234
242
235
243
def find_true_cost (boolean_matrix ):
236
244
""" when passed a boolean matrix, presumably from thresholding to
0 commit comments