@@ -162,6 +162,46 @@ def format_matrix2(data, s, sc, c, lk, co, idc=[],
162
162
return ~ (cmat == 0 )
163
163
return cmat
164
164
165
+ def format_matrix3 (data , s , c , b , lk , co , idc = [],
166
+ costlist = [], nouptri = False , asbool = True ):
167
+ """ Function which formats matrix for a particular subject and
168
+ particular block (thresholds, upper-tris it) so that we can
169
+ make a graph object out of it
170
+
171
+ Parameters
172
+ ----------
173
+ data : numpy array
174
+ full data array 5D (subcondition, condition, subject, node, node)
175
+ s : int
176
+ index of subject
177
+ c : int
178
+ index of condition
179
+ b : int
180
+ index of block
181
+ lk : numpy array
182
+ lookup table for thresholds at each possible cost
183
+ co : float
184
+ cost value to threshold at
185
+ idc : float
186
+ ideal cost
187
+ costlist : list
188
+ list of possible costs
189
+ nouptri : bool
190
+ False zeros out diag and below, True returns symmetric matrix
191
+ asbool : bool
192
+ If true returns boolean mask, otherwise returns thresholded w
193
+ weighted matrix
194
+ """
195
+ cmat = slice_data (data , s , b , c )
196
+ th = cost2thresh2 (co ,s ,c ,b ,lk ,[],idc ,costlist ) #get the right threshold
197
+ cmat = thresholded_arr (cmat ,th ,fill_val = 0 )
198
+ if not nouptri :
199
+ cmat = np .triu (cmat ,1 )
200
+ if asbool :
201
+ # return boolean mask
202
+ return ~ (cmat == 0 )
203
+ return cmat
204
+
165
205
def threshold_adjacency_matrix (adj_matrix , cost , uptri = False ):
166
206
"""threshold adj_matrix at cost
167
207
@@ -317,6 +357,26 @@ def store_metrics(b, s, co, metd, arr):
317
357
318
358
for met_name , met_val in metd .iteritems ():
319
359
arr [idx ][met_name ] = met_val
360
+
361
+
362
+ def store_metrics2 (c , b , s , co , metd , arr ):
363
+ """Store a set of metrics into a structured array
364
+ c = condition
365
+ b = block
366
+ s = subject
367
+ co = cost? float
368
+ metd = dict of metrics
369
+ arr : array?"""
370
+
371
+ if arr .ndim == 4 :
372
+ idx = c ,b ,s ,co
373
+ elif arr .ndim == 5 :
374
+ idx = c ,b ,s ,co ,slice (None )
375
+ else :
376
+ raise ValueError ("only know how to handle 4 or 5-d arrays" )
377
+
378
+ for met_name , met_val in metd .iteritems ():
379
+ arr [idx ][met_name ] = met_val
320
380
321
381
322
382
def regular_lattice (n ,k ):
0 commit comments