def test_objective_sym_optimum():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    L = incomplete_cholesky_gaussian(Z, sigma, eta=0.1)["R"].T
    a = develop_gaussian_low_rank.fit_sym(Z, sigma, lmbda, L)
    b = develop_gaussian_low_rank.compute_b_sym(Z, L, sigma)
    J_opt = develop_gaussian_low_rank.objective_sym(Z, sigma, lmbda, a, L, b)
    
    for _ in range(10):
        a_random = np.random.randn(len(Z))
        J = develop_gaussian_low_rank.objective_sym(Z, sigma, lmbda, a_random, L)
        assert J >= J_opt
def test_objective_sym_optimum():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

    L = incomplete_cholesky_gaussian(Z, sigma, eta=0.1)["R"].T
    a = develop_gaussian_low_rank.fit_sym(Z, sigma, lmbda, L)
    b = develop_gaussian_low_rank.compute_b_sym(Z, L, sigma)
    J_opt = develop_gaussian_low_rank.objective_sym(Z, sigma, lmbda, a, L, b)

    for _ in range(10):
        a_random = np.random.randn(len(Z))
        J = develop_gaussian_low_rank.objective_sym(Z, sigma, lmbda, a_random,
                                                    L)
        assert J >= J_opt
def test_objective_sym_matches_full():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    K = gaussian_kernel(Z, sigma=sigma)
    a_opt = develop_gaussian.fit_sym(Z, sigma, lmbda, K)
    J_opt = develop_gaussian.objective_sym(Z, sigma, lmbda, a_opt, K)
    
    L = incomplete_cholesky_gaussian(Z, sigma, eta=0.01)["R"].T
    a_opt_chol = develop_gaussian_low_rank.fit_sym(Z, sigma, lmbda, L)
    J_opt_chol = develop_gaussian_low_rank.objective_sym(Z, sigma, lmbda, a_opt_chol, L)
    
    assert_almost_equal(J_opt, J_opt_chol, delta=2.)
def test_objective_sym_matches_full():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

    K = gaussian_kernel(Z, sigma=sigma)
    a_opt = develop_gaussian.fit_sym(Z, sigma, lmbda, K)
    J_opt = develop_gaussian.objective_sym(Z, sigma, lmbda, a_opt, K)

    L = incomplete_cholesky_gaussian(Z, sigma, eta=0.01)["R"].T
    a_opt_chol = develop_gaussian_low_rank.fit_sym(Z, sigma, lmbda, L)
    J_opt_chol = develop_gaussian_low_rank.objective_sym(
        Z, sigma, lmbda, a_opt_chol, L)

    assert_almost_equal(J_opt, J_opt_chol, delta=2.)
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)