12
12
#-----------------------------------------------------------------------------
13
13
# Functions
14
14
#-----------------------------------------------------------------------------
15
- def format_matrix (data ,s ,b ,lk ,co ,nouptri = False ):
15
+ def format_matrix (data ,s ,b ,lk ,co ,idc = [], costlist = [], nouptri = False ):
16
16
""" Function which formats matrix for a particular subject and particular block (thresholds, upper-tris it) so that we can make a graph object out of it
17
17
18
18
Parameters:
@@ -25,7 +25,7 @@ def format_matrix(data,s,b,lk,co,nouptri = False):
25
25
"""
26
26
27
27
cmat = data [b ,s ]
28
- th = cost2thresh (co ,s ,b ,lk ,[]) #get the right threshold
28
+ th = cost2thresh (co ,s ,b ,lk ,[], idc , costlist ) #get the right threshold
29
29
30
30
#cmat = replace_diag(cmat) #replace diagonals with zero
31
31
cmat = thresholded_arr (cmat ,th ,fill_val = 0 )
@@ -35,7 +35,7 @@ def format_matrix(data,s,b,lk,co,nouptri = False):
35
35
36
36
return cmat
37
37
38
- def format_matrix2 (data ,s ,sc ,c ,lk ,co ,nouptri = False ):
38
+ def format_matrix2 (data ,s ,sc ,c ,lk ,co ,idc = [], costlist = [], nouptri = False ):
39
39
""" Function which formats matrix for a particular subject and particular block (thresholds, upper-tris it) so that we can make a graph object out of it
40
40
41
41
Parameters:
@@ -48,7 +48,7 @@ def format_matrix2(data,s,sc,c,lk,co,nouptri = False):
48
48
"""
49
49
50
50
cmat = data [sc ,c ,s ]
51
- th = cost2thresh2 (co ,s ,sc ,c ,lk ,[]) #get the right threshold
51
+ th = cost2thresh2 (co ,s ,sc ,c ,lk ,[], idc , costlist ) #get the right threshold
52
52
53
53
#cmat = replace_diag(cmat) #replace diagonals with zero
54
54
cmat = thresholded_arr (cmat ,th ,fill_val = 0 )
@@ -400,7 +400,7 @@ def replace_diag(arr,val=0):
400
400
return arr
401
401
402
402
403
- def cost2thresh (cost ,sub ,bl ,lk ,last ):
403
+ def cost2thresh (cost ,sub ,bl ,lk ,last , idc = [], costlist = [] ):
404
404
"""A definition for loading the lookup table and finding the threshold associated with a particular cost for a particular subject in a particular block
405
405
406
406
inputs:
@@ -422,15 +422,27 @@ def cost2thresh(cost,sub,bl,lk,last):
422
422
th = th [0 ] #if there are multiple thresholds, go down to the lower cost ####Is this right?!!!####
423
423
print 'multiple thresh'
424
424
elif len (th )< 1 :
425
- th = last #if there is no associated thresh value because of repeats, just use the previous one
425
+ done = 1
426
+ while done :
427
+ idc = idc - 1
428
+ newcost = costlist [idc ]
429
+ print idc ,newcost
430
+ ind = np .where (lk [bl ][sub ][1 ]== newcost )
431
+ th = lk [bl ][sub ][0 ][ind ]
432
+ if len (th ) > 1 :
433
+ th = th [0 ]
434
+ done = 0
435
+
436
+ #th=last #if there is no associated thresh value because of repeats, just use the previous one
426
437
print 'use previous thresh'
438
+
427
439
else :
428
440
th = th [0 ]
429
441
430
442
#print th
431
443
return th
432
444
433
- def cost2thresh2 (cost ,sub ,sc ,c ,lk ,last ):
445
+ def cost2thresh2 (cost ,sub ,sc ,c ,lk ,last , idc = [], costlist = [] ):
434
446
"""A definition for loading the lookup table and finding the threshold associated with a particular cost for a particular subject in a particular block
435
447
436
448
inputs:
@@ -452,7 +464,17 @@ def cost2thresh2(cost,sub,sc,c,lk,last):
452
464
th = th [0 ] #if there are multiple thresholds, go down to the lower cost ####Is this right?!!!####
453
465
print 'multiple thresh'
454
466
elif len (th )< 1 :
455
- th = last #if there is no associated thresh value because of repeats, just use the previous one
467
+ done = 1
468
+ while done :
469
+ idc = idc - 1
470
+ newcost = costlist [idc ]
471
+ print idc ,newcost
472
+ ind = np .where (lk [bl ][sub ][1 ]== newcost )
473
+ th = lk [bl ][sub ][0 ][ind ]
474
+ if len (th ) > 1 :
475
+ th = th [0 ]
476
+ done = 0
477
+ #th=last #if there is no associated thresh value because of repeats, just use the previous one
456
478
print 'use previous thresh'
457
479
else :
458
480
th = th [0 ]
0 commit comments