def test_vq_large_nfeat(self): X = np.random.rand(20, 20) code_book = np.random.rand(3, 20) codes0, dis0 = _vq.vq(X, code_book) codes1, dis1 = py_vq(X, code_book) assert_allclose(dis0, dis1, 1e-5) assert_array_equal(codes0, codes1) X = X.astype(np.float32) code_book = code_book.astype(np.float32) codes0, dis0 = _vq.vq(X, code_book) codes1, dis1 = py_vq(X, code_book) assert_allclose(dis0, dis1, 1e-5) assert_array_equal(codes0, codes1)
def test_vq_1d(self): # Test special rank 1 vq algo, python implementation. data = X[:, 0] initc = data[:3] a, b = _vq.vq(data, initc) ta, tb = py_vq(data[:, np.newaxis], initc[:, np.newaxis]) assert_array_equal(a, ta) assert_array_equal(b, tb)
def test_vq_large_features(self): X = np.random.rand(10, 5) * 1000000 code_book = np.random.rand(2, 5) * 1000000 codes0, dis0 = _vq.vq(X, code_book) codes1, dis1 = py_vq(X, code_book) assert_allclose(dis0, dis1, 1e-5) assert_array_equal(codes0, codes1)
def test_vq_1d(self): """Test special rank 1 vq algo, python implementation.""" data = X[:, 0] initc = data[:3] a, b = _vq.vq(data, initc) ta, tb = py_vq(data[:, np.newaxis], initc[:, np.newaxis]) assert_array_equal(a, ta) assert_array_equal(b, tb)
def test_vq_1d(self): """Test special rank 1 vq algo, python implementation.""" data = X[:, 0] initc = data[:3] if TESTC: a, b = _vq.vq(data, initc) ta, tb = py_vq(data[:, np.newaxis], initc[:, np.newaxis]) assert_array_equal(a, ta) assert_array_equal(b, tb) else: print("== not testing C imp of vq (rank 1) ==")
def test_py_vq(self): initc = np.concatenate(([[X[0]], [X[1]], [X[2]]])) for tp in np.array, np.matrix: label1 = py_vq(tp(X), tp(initc))[0] assert_array_equal(label1, LABEL1)
def test_py_vq(self): initc = np.concatenate(([[X[0]], [X[1]], [X[2]]])) label1 = py_vq(X, initc)[0] assert_array_equal(label1, LABEL1)
def test_py_vq(self): initc = np.concatenate(([[X[0]], [X[1]], [X[2]]])) code = initc.copy() label1 = py_vq(X, initc)[0] assert_array_equal(label1, LABEL1)