Пример #1
0
 def test_constant_row_matrix(self):
     # should give one cluster in columns
     Z = np.repeat(np.arange(8), 7).reshape(8, 7).astype('float64')
     ncl_row = 3
     ncl_col = 4
     np.random.seed(1234)
     _, _, row_cl, col_cl, _ = coclustering(Z, ncl_row, ncl_col, 1.e-5, 100,
                                            1.e-8)
     assert np.unique(row_cl).size == ncl_row
     assert np.unique(col_cl).size == 1
Пример #2
0
 def test_constant_col_matrix(self):
     # should give one cluster in rows
     Z = np.tile(np.arange(7), (8, 1)).astype('float64')
     ncl_row = 3
     ncl_col = 4
     np.random.seed(1234)
     _, _, row_cl, col_cl, _ = coclustering(Z, ncl_row, ncl_col, 1.e-5, 100,
                                            1.e-8)
     assert np.unique(row_cl).size == 1
     assert np.unique(col_cl).size == ncl_col
Пример #3
0
 def test_as_many_clusters_as_elements(self):
     # it should immediately converge (2 iterations)
     ncl_row = 8
     ncl_col = 7
     np.random.seed(1234)
     Z = np.random.randint(100, size=(ncl_row, ncl_col)).astype('float64')
     conv, niterations, _, _, _ = coclustering(Z, ncl_row, ncl_col, 1.e-5,
                                               100, 1.e-8)
     assert conv
     assert niterations == 2
Пример #4
0
 def test_zero_matrix(self):
     # special case for the error - and no nan/inf
     Z = np.zeros((8, 7))
     ncl_row = 3
     ncl_col = 4
     epsilon = 1.e-6
     np.random.seed(1234)
     _, _, _, _, error = coclustering(Z, ncl_row, ncl_col, 1.e-5, 100,
                                      epsilon)
     assert np.isclose(error, Z.size * epsilon)
Пример #5
0
 def test_bigger_matrix(self):
     Z = np.random.randint(100, size=(20, 15)).astype('float64')
     ncl_row = 5
     ncl_col = 6
     np.random.seed(1234)
     _, _, row_cl, col_cl, _ = coclustering(Z, ncl_row, ncl_col, 1.e-5, 100,
                                            1.e-8)
     np.testing.assert_array_equal(np.sort(np.unique(row_cl)),
                                   np.arange(ncl_row))
     np.testing.assert_array_equal(np.sort(np.unique(col_cl)),
                                   np.arange(ncl_col))
Пример #6
0
 def test_small_matrix(self):
     np.random.seed(1234)
     Z = np.random.permutation(np.arange(12)).reshape(3,
                                                      4).astype('float64')
     ncl_row = 2
     ncl_col = 3
     conv, niterations, row_cl, col_cl, error = coclustering(
         Z, ncl_row, ncl_col, 1.e-5, 100, 1.e-8)
     assert conv
     assert niterations == 3
     np.testing.assert_array_equal(row_cl, np.array([1, 0, 0]))
     np.testing.assert_array_equal(col_cl, np.array([1, 1, 2, 0]))
     np.testing.assert_almost_equal(error, -56.457907947376775)