Skip to content

Commit 1f19978

Browse files
author
Emi Nomura
committed
Fixed cost2thresh so that it searches for the last cost if missing.
1 parent a4fec43 commit 1f19978

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

brainx/util.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#-----------------------------------------------------------------------------
1313
# Functions
1414
#-----------------------------------------------------------------------------
15-
def format_matrix(data,s,b,lk,co,nouptri = False):
15+
def format_matrix(data,s,b,lk,co,idc = [],costlist=[],nouptri = False):
1616
""" 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
1717
1818
Parameters:
@@ -25,7 +25,7 @@ def format_matrix(data,s,b,lk,co,nouptri = False):
2525
"""
2626

2727
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
2929

3030
#cmat = replace_diag(cmat) #replace diagonals with zero
3131
cmat = thresholded_arr(cmat,th,fill_val=0)
@@ -35,7 +35,7 @@ def format_matrix(data,s,b,lk,co,nouptri = False):
3535

3636
return cmat
3737

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):
3939
""" 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
4040
4141
Parameters:
@@ -48,7 +48,7 @@ def format_matrix2(data,s,sc,c,lk,co,nouptri = False):
4848
"""
4949

5050
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
5252

5353
#cmat = replace_diag(cmat) #replace diagonals with zero
5454
cmat = thresholded_arr(cmat,th,fill_val=0)
@@ -400,7 +400,7 @@ def replace_diag(arr,val=0):
400400
return arr
401401

402402

403-
def cost2thresh(cost,sub,bl,lk,last):
403+
def cost2thresh(cost,sub,bl,lk,last,idc = [],costlist=[]):
404404
"""A definition for loading the lookup table and finding the threshold associated with a particular cost for a particular subject in a particular block
405405
406406
inputs:
@@ -422,15 +422,27 @@ def cost2thresh(cost,sub,bl,lk,last):
422422
th=th[0] #if there are multiple thresholds, go down to the lower cost ####Is this right?!!!####
423423
print 'multiple thresh'
424424
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
426437
print 'use previous thresh'
438+
427439
else:
428440
th=th[0]
429441

430442
#print th
431443
return th
432444

433-
def cost2thresh2(cost,sub,sc,c,lk,last):
445+
def cost2thresh2(cost,sub,sc,c,lk,last,idc = [],costlist=[]):
434446
"""A definition for loading the lookup table and finding the threshold associated with a particular cost for a particular subject in a particular block
435447
436448
inputs:
@@ -452,7 +464,17 @@ def cost2thresh2(cost,sub,sc,c,lk,last):
452464
th=th[0] #if there are multiple thresholds, go down to the lower cost ####Is this right?!!!####
453465
print 'multiple thresh'
454466
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
456478
print 'use previous thresh'
457479
else:
458480
th=th[0]

0 commit comments

Comments
 (0)