def test_objective_matches_sym():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    kernel = lambda X, Y: gaussian_kernel(X, Y, sigma=sigma)
    alpha = np.random.randn(len(Z))
    
    temp = incomplete_cholesky(Z, kernel, eta=0.1)
    I, R, nu = (temp["I"], temp["R"], temp["nu"])
    
    R_test = incomplete_cholesky_new_points(Z, Z, kernel, I, R, nu)
    
    b = gaussian_low_rank.compute_b(Z, Z, R.T, R_test.T, sigma)
    
    J_sym = develop_gaussian_low_rank.objective_sym(Z, sigma, lmbda, alpha, R.T, b)
    J = gaussian_low_rank.objective(Z, Z, sigma, lmbda, alpha, R.T, R_test.T, b)
    
    assert_close(J, J_sym)
def test_objective_matches_sym():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

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

    temp = incomplete_cholesky(Z, kernel, eta=0.1)
    I, R, nu = (temp["I"], temp["R"], temp["nu"])

    R_test = incomplete_cholesky_new_points(Z, Z, kernel, I, R, nu)

    b = gaussian_low_rank.compute_b(Z, Z, R.T, R_test.T, sigma)

    J_sym = develop_gaussian_low_rank.objective_sym(Z, sigma, lmbda, alpha,
                                                    R.T, b)
    J = gaussian_low_rank.objective(Z, Z, sigma, lmbda, alpha, R.T, R_test.T,
                                    b)

    assert_close(J, J_sym)
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)