@@ -162,7 +162,7 @@ def format_matrix2(data, s, sc, c, lk, co, idc=[],
162162 return ~ (cmat == 0 )
163163 return cmat
164164
165- def threshold_adjacency_matrix (adj_matrix , cost , uptri = False ):
165+ def threshold_adjacency_matrix (adj_matrix , cost , uptri = False , return_thresh = False ):
166166 """threshold adj_matrix at cost
167167
168168 Parameters
@@ -173,12 +173,16 @@ def threshold_adjacency_matrix(adj_matrix, cost, uptri=False):
173173 user specified cost
174174 uptri : bool
175175 False returns symmetric matrix, True zeros out diagonal and below
176+ return_thresh: bool
177+ False returns thresholded correlation matrix and expected cost, True also returns the threshold value
176178 Returns
177179 -------
178180 thresholded : array of bools
179181 binary matrix thresholded to result in cost
180182 expected_cost : float
181183 the real cost value (closest to cost)
184+ thresh (optional): float
185+ the real threshold value used to result in cost
182186 """
183187 nnodes , _ = adj_matrix .shape
184188 ind = np .triu_indices (nnodes , 1 )
@@ -190,7 +194,10 @@ def threshold_adjacency_matrix(adj_matrix, cost, uptri=False):
190194 np .fill_diagonal (adj_matrix , 0 ) #zero out diagonal
191195 if uptri : #also zero out below diagonal
192196 adj_matrix = np .triu (adj_matrix )
193- return adj_matrix , expected_cost
197+ if return_thresh : # also return threshold value
198+ return adj_matrix , expected_cost , thresh
199+ else :
200+ return adj_matrix , expected_cost
194201
195202def find_true_cost (boolean_matrix ):
196203 """ when passed a boolean matrix, presumably from thresholding to
0 commit comments