@@ -117,15 +117,37 @@ def format_matrix2(data, s, sc, c, lk, co, idc=[],
117
117
return cmat
118
118
119
119
def threshold_adjacency_matrix (adj_matrix , cost ):
120
- """docstring for threshold_adjacency_matrix(adj_matrix, cost"""
120
+ """threshold adj_matrix at cost
121
+
122
+ Parameters
123
+ ----------
124
+ adj_matrix : numpy array
125
+ graph adjacency matrix
126
+ cost : float
127
+ user specified cost
128
+ Returns
129
+ -------
130
+ thresholded : array of bools
131
+ binary matrix thresholded to result in cost
132
+ expected_cost : float
133
+ the real cost value (closest to cost)
134
+ """
121
135
nnodes , _ = adj_matrix .shape
122
136
ind = np .triu_indices (nnodes , 1 )
123
137
nedges = adj_matrix [ind ].shape [0 ]
124
138
lookup = make_cost_thresh_lookup (adj_matrix )
125
139
cost_index = np .round (cost * float (nedges ))
126
- thresh , actual_cost , round_cost = lookup [cost_index ]
127
- return adj_matrix > thresh , actual_cost
128
-
140
+ thresh , expected_cost , round_cost = lookup [cost_index ]
141
+ return adj_matrix > thresh , expected_cost
142
+
143
+ def find_true_cost (boolean_matrix ):
144
+ """ when passed a boolean matrix, presumably from thresholding to
145
+ achieve a specific cost, this calculates the actual cost for
146
+ this thresholded array"""
147
+ ind = np .triu_indices_from ( boolean_matrix , 1 )
148
+ alledges = np .array (boolean_matrix )[ind ].shape [0 ]
149
+ found_edges = boolean_matrix [ind ].sum ()
150
+ return float (found_edges ) / alledges
129
151
130
152
def all_positive (adjacency_matrix ):
131
153
""" checks if edge values in adjacency matrix are all positive
0 commit comments