added test for transform and sqrt transform
@@ -209,6 +209,25 @@ class TestRDM(unittest.TestCase):
i += 1
self.assertEqual(i, rdms.n_rdm)
+ def test_transform(self):
+ from rsatoolbox.rdm import transform
+ dis = np.random.rand(8, 10)
+ mes = "Euclidean"
+ des = {'subj': 0}
+ pattern_des = {'type': np.array([0, 1, 2, 2, 4])}
+ rdm_des = {'session': np.array([0, 1, 2, 2, 4, 5, 6, 7])}
+ rdms = rsr.RDMs(dissimilarities=dis,
+ rdm_descriptors=rdm_des,
+ pattern_descriptors=pattern_des,
+ dissimilarity_measure=mes,
+ descriptors=des)
+ def square(x):
+ return x ** 2
+ transformed_rdm = transform(rdms, square)
+ assert transformed_rdm.n_rdm == rdms.n_rdm
+ assert transformed_rdm.n_cond == rdms.n_cond
+
+
def test_rank_transform(self):
from rsatoolbox.rdm import rank_transform
dis = np.zeros((8, 10))
@@ -225,6 +244,39 @@ class TestRDM(unittest.TestCase):
assert rank_rdm.n_rdm == rdms.n_rdm
assert rank_rdm.n_cond == rdms.n_cond
+ def test_sqrt_transform(self):
+ from rsatoolbox.rdm import sqrt_transform
+ dis = np.zeros((8, 10))
+ mes = "Euclidean"
+ des = {'subj': 0}
+ pattern_des = {'type': np.array([0, 1, 2, 2, 4])}
+ rdm_des = {'session': np.array([0, 1, 2, 2, 4, 5, 6, 7])}
+ rdms = rsr.RDMs(dissimilarities=dis,
+ rdm_descriptors=rdm_des,
+ pattern_descriptors=pattern_des,
+ dissimilarity_measure=mes,
+ descriptors=des)
+ sqrt_rdm = sqrt_transform(rdms)
+ assert sqrt_rdm.n_rdm == rdms.n_rdm
+ assert sqrt_rdm.n_cond == rdms.n_cond
+
+ def test_positive_transform(self):
+ from rsatoolbox.rdm import positive_transform
+ dis = np.random.rand(8, 10) - 0.5
+ mes = "Euclidean"
+ des = {'subj': 0}
+ pattern_des = {'type': np.array([0, 1, 2, 2, 4])}
+ rdm_des = {'session': np.array([0, 1, 2, 2, 4, 5, 6, 7])}
+ rdms = rsr.RDMs(dissimilarities=dis,
+ rdm_descriptors=rdm_des,
+ pattern_descriptors=pattern_des,
+ dissimilarity_measure=mes,
+ descriptors=des)
+ pos_rdm = positive_transform(rdms)
+ assert pos_rdm.n_rdm == rdms.n_rdm
+ assert pos_rdm.n_cond == rdms.n_cond
+ assert np.all(pos_rdm.dissimilarities >= 0)
+
def test_rdm_append(self):
dis = np.zeros((8, 10))
mes = "Euclidean"
