@@ -162,6 +162,7 @@ def format_matrix2(data, s, sc, c, lk, co, idc=[],
162162 return ~ (cmat == 0 )
163163 return cmat
164164
165+ < << << << HEAD
165166def format_matrix3 (data , s , c , b , lk , co , idc = [],
166167 costlist = [], nouptri = False , asbool = True ):
167168 """ Function which formats matrix for a particular subject and
@@ -202,7 +203,7 @@ def format_matrix3(data, s, c, b, lk, co, idc=[],
202203 return ~ (cmat == 0 )
203204 return cmat
204205
205- def threshold_adjacency_matrix (adj_matrix , cost , uptri = False ):
206+ def threshold_adjacency_matrix (adj_matrix , cost , uptri = False , return_thresh = False ):
206207 """threshold adj_matrix at cost
207208
208209 Parameters
@@ -213,12 +214,16 @@ def threshold_adjacency_matrix(adj_matrix, cost, uptri=False):
213214 user specified cost
214215 uptri : bool
215216 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
216219 Returns
217220 -------
218221 thresholded : array of bools
219222 binary matrix thresholded to result in cost
220223 expected_cost : float
221224 the real cost value (closest to cost)
225+ thresh (optional): float
226+ the real threshold value used to result in cost
222227 """
223228 nnodes , _ = adj_matrix .shape
224229 ind = np .triu_indices (nnodes , 1 )
@@ -230,7 +235,10 @@ def threshold_adjacency_matrix(adj_matrix, cost, uptri=False):
230235 np .fill_diagonal (adj_matrix , 0 ) #zero out diagonal
231236 if uptri : #also zero out below diagonal
232237 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
234242
235243def find_true_cost (boolean_matrix ):
236244 """ when passed a boolean matrix, presumably from thresholding to
0 commit comments