Example #1
0
 def test_calc_euclid_as_scipy(self, _parse_input):
     from pyrsa.rdm import calc_rdm
     data = Mock()
     data.descriptors = {'session': 0, 'subj': 0}
     data.measurements = np.random.rand(6, 5)
     desc = [0, 1, 2, 3, 4, 5]
     _parse_input.return_value = (data.measurements, desc, 'conds')
     rdm_expected = pdist(data.measurements)**2 / 5
     rdms = calc_rdm(self.test_data, descriptor='conds', method='euclidean')
     assert_array_almost_equal(rdm_expected, rdms.dissimilarities.flatten())
Example #2
0
 def test_example_dissimilarities(self):
     # relevant imports
     import numpy as np
     from scipy import io
     import pyrsa
     import pyrsa.data as rsd  # abbreviation to deal with dataset
     import pyrsa.rdm as rsr
     # create a dataset object
     measurements = {'simTruePatterns': np.random.randn(92, 100)}
     measurements = measurements['simTruePatterns']
     nCond = measurements.shape[0]
     nVox = measurements.shape[1]
     # now create a  dataset object
     des = {'session': 1, 'subj': 1}
     obs_des = {
         'conds': np.array(['cond_' + str(x) for x in np.arange(nCond)])
     }
     chn_des = {
         'voxels': np.array(['voxel_' + str(x) for x in np.arange(nVox)])
     }
     data = rsd.Dataset(measurements=measurements,
                        descriptors=des,
                        obs_descriptors=obs_des,
                        channel_descriptors=chn_des)
     # calculate an RDM
     RDM_euc = rsr.calc_rdm(data)
     RDM_corr = rsr.calc_rdm(data, method='correlation', descriptor='conds')
     # create an RDM object
     rdm_des = {'RDM': np.array(['RDM_1'])}
     RDM_euc2 = rsr.RDMs(
         RDM_euc.dissimilarities,
         dissimilarity_measure=RDM_euc.dissimilarity_measure,
         descriptors=RDM_euc.descriptors,
         rdm_descriptors=rdm_des,
         pattern_descriptors=obs_des)
     print(RDM_euc.dissimilarities)  # here a vector
     dist_matrix = RDM_euc.get_matrices()
     print(dist_matrix)
Example #3
0
    def test_calc_poisson_extreme_pairs(self):
        """Check the dissimilarities computed with the 'poisson' method

        The closest pair should be that between the condition 1 and itself
        The furthest pair should be that between condition 1 and condition 3
        """
        rdm = rsr.calc_rdm(self.test_data_deterministic,
                           descriptor='conds',
                           method='poisson')
        rdm_array = squareform(rdm.get_vectors()[0, :])
        closest_pair_index = np.argmin(rdm_array)
        furthest_pair_index = np.argmax(rdm_array)
        self.assertEqual(closest_pair_index, 0)
        self.assertEqual(furthest_pair_index, 2)
Example #4
0
 def test_calc_correlation(self, _parse_input):
     from pyrsa.rdm import calc_rdm
     data = Mock()
     data.descriptors = {'session': 0, 'subj': 0}
     data.measurements = np.random.rand(6, 5)
     desc = [0, 1, 2, 3, 4, 5]
     _parse_input.return_value = (data.measurements, desc, 'conds')
     rdm_expected = 1 - np.corrcoef(data.measurements)
     rdme = rsr.RDMs(dissimilarities=np.array([rdm_expected]),
                     dissimilarity_measure='correlation',
                     descriptors=data.descriptors)
     rdm = calc_rdm(self.test_data,
                    descriptor='conds',
                    method='correlation')
     assert_array_almost_equal(rdme.dissimilarities.flatten(),
                               rdm.dissimilarities.flatten())
Example #5
0
 def test_calc_poisson_cv(self):
     rdm = rsr.calc_rdm(self.test_data,
                        descriptor='conds',
                        cv_descriptor='fold',
                        method='poisson_cv')
     assert rdm.n_cond == 6
Example #6
0
 def test_calc_poisson_6_conditions(self):
     rdm = rsr.calc_rdm(self.test_data,
                        descriptor='conds',
                        method='poisson')
     assert rdm.n_cond == 6
Example #7
0
 def test_calc_mahalanobis(self):
     rdm = rsr.calc_rdm(self.test_data,
                        descriptor='conds',
                        method='mahalanobis')
     assert rdm.n_cond == 6
Example #8
0
 def test_calc_euclid_nconds(self):
     rdm = rsr.calc_rdm(self.test_data,
                        descriptor='conds',
                        method='euclidean')
     assert rdm.n_cond == 6