예제 #1
0
def test_score_matching_matches_sym():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    a_sym = develop_gaussian.fit_sym(Z, sigma, lmbda)
    a = gaussian.fit(Z, Z, sigma, lmbda)
    
    assert_allclose(a, a_sym)
예제 #2
0
def test_score_matching_matches_sym():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

    a_sym = develop_gaussian.fit_sym(Z, sigma, lmbda)
    a = gaussian.fit(Z, Z, sigma, lmbda)

    assert_allclose(a, a_sym)
예제 #3
0
def test_score_matching_objective_matches_sym():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

    K = gaussian_kernel(Z, sigma=sigma)
    J_sym = develop_gaussian.fit_sym(Z, sigma, lmbda, K)
    J = gaussian.fit(Z, Z, sigma, lmbda, K)

    assert_allclose(J, J_sym)
예제 #4
0
def test_score_matching_sym_execute_only():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

    # only run here
    a = develop_gaussian.fit_sym(Z, sigma, lmbda)
    assert type(a) == np.ndarray
    assert len(a.shape) == 1
    assert len(a) == len(Z)
def test_fit_sym_matches_full():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

    a = develop_gaussian.fit_sym(Z, sigma, lmbda)

    R = incomplete_cholesky_gaussian(Z, sigma, eta=0.1)["R"]
    a_cholesky_cg = develop_gaussian_low_rank.fit_sym(Z, sigma, lmbda, L=R.T)
    assert_allclose(a, a_cholesky_cg, atol=3)
def test_fit_sym_matches_full():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    a = develop_gaussian.fit_sym(Z, sigma, lmbda)
    
    R = incomplete_cholesky_gaussian(Z, sigma, eta=0.1)["R"]
    a_cholesky_cg = develop_gaussian_low_rank.fit_sym(Z, sigma, lmbda, L=R.T)
    assert_allclose(a, a_cholesky_cg, atol=3)
예제 #7
0
def test_score_matching_objective_matches_sym():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    K = gaussian_kernel(Z, sigma=sigma)
    J_sym = develop_gaussian.fit_sym(Z, sigma, lmbda, K)
    J = gaussian.fit(Z, Z, sigma, lmbda, K)
    
    assert_allclose(J, J_sym)
예제 #8
0
def test_score_matching_sym_execute_only():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    # only run here
    a = develop_gaussian.fit_sym(Z, sigma, lmbda)
    assert type(a) == np.ndarray
    assert len(a.shape) == 1
    assert len(a) == len(Z)
예제 #9
0
def test_objective_sym_same_as_from_estimation():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

    K = gaussian_kernel(Z, sigma=sigma)
    a = develop_gaussian.fit_sym(Z, sigma, lmbda, K)
    C = develop_gaussian.compute_C_sym(Z, K, sigma)
    b = develop_gaussian.compute_b_sym(Z, K, sigma)
    J = develop_gaussian.objective_sym(Z, sigma, lmbda, a, K, b, C)

    J2 = develop_gaussian.objective_sym(Z, sigma, lmbda, a, K)
    assert_almost_equal(J, J2)
예제 #10
0
def test_objective_sym_optimum():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)

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

    for _ in range(10):
        a_random = np.random.randn(len(Z))
        J = develop_gaussian.objective_sym(Z, sigma, lmbda, a_random, K)
        assert J >= J_opt
예제 #11
0
def test_objective_sym_same_as_from_estimation():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    K = gaussian_kernel(Z, sigma=sigma)
    a = develop_gaussian.fit_sym(Z, sigma, lmbda, K)
    C = develop_gaussian.compute_C_sym(Z, K, sigma)
    b = develop_gaussian.compute_b_sym(Z, K, sigma)
    J = develop_gaussian.objective_sym(Z, sigma, lmbda, a, K, b, C)
    
    J2 = develop_gaussian.objective_sym(Z, sigma, lmbda, a, K)
    assert_almost_equal(J, J2)
예제 #12
0
def test_objective_sym_optimum():
    sigma = 1.
    lmbda = 1.
    Z = np.random.randn(100, 2)
    
    K = gaussian_kernel(Z, sigma=sigma)
    a = develop_gaussian.fit_sym(Z, sigma, lmbda, K)
    J_opt = develop_gaussian.objective_sym(Z, sigma, lmbda, a, K)
    
    for _ in range(10):
        a_random = np.random.randn(len(Z))
        J = develop_gaussian.objective_sym(Z, sigma, lmbda, a_random, K)
        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.)