@@ -128,20 +128,34 @@ def make_cost_thresh_lookup(adjacency_matrix):
128
128
adjacency matrix, sorts (lowest -> highest)
129
129
Returns
130
130
-------
131
- lookup : numpy array
132
- 3 X number_of_edges, numpy array
133
- row 0 is sorted thresholds (largest -> smallest)
134
- row 1 is cost at each threshold (smallest -> largest)
135
- row 2 is costs rounded to one decimal point
131
+ lookup : numpy record array
132
+ shape = number of edges
133
+ 'weight' is sorted weight values (largest -> smallest)
134
+ 'actual_cost' is cost at each weight (smallest -> largest)
135
+ 'cost' is 'actual_costs' rounded to two decimal points
136
+ Example
137
+ -------
138
+ lookup = make_cost_thresh_lookup(adj_mat)
139
+ lookup[100]
140
+ (0.3010111736597483, 0.704225352112676, 0.7)
141
+ lookup[100].weight
142
+ 0.3010111736597483
143
+ lookup[100].actual_cost
144
+ 0.704225352112676
145
+ lookup[100].cost
146
+ 0.70
147
+
136
148
"""
137
149
138
150
ind = np .triu_indices_from (adjacency_matrix , k = 1 )
139
151
edges = adjacency_matrix [ind ]
140
152
nedges = edges .shape [0 ]
141
- lookup = np .zeros ((3 , nedges ))
142
- lookup [0 ,:] = sorted (edges , reverse = True )
143
- lookup [1 ,:] = np .arange (nedges ) / float (nedges )
144
- lookup [2 ,:] = np .round (lookup [1 ,:], decimals = 2 )
153
+ lookup = np .recarray ((nedges ), dtype = [('weight' , float ),
154
+ ('actual_cost' , float ),
155
+ ('cost' , float )])
156
+ lookup ['weight' ] = sorted (edges , reverse = True )
157
+ lookup ['actual_cost' ] = np .arange (nedges ) / float (nedges )
158
+ lookup ['cost' ] = np .round (lookup ['actual_cost' ], decimals = 2 )
145
159
return lookup
146
160
147
161
def cost_size (nnodes ):
0 commit comments