예제 #1
0
 def help_is_isomorphic_randperm(self, nobs, nclusters, noniso=False, nerrors=0):
     for k in range(3):
         a = np.int_(np.random.rand(nobs) * nclusters)
         b = np.zeros(a.size, dtype=np.int_)
         P = np.random.permutation(nclusters)
         for i in xrange(0, a.shape[0]):
             b[i] = P[a[i]]
         if noniso:
             Q = np.random.permutation(nobs)
             b[Q[0:nerrors]] += 1
             b[Q[0:nerrors]] %= nclusters
         assert_(is_isomorphic(a, b) == (not noniso))
         assert_(is_isomorphic(b, a) == (not noniso))
예제 #2
0
 def help_is_isomorphic_randperm(self,
                                 nobs,
                                 nclusters,
                                 noniso=False,
                                 nerrors=0):
     for k in range(3):
         a = np.int_(np.random.rand(nobs) * nclusters)
         b = np.zeros(a.size, dtype=np.int_)
         P = np.random.permutation(nclusters)
         for i in xrange(0, a.shape[0]):
             b[i] = P[a[i]]
         if noniso:
             Q = np.random.permutation(nobs)
             b[Q[0:nerrors]] += 1
             b[Q[0:nerrors]] %= nclusters
         assert_(is_isomorphic(a, b) == (not noniso))
         assert_(is_isomorphic(b, a) == (not noniso))
예제 #3
0
 def test_is_isomorphic_4C(self):
     # Tests is_isomorphic on test case #4C (3 flat clusters, different labelings, isomorphic)
     a = [7, 2, 3]
     b = [6, 3, 2]
     assert_(is_isomorphic(a, b))
     assert_(is_isomorphic(b, a))
예제 #4
0
 def test_is_isomorphic_4B(self):
     # Tests is_isomorphic on test case #4B (3 flat clusters, different labelings, nonisomorphic)
     a = [1, 2, 3, 3]
     b = [1, 3, 2, 3]
     assert_(is_isomorphic(a, b) == False)
     assert_(is_isomorphic(b, a) == False)
예제 #5
0
 def test_is_isomorphic_3(self):
     # Tests is_isomorphic on test case #3 (no flat clusters)
     a = []
     b = []
     assert_(is_isomorphic(a, b))
예제 #6
0
 def test_is_isomorphic_2(self):
     # Tests is_isomorphic on test case #2 (two flat clusters, different labelings)
     a = [1, 7, 1]
     b = [2, 3, 2]
     assert_(is_isomorphic(a, b))
     assert_(is_isomorphic(b, a))
예제 #7
0
 def test_is_isomorphic_1(self):
     # Tests is_isomorphic on test case #1 (one flat cluster, different labellings)
     a = [1, 1, 1]
     b = [2, 2, 2]
     assert_(is_isomorphic(a, b))
     assert_(is_isomorphic(b, a))
예제 #8
0
 def check_fcluster_maxclust_monocrit(self, t):
     expectedT = hierarchy_test_data.fcluster_maxclust[t]
     Z = single(hierarchy_test_data.Q_X)
     T = fcluster(Z, t, criterion='maxclust_monocrit', monocrit=maxdists(Z))
     assert_(is_isomorphic(T, expectedT))
예제 #9
0
 def check_fcluster(self, t, criterion):
     # Tests fcluster(Z, criterion=criterion, t=t) on a random 3-cluster data set.
     expectedT = getattr(hierarchy_test_data, 'fcluster_' + criterion)[t]
     Z = single(hierarchy_test_data.Q_X)
     T = fcluster(Z, criterion=criterion, t=t)
     assert_(is_isomorphic(T, expectedT))
예제 #10
0
 def test_is_isomorphic_4B(self):
     # Tests is_isomorphic on test case #4B (3 flat clusters, different labelings, nonisomorphic)
     a = [1, 2, 3, 3]
     b = [1, 3, 2, 3]
     assert_(is_isomorphic(a, b) == False)
     assert_(is_isomorphic(b, a) == False)
예제 #11
0
 def test_is_isomorphic_4C(self):
     # Tests is_isomorphic on test case #4C (3 flat clusters, different labelings, isomorphic)
     a = [7, 2, 3]
     b = [6, 3, 2]
     assert_(is_isomorphic(a, b))
     assert_(is_isomorphic(b, a))
예제 #12
0
 def test_is_isomorphic_3(self):
     # Tests is_isomorphic on test case #3 (no flat clusters)
     a = []
     b = []
     assert_(is_isomorphic(a, b))
예제 #13
0
 def test_is_isomorphic_2(self):
     # Tests is_isomorphic on test case #2 (two flat clusters, different labelings)
     a = [1, 7, 1]
     b = [2, 3, 2]
     assert_(is_isomorphic(a, b))
     assert_(is_isomorphic(b, a))
예제 #14
0
 def test_is_isomorphic_1(self):
     # Tests is_isomorphic on test case #1 (one flat cluster, different labellings)
     a = [1, 1, 1]
     b = [2, 2, 2]
     assert_(is_isomorphic(a, b))
     assert_(is_isomorphic(b, a))
예제 #15
0
 def check_fcluster_maxclust_monocrit(self, t):
     expectedT = hierarchy_test_data.fcluster_maxclust[t]
     Z = single(hierarchy_test_data.Q_X)
     T = fcluster(Z, t, criterion='maxclust_monocrit', monocrit=maxdists(Z))
     assert_(is_isomorphic(T, expectedT))
예제 #16
0
 def check_fcluster(self, t, criterion):
     # Tests fcluster(Z, criterion=criterion, t=t) on a random 3-cluster data set.
     expectedT = getattr(hierarchy_test_data, 'fcluster_' + criterion)[t]
     Z = single(hierarchy_test_data.Q_X)
     T = fcluster(Z, criterion=criterion, t=t)
     assert_(is_isomorphic(T, expectedT))