示例#1
0
    def test_random_fn(self):
        def myrand(num_rows, num_cols):
            # One dm to rule them all...
            data = np.empty((num_rows, num_cols))
            data.fill(42)
            return data

        exp = DistanceMatrix(np.asarray([[0, 42, 42], [42, 0, 42],
                                         [42, 42, 0]]), ['1', '2', '3'])
        obs = randdm(3, random_fn=myrand)
        self.assertEqual(obs, exp)
示例#2
0
    def test_default_usage(self):
        exp = DistanceMatrix(np.asarray([[0.0]]), ['1'])
        obs = randdm(1)
        self.assertEqual(obs, exp)

        obs = randdm(2)
        self.assertEqual(obs.shape, (2, 2))
        self.assertEqual(obs.ids, ('1', '2'))

        obs1 = randdm(5)
        num_trials = 10
        found_diff = False
        for _ in range(num_trials):
            obs2 = randdm(5)

            if obs1 != obs2:
                found_diff = True
                break

        self.assertTrue(found_diff)
示例#3
0
    def test_default_usage(self):
        exp = DistanceMatrix(np.asarray([[0.0]]), ['1'])
        obs = randdm(1)
        self.assertEqual(obs, exp)

        obs = randdm(2)
        self.assertEqual(obs.shape, (2, 2))
        self.assertEqual(obs.ids, ('1', '2'))

        obs1 = randdm(5)
        num_trials = 10
        found_diff = False
        for _ in range(num_trials):
            obs2 = randdm(5)

            if obs1 != obs2:
                found_diff = True
                break

        self.assertTrue(found_diff)
示例#4
0
    def test_random_fn(self):
        def myrand(num_rows, num_cols):
            # One dm to rule them all...
            data = np.empty((num_rows, num_cols))
            data.fill(42)
            return data

        exp = DistanceMatrix(np.asarray([[0, 42, 42], [42, 0, 42],
                                         [42, 42, 0]]), ['1', '2', '3'])
        obs = randdm(3, random_fn=myrand)
        self.assertEqual(obs, exp)
示例#5
0
    def test_invalid_input(self):
        # Invalid dimensions.
        with self.assertRaises(DissimilarityMatrixError):
            randdm(0)

        # Invalid dimensions.
        with self.assertRaises(ValueError):
            randdm(-1)

        # Invalid number of IDs.
        with self.assertRaises(DissimilarityMatrixError):
            randdm(2, ids=['foo'])
示例#6
0
    def test_invalid_input(self):
        # Invalid dimensions.
        with self.assertRaises(DissimilarityMatrixError):
            randdm(0)

        # Invalid dimensions.
        with self.assertRaises(ValueError):
            randdm(-1)

        # Invalid number of IDs.
        with self.assertRaises(DissimilarityMatrixError):
            randdm(2, ids=['foo'])
示例#7
0
 def test_constructor(self):
     exp = DissimilarityMatrix(np.asarray([[0.0]]), ['1'])
     obs = randdm(1, constructor=DissimilarityMatrix)
     self.assertEqual(obs, exp)
     self.assertEqual(type(obs), DissimilarityMatrix)
示例#8
0
 def test_ids(self):
     ids = ['foo', 'bar', 'baz']
     obs = randdm(3, ids=ids)
     self.assertEqual(obs.shape, (3, 3))
     self.assertEqual(obs.ids, tuple(ids))
示例#9
0
 def test_large_matrix_for_symmetry(self):
     obs3 = randdm(100)
     self.assertEqual(obs3, obs3.T)
示例#10
0
 def _create_distance_matrix(self, sample_ids):
     dm = randdm(len(sample_ids), sample_ids)
     fd, fp = mkstemp(suffix='.txt', dir=self.out_dir)
     close(fd)
     dm.write(fp)
     return fp
示例#11
0
 def test_constructor(self):
     exp = DissimilarityMatrix(np.asarray([[0.0]]), ['1'])
     obs = randdm(1, constructor=DissimilarityMatrix)
     self.assertEqual(obs, exp)
     self.assertEqual(type(obs), DissimilarityMatrix)
示例#12
0
 def test_ids(self):
     ids = ['foo', 'bar', 'baz']
     obs = randdm(3, ids=ids)
     self.assertEqual(obs.shape, (3, 3))
     self.assertEqual(obs.ids, tuple(ids))
示例#13
0
 def test_large_matrix_for_symmetry(self):
     obs3 = randdm(100)
     self.assertEqual(obs3, obs3.T)
示例#14
0
 def test_constructor(self):
     """Test generating random dist mats with a specific constructor."""
     exp = DissimilarityMatrix(np.asarray([[0.0]]), ['1'])
     obs = randdm(1, constructor=DissimilarityMatrix)
     self.assertEqual(obs, exp)
     self.assertEqual(type(obs), DissimilarityMatrix)
示例#15
0
 def test_ids(self):
     """Test generating random distance matrices with specific IDs."""
     ids = ['foo', 'bar', 'baz']
     obs = randdm(3, ids=ids)
     self.assertEqual(obs.shape, (3, 3))
     self.assertEqual(obs.ids, tuple(ids))