Skip to content

Commit 8740324

Browse files
author
Courtney Gallen
committed
added uptri flag and diagonal zero-ing, note: breaks tests
1 parent d47460a commit 8740324

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

brainx/util.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def format_matrix2(data, s, sc, c, lk, co, idc=[],
116116
return ~(cmat == 0)
117117
return cmat
118118

119-
def threshold_adjacency_matrix(adj_matrix, cost):
119+
def threshold_adjacency_matrix(adj_matrix, cost, uptri=False):
120120
"""threshold adj_matrix at cost
121121
122122
Parameters
@@ -125,6 +125,8 @@ def threshold_adjacency_matrix(adj_matrix, cost):
125125
graph adjacency matrix
126126
cost : float
127127
user specified cost
128+
uptri : bool
129+
False returns symmetric matrix, True zeros out diagonal and below
128130
Returns
129131
-------
130132
thresholded : array of bools
@@ -138,7 +140,11 @@ def threshold_adjacency_matrix(adj_matrix, cost):
138140
lookup = make_cost_thresh_lookup(adj_matrix)
139141
cost_index = np.round(cost * float(nedges))
140142
thresh, expected_cost, round_cost = lookup[cost_index]
141-
return adj_matrix > thresh, expected_cost
143+
adj_matrix = adj_matrix > thresh #threshold matrix
144+
np.fill_diagonal(adj_matrix, 0) #zero out diagonal
145+
if uptri: #also zero out below diagonal
146+
adj_matrix = np.triu(adj_matrix)
147+
return adj_matrix, expected_cost
142148

143149
def find_true_cost(boolean_matrix):
144150
""" when passed a boolean matrix, presumably from thresholding to

0 commit comments

Comments
 (0)