コード例 #1
0
def test_compute_b_matches_sym():
    sigma = 1.
    Z = np.random.randn(10, 2)

    K = gaussian_kernel(Z, sigma=sigma)
    b = develop_gaussian.compute_b_sym(Z, K, sigma=sigma)
    b_sym = gaussian.compute_b(Z, Z, K, sigma=sigma)
    assert_allclose(b, b_sym)
コード例 #2
0
def test_compute_b_matches_sym():
    sigma = 1.
    Z = np.random.randn(10, 2)
    
    K = gaussian_kernel(Z, sigma=sigma)
    b = develop_gaussian.compute_b_sym(Z, K, sigma=sigma)
    b_sym = gaussian.compute_b(Z, Z, K, sigma=sigma)
    assert_allclose(b, b_sym)
コード例 #3
0
def test_compute_b_matches_full():
    sigma = 1.
    X = np.random.randn(100, 2)
    Y = np.random.randn(50, 2)

    low_rank_dim = int(len(X) * 0.9)
    kernel = lambda X, Y: gaussian_kernel(X, Y, sigma=sigma)
    K_XY = kernel(X, Y)
    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)

    x = gaussian.compute_b(X, Y, K_XY, sigma)
    y = gaussian_low_rank.compute_b(X, Y, R.T, R_test.T, sigma)
    assert_allclose(x, y, atol=5e-1)
コード例 #4
0
def test_compute_b_matches_full():
    sigma = 1.
    X = np.random.randn(100, 2)
    Y = np.random.randn(50, 2)
    
    low_rank_dim = int(len(X) * 0.9)
    kernel = lambda X, Y: gaussian_kernel(X, Y, sigma=sigma)
    K_XY = kernel(X, Y)
    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)
    
    x = gaussian.compute_b(X, Y, K_XY, sigma)
    y = gaussian_low_rank.compute_b(X, Y, R.T, R_test.T, sigma)
    assert_allclose(x, y, atol=5e-1)
コード例 #5
0
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)
コード例 #6
0
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)