def testtemplate(self): X = nr.randn(10,2) A = np.vstack(( np.ones((7,2)), np.zeros((3,2)) )) X = X + 3*A C,L,J = fc.cmeans(X,2) L = np.array([0,0,0,0,0,1,1,1,1,1]) C,L,J = fc.cmeans(X,2,L) self.assert_(np.mean(L[:7])<0.5)
def testcmeans1(self): X = nr.randn(10,2) A = np.concatenate([np.ones((7,2)),np.zeros((3,2))]) X = X+3*A; C,L,J = fc.cmeans(X,2) L = np.array([0,0,0,0,0,1,1,1,1,1]) C,L,J = fc.cmeans(X,2,L) self.assert_(np.mean(L[:7])<0.5)
def testcmeans2(self): X = nr.randn(10000,2) A = np.concatenate([np.ones((7000,2)),np.zeros((3000,2))]) X = X+3*A L = np.concatenate([np.ones(5000), np.zeros(5000)]).astype(np.int) C,L,J = fc.cmeans(X,2,L) l = L[:7000].astype(np.float) self.assert_(np.mean(l)>0.9)
def testvarious(self): import sys import weakref Y = nr.randn(20,2) X = Y[::2, :] del Y self.assert_(X.flags['CONTIGUOUS'] == False) A = np.vstack(( np.ones((7,2)), np.zeros((3,2)) )) X = X + 3*A wX = weakref.ref(X) print sys.getrefcount(X) self.assert_(sys.getrefcount(X) <4) # fixme : Previsously, the good answer was supposed to be "2"; # It is unclear to me (b. thirion) what it should be exactly L1 = np.array([0,0,0,0,0,1,1,1,1,1]) C,L,J = fc.cmeans(X,2,L1) self.assert_(id(L1) != id(L)) C,L,J = fc.cmeans(X,2,L) del X self.assert_(wX() == None)