示例#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 check_fcluster(self, t, criterion):
     # Tests fcluster(Z, criterion=criterion, t=t) on a random 3-cluster data set.
     expectedT = np.int_(eo['fclusterdata-%s-%d' % (criterion, t)])
     X = eo['Q-X']
     Y = pdist(X)
     Z = linkage(Y)
     T = fcluster(Z, criterion=criterion, t=t)
     assert_(is_isomorphic(T, expectedT))
示例#3
0
 def check_fcluster_monocrit(self, t, criterion):
     # Tests fcluster(Z, criterion='monocrit'/'maxclust_monocrit', t=t,
     # monicrit=maxdists(Z)) on a random 3-cluster data set.
     expectedT = np.int_(eo['fcluster-%s-%d' % (criterion, t)])
     X = eo['Q-X']
     Y = pdist(X)
     Z = linkage(Y)
     T = fcluster(Z, criterion=criterion, t=t, monocrit=maxdists(Z))
     assert_(is_isomorphic(T, expectedT))
示例#4
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))
示例#5
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))
示例#6
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))
示例#7
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))
示例#8
0
 def test_is_isomorphic_3(self):
     # Tests is_isomorphic on test case #3 (no flat clusters)
     a = []
     b = []
     assert_(is_isomorphic(a, b))
示例#9
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))
示例#10
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))
示例#11
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))
示例#12
0
 def test_is_isomorphic_7(self):
     # Regression test for gh-6271
     assert_(not is_isomorphic([1, 2, 3], [1, 1, 1]))
示例#13
0
 def check_fclusterdata(self, t, criterion):
     # Tests fclusterdata(X, criterion=criterion, t=t) on a random 3-cluster data set.
     expectedT = getattr(hierarchy_test_data, "fcluster_" + criterion)[t]
     X = hierarchy_test_data.Q_X
     T = fclusterdata(X, criterion=criterion, t=t)
     assert_(is_isomorphic(T, expectedT))
示例#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 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))
示例#16
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))
示例#17
0
 def test_is_isomorphic_3(self):
     # Tests is_isomorphic on test case #3 (no flat clusters)
     a = []
     b = []
     assert_(is_isomorphic(a, b))
示例#18
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)
示例#19
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)
示例#20
0
 def test_is_isomorphic_7(self):
     # Regression test for gh-6271
     assert_(not is_isomorphic([1, 2, 3], [1, 1, 1]))
示例#21
0
 def check_fclusterdata(self, t, criterion):
     # Tests fclusterdata(X, criterion=criterion, t=t) on a random 3-cluster data set.
     expectedT = np.int_(eo['fclusterdata-%s-%d' % (criterion, t)])
     X = eo['Q-X']
     T = fclusterdata(X, criterion=criterion, t=t)
     assert_(is_isomorphic(T, expectedT))