@@ -37,7 +37,8 @@ def slice_data(data, sub, block, subcond=None):
37
37
return data [subcond , block , sub ]
38
38
39
39
40
- def format_matrix (data ,s ,b ,lk ,co ,idc = [],costlist = [],nouptri = False ):
40
+ def format_matrix (data , s , b , lk , co , idc = [], costlist = [],
41
+ nouptri = False , asbool = True ):
41
42
""" Function which thresholds the adjacency matrix for a particular
42
43
subject and particular block, using lookuptable to find thresholds,
43
44
cost value to find threshold, costlist
@@ -46,24 +47,37 @@ def format_matrix(data,s,b,lk,co,idc = [],costlist=[],nouptri = False):
46
47
Parameters
47
48
-----------
48
49
data : full data array 4D (block, sub, node, node)
49
- s = subject
50
- b = block
51
- lk = lookup table for study
52
- co = cost value to threshold at
53
- idc = index of ideal cost
54
- costlist = list (size num_edges) with ordered values used to find
50
+ s : int
51
+ subject
52
+ b : int
53
+ block
54
+ lk : numpy array
55
+ lookup table for study
56
+ co : int
57
+ cost value to threshold at
58
+ idc : int
59
+ index of ideal cost
60
+ costlist : list
61
+ list (size num_edges) with ordered values used to find
55
62
threshold to control number of edges
56
- nouptri = if False only keeps upper tri, True yields symmetric matrix
63
+ nouptri : bool
64
+ if False only keeps upper tri, True yields symmetric matrix
65
+ asbool : bool
66
+ if True return boolean mask, otherwise returns thesholded
67
+ weight matrix
57
68
"""
58
- cmat = data [ b ,s ]
69
+ cmat = slice_data ( data , b ,s )
59
70
th = cost2thresh (co ,s ,b ,lk ,idc ,costlist ) #get the right threshold
60
71
cmat = thresholded_arr (cmat ,th ,fill_val = 0 )
61
72
if not nouptri :
62
73
cmat = np .triu (cmat ,1 )
74
+ if asbool :
75
+ return ~ (cmat == 0 )
63
76
return cmat
64
77
65
78
66
- def format_matrix2 (data ,s ,sc ,c ,lk ,co ,idc = [],costlist = [],nouptri = False ):
79
+ def format_matrix2 (data , s , sc , c , lk , co , idc = [],
80
+ costlist = [], nouptri = False , asbool = True ):
67
81
""" Function which formats matrix for a particular subject and
68
82
particular block (thresholds, upper-tris it) so that we can
69
83
make a graph object out of it
@@ -88,14 +102,19 @@ def format_matrix2(data,s,sc,c,lk,co,idc = [],costlist=[],nouptri = False):
88
102
list of possible costs
89
103
nouptri : bool
90
104
False zeros out diag and below, True returns symmetric matrix
105
+ asbool : bool
106
+ If true returns boolean mask, otherwise returns thresholded w
107
+ weighted matrix
91
108
"""
92
109
cmat = slice_data (data , s , c , sc )
93
110
th = cost2thresh2 (co ,s ,sc ,c ,lk ,[],idc ,costlist ) #get the right threshold
94
111
cmat = thresholded_arr (cmat ,th ,fill_val = 0 )
95
112
if not nouptri :
96
113
cmat = np .triu (cmat ,1 )
97
- # return boolean mask
98
- return ~ (cmat == 0 )
114
+ if asbool :
115
+ # return boolean mask
116
+ return ~ (cmat == 0 )
117
+ return cmat
99
118
100
119
def threshold_adjacency_matrix (adj_matrix , cost ):
101
120
"""docstring for threshold_adjacency_matrix(adj_matrix, cost"""
0 commit comments