def check_is_valid_im_various_size(self, nrow, ncol, valid): # Tests is_valid_im(R) with linkage matrics of various sizes R = np.asarray([[0, 1, 3.0, 2, 5], [3, 2, 4.0, 3, 3]], dtype=np.double) R = R[:nrow, :ncol] assert_(is_valid_im(R) == valid) if not valid: assert_raises(ValueError, is_valid_im, R, throw=True)
def test_is_valid_im_4_and_up(self): # Tests is_valid_im(R) on im on observation sets between sizes 4 and 15 # (step size 3). for i in xrange(4, 15, 3): y = np.random.rand(i * (i - 1) // 2) Z = linkage(y) R = inconsistent(Z) assert_(is_valid_im(R) == True)
def test_is_valid_im_4_and_up(self): # Tests is_valid_im(R) on im on observation sets between sizes 4 and 15 # (step size 3). for i in xrange(4, 15, 3): y = np.random.rand(i*(i-1)//2) Z = linkage(y) R = inconsistent(Z) assert_(is_valid_im(R) == True)
def test_is_valid_im_4_and_up_neg_dist(self): # Tests is_valid_im(R) on im on observation sets between sizes 4 and 15 # (step size 3) with negative link counts. for i in xrange(4, 15, 3): y = np.random.rand(i * (i - 1) // 2) Z = linkage(y) R = inconsistent(Z) R[i // 2, 2] = -0.5 assert_(is_valid_im(R) == False) assert_raises(ValueError, is_valid_im, R, throw=True)
def test_is_valid_im_4_and_up_neg_dist(self): # Tests is_valid_im(R) on im on observation sets between sizes 4 and 15 # (step size 3) with negative link counts. for i in xrange(4, 15, 3): y = np.random.rand(i*(i-1)//2) Z = linkage(y) R = inconsistent(Z) R[i//2,2] = -0.5 assert_(is_valid_im(R) == False) assert_raises(ValueError, is_valid_im, R, throw=True)
def test_is_valid_im_empty(self): # Tests is_valid_im(R) with empty inconsistency matrix. R = np.zeros((0, 4), dtype=np.double) assert_(is_valid_im(R) == False) assert_raises(ValueError, is_valid_im, R, throw=True)
def test_is_valid_im_int_type(self): # Tests is_valid_im(R) with integer type. R = np.asarray([[0, 1, 3.0, 2], [3, 2, 4.0, 3]], dtype=np.int) assert_(is_valid_im(R) == False) assert_raises(TypeError, is_valid_im, R, throw=True)