@@ -12,7 +12,6 @@ class TestDemos(unittest.TestCase):
12
12
def test_example_dataset (self ):
13
13
import numpy as np
14
14
import matplotlib .pyplot as plt
15
- import rsatoolbox
16
15
import rsatoolbox .data as rsd # abbreviation to deal with dataset
17
16
18
17
# import the measurements for the dataset
@@ -101,8 +100,6 @@ def test_example_dataset(self):
101
100
def test_example_dissimilarities (self ):
102
101
# relevant imports
103
102
import numpy as np
104
- from scipy import io
105
- import rsatoolbox
106
103
import rsatoolbox .data as rsd # abbreviation to deal with dataset
107
104
import rsatoolbox .rdm as rsr
108
105
# create a dataset object
@@ -122,11 +119,12 @@ def test_example_dissimilarities(self):
122
119
channel_descriptors = chn_des )
123
120
# calculate an RDM
124
121
RDM_euc = rsr .calc_rdm (data )
125
- RDM_corr = rsr .calc_rdm (data ,
126
- method = 'correlation' , descriptor = 'conds' )
122
+ _ = rsr .calc_rdm (
123
+ data ,
124
+ method = 'correlation' , descriptor = 'conds' )
127
125
# create an RDM object
128
126
rdm_des = {'RDM' : np .array (['RDM_1' ])}
129
- RDM_euc2 = rsr .RDMs (
127
+ _ = rsr .RDMs (
130
128
RDM_euc .dissimilarities ,
131
129
dissimilarity_measure = RDM_euc .dissimilarity_measure ,
132
130
descriptors = RDM_euc .descriptors ,
@@ -136,6 +134,49 @@ def test_example_dissimilarities(self):
136
134
dist_matrix = RDM_euc .get_matrices ()
137
135
print (dist_matrix )
138
136
137
+ def test_dual_boot (self ):
138
+ import numpy as np
139
+ from scipy import io
140
+ import rsatoolbox
141
+ import os
142
+ path = os .path .dirname (os .path .abspath (__file__ ))
143
+ matlab_data = io .matlab .loadmat (
144
+ os .path .join (path , '..' , 'demos' ,
145
+ 'rdms_inferring' , 'modelRDMs_A2020.mat' ))
146
+ matlab_data = matlab_data ['modelRDMs' ]
147
+ n_models = len (matlab_data [0 ])
148
+ model_names = [matlab_data [0 ][i ][0 ][0 ] for i in range (n_models )]
149
+ measurement_model = [matlab_data [0 ][i ][1 ][0 ] for i in range (n_models )]
150
+ rdms_array = np .array ([matlab_data [0 ][i ][3 ][0 ] for i in range (n_models )])
151
+ model_rdms = rsatoolbox .rdm .RDMs (
152
+ rdms_array ,
153
+ rdm_descriptors = {
154
+ 'brain_computational_model' : model_names ,
155
+ 'measurement_model' : measurement_model },
156
+ dissimilarity_measure = 'Euclidean'
157
+ )
158
+ model_names = [matlab_data [0 ][i ][0 ][0 ] for i in range (n_models )]
159
+ matlab_data = io .matlab .loadmat (
160
+ os .path .join (path , '..' , 'demos' ,
161
+ 'rdms_inferring' , 'noisyModelRDMs_A2020.mat' ))
162
+ rdms_matlab = matlab_data ['noisyModelRDMs' ]
163
+ rdms_matrix = rdms_matlab .squeeze ().astype ('float' )
164
+ i_rep = 2 # np.random.randint(len(repr_names))
165
+ i_noise = 1 # np.random.randint(len(noise_std))
166
+ i_fwhm = 0 # np.random.randint(len(fwhms))
167
+ rdms_data = rsatoolbox .rdm .RDMs (rdms_matrix [:, i_rep , i_fwhm , i_noise , :].transpose ())
168
+ models_flex = []
169
+ for i_model in np .unique (model_names ):
170
+ models_flex .append (
171
+ rsatoolbox .model .ModelSelect (
172
+ i_model ,
173
+ model_rdms .subset ('brain_computational_model' , i_model )
174
+ )
175
+ )
176
+ results_3_full = rsatoolbox .inference .eval_dual_bootstrap (
177
+ models_flex , rdms_data , k_pattern = 4 , k_rdm = 2 , method = 'corr' , N = 5 )
178
+ print (results_3_full )
179
+
139
180
def test_exercise_all (self ):
140
181
import numpy as np
141
182
from scipy import io
@@ -161,8 +202,9 @@ def test_exercise_all(self):
161
202
162
203
conv1_rdms = model_rdms .subset ('brain_computational_model' , 'conv1' )
163
204
plt .figure (figsize = (10 , 10 ))
164
- rsatoolbox .vis .show_rdm (conv1_rdms ,
165
- rdm_descriptor = 'measurement_model' )
205
+ rsatoolbox .vis .show_rdm (
206
+ conv1_rdms ,
207
+ rdm_descriptor = 'measurement_model' )
166
208
167
209
conv1_rdms = model_rdms .subset ('brain_computational_model' , 'conv1' )
168
210
print (conv1_rdms )
@@ -229,8 +271,10 @@ def test_exercise_all(self):
229
271
230
272
models_flex = []
231
273
for i_model in np .unique (model_names ):
232
- models_flex .append (rsatoolbox .model .ModelSelect (i_model ,
233
- model_rdms .subset ('brain_computational_model' , i_model )))
274
+ models_flex .append (
275
+ rsatoolbox .model .ModelSelect (
276
+ i_model ,
277
+ model_rdms .subset ('brain_computational_model' , i_model )))
234
278
235
279
print ('created the following models:' )
236
280
for i in range (len (models_flex )):
@@ -332,9 +376,10 @@ def test_temporal_rsa(self):
332
376
'%0.0f ms' % (np .round (x * 1000 , 2 ))
333
377
for x in rdms_data_binned .rdm_descriptors ['time' ]]
334
378
335
- rsatoolbox .vis .show_rdm (rdms_data_binned ,
336
- pattern_descriptor = 'conds' ,
337
- rdm_descriptor = 'time_formatted' )
379
+ rsatoolbox .vis .show_rdm (
380
+ rdms_data_binned ,
381
+ pattern_descriptor = 'conds' ,
382
+ rdm_descriptor = 'time_formatted' )
338
383
from rsatoolbox .rdm import get_categorical_rdm
339
384
rdms_model_in = get_categorical_rdm (['%d' % x for x in range (4 )])
340
385
rdms_model_lr = get_categorical_rdm (['l' , 'r' , 'l' , 'r' ])
@@ -347,8 +392,10 @@ def test_temporal_rsa(self):
347
392
model_rdms .rdm_descriptors ['model_names' ] = model_names
348
393
model_rdms .pattern_descriptors ['cond_names' ] = cond_names
349
394
plt .figure (figsize = (10 , 10 ))
350
- rsatoolbox .vis .show_rdm (model_rdms , rdm_descriptor = 'model_names' ,
351
- pattern_descriptor = 'cond_names' )
395
+ rsatoolbox .vis .show_rdm (
396
+ model_rdms ,
397
+ rdm_descriptor = 'model_names' ,
398
+ pattern_descriptor = 'cond_names' )
352
399
from rsatoolbox .rdm import compare
353
400
r = []
354
401
for mod in model_rdms :
@@ -375,16 +422,18 @@ def test_demo_rdm_scatterplot(self):
375
422
matlab_data = loadmat (
376
423
os .path .join (path , '..' , 'demos' , '92imageData/92_brainRDMs.mat' ))['RDMs' ]
377
424
n_rdms = len (matlab_data [0 ])
378
- rdms_ = RDMs (np .array ([matlab_data [0 ][i ][0 ][0 ] for i in range (n_rdms )]),
379
- pattern_descriptors = condition_descriptors ,
380
- rdm_descriptors = {'name' : np .array ([f"RDM{ i } "
381
- for i in range (4 )])}
382
- )
425
+ rdms_ = RDMs (
426
+ np .array ([matlab_data [0 ][i ][0 ][0 ] for i in range (n_rdms )]),
427
+ pattern_descriptors = condition_descriptors ,
428
+ rdm_descriptors = {
429
+ 'name' : np .array ([f"RDM{ i } " for i in range (4 )])}
430
+ )
383
431
384
432
rdms_a = concat ([rdms_ [0 ], rdms_ [1 ]])
385
433
rdms_b = concat ([rdms_ [2 ], rdms_ [3 ]])
386
434
387
- rdm_comparison_scatterplot ((rdms_a , rdms_b ),
435
+ rdm_comparison_scatterplot (
436
+ (rdms_a , rdms_b ),
388
437
show_marginal_distributions = True ,
389
438
show_identity_line = True ,
390
439
show_legend = False ,
@@ -397,5 +446,6 @@ def test_demo_rdm_scatterplot(self):
397
446
}
398
447
)
399
448
449
+
400
450
if __name__ == '__main__' :
401
451
unittest .main ()
0 commit comments