def test_compute_C_run_asym():
    sigma = 1.
    X = np.random.randn(100, 2)
    Y = np.random.randn(100, 2)

    K_XY = gaussian_kernel(X, Y, sigma=sigma)
    _ = gaussian.compute_C(X, Y, K_XY, sigma=sigma)
Example #2
0
def test_compute_C_run_asym():
    sigma = 1.
    X = np.random.randn(100, 2)
    Y = np.random.randn(100, 2)

    K_XY = gaussian_kernel(X, Y, sigma=sigma)
    _ = gaussian.compute_C(X, Y, K_XY, sigma=sigma)
def test_compute_C_matches_sym():
    sigma = 1.
    Z = np.random.randn(10, 2)

    K = gaussian_kernel(Z, sigma=sigma)
    C_sym = develop_gaussian.compute_C_sym(Z, K, sigma=sigma)
    C = gaussian.compute_C(Z, Z, K, sigma=sigma)
    assert_allclose(C, C_sym)
def test_compute_C_matches_sym():
    sigma = 1.
    Z = np.random.randn(10, 2)
    
    K = gaussian_kernel(Z, sigma=sigma)
    C_sym = develop_gaussian.compute_C_sym(Z, K, sigma=sigma)
    C = gaussian.compute_C(Z, Z, K, sigma=sigma)
    assert_allclose(C, C_sym)
def test_apply_C_left_matches_full():
    sigma = 1.
    N = 100
    X = np.random.randn(N, 2)
    Y = np.random.randn(20, 2)
    low_rank_dim = int(len(X) * .9)
    kernel = lambda X, Y = None: gaussian_kernel(X, Y, sigma=sigma)
    K_XY = kernel(X, Y)
    K = kernel(X)
    
    temp = incomplete_cholesky(X, kernel, eta=low_rank_dim)
    I, R, nu = (temp["I"], temp["R"], temp["nu"])
    R_test = incomplete_cholesky_new_points(X, Y, kernel, I, R, nu)
    
    v = np.random.randn(X.shape[0])
    lmbda = 1.
    
    x = (gaussian.compute_C(X, Y, K_XY, sigma) + (K + np.eye(len(X))) * lmbda).dot(v)
    y = gaussian_low_rank.apply_left_C(v, X, Y, R.T, R_test.T, lmbda)
    assert_allclose(x, y, atol=1e-1)
def test_apply_C_left_matches_full():
    sigma = 1.
    N = 100
    X = np.random.randn(N, 2)
    Y = np.random.randn(20, 2)
    low_rank_dim = int(len(X) * .9)
    kernel = lambda X, Y=None: gaussian_kernel(X, Y, sigma=sigma)
    K_XY = kernel(X, Y)
    K = kernel(X)

    temp = incomplete_cholesky(X, kernel, eta=low_rank_dim)
    I, R, nu = (temp["I"], temp["R"], temp["nu"])
    R_test = incomplete_cholesky_new_points(X, Y, kernel, I, R, nu)

    v = np.random.randn(X.shape[0])
    lmbda = 1.

    x = (gaussian.compute_C(X, Y, K_XY, sigma) +
         (K + np.eye(len(X))) * lmbda).dot(v)
    y = gaussian_low_rank.apply_left_C(v, X, Y, R.T, R_test.T, lmbda)
    assert_allclose(x, y, atol=1e-1)
def test_objective_matches_full():
    sigma = 1.
    lmbda = 1.
    X = np.random.randn(100, 2)
    Y = np.random.randn(10, 2)
    low_rank_dim = int(len(X) * 0.9)
    
    kernel = lambda X, Y: gaussian_kernel(X, Y, sigma=sigma)
    alpha = np.random.randn(len(X))
    
    K_XY = kernel(X, Y)
    C = gaussian.compute_C(X, Y, K_XY, sigma)
    b = gaussian.compute_b(X, Y, K_XY, sigma)
    J_full = gaussian.objective(X, Y, sigma, lmbda, alpha, K_XY=K_XY, b=b, C=C)
    
    temp = incomplete_cholesky(X, kernel, eta=low_rank_dim)
    I, R, nu = (temp["I"], temp["R"], temp["nu"])
    R_test = incomplete_cholesky_new_points(X, Y, kernel, I, R, nu)
    b = gaussian_low_rank.compute_b(X, Y, R.T, R_test.T, sigma)
    J = gaussian_low_rank.objective(X, Y, sigma, lmbda, alpha, R.T, R_test.T, b)
    
    assert_close(J, J_full, decimal=1)
def test_objective_matches_full():
    sigma = 1.
    lmbda = 1.
    X = np.random.randn(100, 2)
    Y = np.random.randn(10, 2)
    low_rank_dim = int(len(X) * 0.9)

    kernel = lambda X, Y: gaussian_kernel(X, Y, sigma=sigma)
    alpha = np.random.randn(len(X))

    K_XY = kernel(X, Y)
    C = gaussian.compute_C(X, Y, K_XY, sigma)
    b = gaussian.compute_b(X, Y, K_XY, sigma)
    J_full = gaussian.objective(X, Y, sigma, lmbda, alpha, K_XY=K_XY, b=b, C=C)

    temp = incomplete_cholesky(X, kernel, eta=low_rank_dim)
    I, R, nu = (temp["I"], temp["R"], temp["nu"])
    R_test = incomplete_cholesky_new_points(X, Y, kernel, I, R, nu)
    b = gaussian_low_rank.compute_b(X, Y, R.T, R_test.T, sigma)
    J = gaussian_low_rank.objective(X, Y, sigma, lmbda, alpha, R.T, R_test.T,
                                    b)

    assert_close(J, J_full, decimal=1)