Esempio n. 1
0
 def test_eval_bootstrap_rdm(self):
     from rsatoolbox.inference import eval_bootstrap_rdm
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     rdms = RDMs(np.random.rand(11, 10))  # 11 5x5 rdms
     m = ModelFixed('test', rdms.get_vectors()[0])
     m2 = ModelFixed('test2', rdms.get_vectors()[1])
     value = eval_bootstrap_rdm([m, m2], rdms, N=10)
Esempio n. 2
0
 def test_eval_bootstrap(self):
     from rsatoolbox.inference import eval_bootstrap
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     rdms = RDMs(np.random.rand(11, 10))  # 11 5x5 rdms
     m = ModelFixed('test', rdms.get_vectors()[0])
     m2 = ModelFixed('test2', rdms.get_vectors()[1])
     result = eval_bootstrap([m, m2], rdms, N=10)
     assert result.evaluations.shape[1] == 2
     assert result.evaluations.shape[0] == 10
Esempio n. 3
0
 def test_bootstrap_crossval_list(self):
     from rsatoolbox.inference import bootstrap_crossval
     from rsatoolbox.model import ModelFixed
     rdms = self.rdms
     m = ModelFixed('test', rdms[0])
     m2 = ModelFixed('test2', rdms[1])
     bootstrap_crossval([m, m2],
                        rdms,
                        N=10,
                        k_rdm=2,
                        k_pattern=2,
                        pattern_descriptor='type',
                        rdm_descriptor='session')
Esempio n. 4
0
 def test_bootstrap_testset_rdm(self):
     from rsatoolbox.inference import bootstrap_testset_rdm
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     rdms = RDMs(np.random.rand(11, 10))  # 11 5x5 rdms
     m = ModelFixed('test', rdms.get_vectors()[0])
     m2 = ModelFixed('test2', rdms.get_vectors()[1])
     evaluations, n_rdms = bootstrap_testset_rdm([m, m2],
                                                 rdms,
                                                 method='cosine',
                                                 fitter=None,
                                                 N=100,
                                                 rdm_descriptor=None)
Esempio n. 5
0
    def test_t_scipy(self):
        from rsatoolbox.util.inference_util import t_tests
        from rsatoolbox.inference import eval_fixed
        from rsatoolbox.rdm import RDMs
        from rsatoolbox.model import ModelFixed
        import scipy.stats

        rdms = RDMs(np.random.rand(11, 10))  # 11 5x5 rdms
        m = ModelFixed('test', rdms.get_vectors()[0])
        m2 = ModelFixed('test', rdms.get_vectors()[2])
        value = eval_fixed([m, m2], rdms)
        ps = t_tests(value.evaluations, value.diff_var, dof=value.dof)
        scipy_t = scipy.stats.ttest_rel(value.evaluations[0, 0],
                                        value.evaluations[0, 1])
        self.assertAlmostEqual(scipy_t.pvalue, ps[0, 1])
Esempio n. 6
0
 def test_bootstrap_cv_random(self):
     from rsatoolbox.inference import bootstrap_cv_random
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     dis = np.random.rand(11, 190)  # 11 10x10 rdms
     mes = "Euclidean"
     des = {'subj': 0}
     rdm_des = {'session': np.array([0, 1, 2, 2, 4, 5, 6, 7, 7, 7, 7])}
     pattern_des = {
         'type':
         np.array([
             0, 1, 2, 2, 4, 5, 5, 5, 6, 7, 10, 11, 12, 12, 14, 15, 15, 15,
             16, 17
         ])
     }
     rdms = RDMs(dissimilarities=dis,
                 rdm_descriptors=rdm_des,
                 pattern_descriptors=pattern_des,
                 dissimilarity_measure=mes,
                 descriptors=des)
     m = ModelFixed('test', rdms[0])
     res = bootstrap_cv_random(m,
                               rdms,
                               N=10,
                               n_rdm=2,
                               n_pattern=4,
                               pattern_descriptor='type',
                               rdm_descriptor='session')
     self.assertEqual(res.evaluations.shape[0], 10)
Esempio n. 7
0
 def test_bootstrap_crossval(self):
     from rsatoolbox.inference import bootstrap_crossval
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     dis = np.random.rand(11, 190)  # 11 10x10 rdms
     mes = "Euclidean"
     des = {'subj': 0}
     rdm_des = {'session': np.array([0, 1, 2, 2, 4, 5, 6, 7, 7, 7, 7])}
     pattern_des = {
         'type':
         np.array([
             0, 1, 2, 2, 4, 5, 5, 5, 6, 7, 10, 11, 12, 12, 14, 15, 15, 15,
             16, 17
         ])
     }
     rdms = RDMs(dissimilarities=dis,
                 rdm_descriptors=rdm_des,
                 pattern_descriptors=pattern_des,
                 dissimilarity_measure=mes,
                 descriptors=des)
     m = ModelFixed('test', rdms[0])
     bootstrap_crossval(m,
                        rdms,
                        N=10,
                        k_rdm=2,
                        k_pattern=2,
                        pattern_descriptor='type',
                        rdm_descriptor='session')
Esempio n. 8
0
 def test_eval_fixed(self):
     from rsatoolbox.inference import eval_fixed
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     rdms = RDMs(np.random.rand(11, 10))  # 11 5x5 rdms
     m = ModelFixed('test', rdms.get_vectors()[0])
     eval_fixed(m, rdms)
Esempio n. 9
0
 def test_eval_bootstrap_rdm(self):
     from rsatoolbox.inference import eval_bootstrap_rdm
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     rdms = RDMs(np.random.rand(11, 10))  # 11 5x5 rdms
     m = ModelFixed('test', rdms.get_vectors()[0])
     eval_bootstrap_rdm(m, rdms, N=10)
     eval_bootstrap_rdm(m, rdms, N=10, boot_noise_ceil=True)
Esempio n. 10
0
 def test_result_dict(self):
     from rsatoolbox.inference import Result
     from rsatoolbox.inference import result_from_dict
     from rsatoolbox.model import ModelFixed
     m1 = ModelFixed('test1', np.random.rand(10))
     m2 = ModelFixed('test2', np.random.rand(10))
     models = [m1, m2]
     evaluations = np.random.rand(100, 2)
     method = 'test_method'
     cv_method = 'test_cv_method'
     noise_ceiling = np.array([0.5, 0.2])
     res = Result(models, evaluations, method, cv_method, noise_ceiling)
     result_dict = res.to_dict()
     res_loaded = result_from_dict(result_dict)
     assert res_loaded.method == method
     assert res_loaded.cv_method == cv_method
     assert np.all(res_loaded.evaluations == evaluations)
     assert np.all(res_loaded.models[0].rdm == m1.rdm)
Esempio n. 11
0
 def test_bootstrap_testset_pattern(self):
     from rsatoolbox.inference import bootstrap_testset_pattern
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     rdms = RDMs(np.random.rand(11, 10))  # 11 5x5 rdms
     m = ModelFixed('test', rdms.get_vectors()[0])
     _, _ = bootstrap_testset_pattern(m,
                                      rdms,
                                      method='cosine',
                                      fitter=None,
                                      N=100,
                                      pattern_descriptor=None)
Esempio n. 12
0
 def test_save_load_result(self):
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.inference import Result
     from rsatoolbox.inference import load_results
     from rsatoolbox.model import ModelFixed
     import io
     rdm = RDMs(np.random.rand(10),
                pattern_descriptors={
                    'test': ['test1', 'test1', 'test1', 'test3', 'test']
                })
     m1 = ModelFixed('test1', rdm)
     m2 = ModelFixed('test2', np.random.rand(10))
     models = [m1, m2]
     evaluations = np.random.rand(100, 2)
     method = 'test_method'
     cv_method = 'test_cv_method'
     noise_ceiling = np.array([0.5, 0.2])
     res = Result(models, evaluations, method, cv_method, noise_ceiling)
     f = io.BytesIO()  # Essentially a Mock file
     res.save(f, file_type='hdf5')
     res_loaded = load_results(f, file_type='hdf5')
     assert res_loaded.method == method
     assert res_loaded.cv_method == cv_method
     assert np.all(res_loaded.evaluations == evaluations)
Esempio n. 13
0
 def setUp(self):
     from rsatoolbox.rdm import RDMs
     from rsatoolbox.model import ModelFixed
     dis = np.random.rand(11, 190)  # 11 20x20 rdms
     mes = "Euclidean"
     des = {'subj': 0}
     rdm_des = {'session': np.array([0, 1, 2, 2, 4, 5, 6, 7, 7, 7, 7])}
     pattern_des = {
         'type':
         np.array([
             0, 1, 2, 2, 4, 5, 5, 5, 6, 7, 10, 11, 12, 12, 14, 15, 15, 15,
             16, 17
         ])
     }
     rdms = RDMs(dissimilarities=dis,
                 rdm_descriptors=rdm_des,
                 pattern_descriptors=pattern_des,
                 dissimilarity_measure=mes,
                 descriptors=des)
     m = ModelFixed('test', rdms[0])
     self.rdms = rdms
     self.m = m
Esempio n. 14
0
    def test_model_dict(self):
        from rsatoolbox.model import model_from_dict
        from rsatoolbox.model import ModelFixed
        m = ModelFixed('test1', np.random.rand(10))
        model_dict = m.to_dict()
        model_loaded = model_from_dict(model_dict)
        assert m.name == model_loaded.name
        assert np.all(
            m.rdm_obj.dissimilarities == model_loaded.rdm_obj.dissimilarities)

        from rsatoolbox.model import ModelInterpolate
        m = ModelInterpolate('test1', np.random.rand(10))
        model_dict = m.to_dict()
        model_loaded = model_from_dict(model_dict)
        assert m.name == model_loaded.name
        assert np.all(
            m.rdm_obj.dissimilarities == model_loaded.rdm_obj.dissimilarities)

        from rsatoolbox.model import ModelSelect
        m = ModelSelect('test1', np.random.rand(10))
        model_dict = m.to_dict()
        model_loaded = model_from_dict(model_dict)
        assert m.name == model_loaded.name
        assert np.all(
            m.rdm_obj.dissimilarities == model_loaded.rdm_obj.dissimilarities)

        from rsatoolbox.model import ModelWeighted
        m = ModelWeighted('test1', np.random.rand(10))
        model_dict = m.to_dict()
        model_loaded = model_from_dict(model_dict)
        assert m.name == model_loaded.name
        assert np.all(
            m.rdm_obj.dissimilarities == model_loaded.rdm_obj.dissimilarities)

        from rsatoolbox.model import Model
        m = Model('test1')
        model_dict = m.to_dict()
        model_loaded = model_from_dict(model_dict)
        assert m.name == model_loaded.name