Example #1
0
def test_probabilistic_pca_1():
    """test that probabilistic PCA yields a readonable score
    """
    n, p = 1000, 3
    X = randn(n, p)*.1 + np.array([3, 4, 5])
    ppca = ProbabilisticPCA(n_comp=2)
    ppca.fit(X)
    ll1 = ppca.score(X)
    h = 0.5 * np.log(2 * np.pi * np.exp(1) / 0.1**2) * p
    np.testing.assert_almost_equal(ll1.mean()/h, 1, 0)
Example #2
0
def test_probabilistic_pca_2():
    """test that probabilistic PCA correctly separated different datasets
    """
    n, p = 100, 3
    X = randn(n, p)*.1 + np.array([3, 4, 5])
    ppca = ProbabilisticPCA(n_comp=2)
    ppca.fit(X)
    ll1 = ppca.score(X)
    ll2 = ppca.score(randn(n, p)*.2 + np.array([3, 4, 5]))
    assert_true(ll1.mean() > ll2.mean())
Example #3
0
def test_probabilistic_pca_4():
    """Check that ppca select the right model
    """
    n, p = 200, 3
    Xl = randn(n, p) + randn(n, 1)*np.array([3, 4, 5]) + np.array([1, 0, 7])
    Xt = randn(n, p) + randn(n, 1)*np.array([3, 4, 5]) + np.array([1, 0, 7])
    ll = np.zeros(p)
    for k in range(p):
        ppca = ProbabilisticPCA(n_comp=k)
        ppca.fit(Xl)
        ll[k] = ppca.score(Xt).mean()

    assert_true(ll.argmax() == 1)
Example #4
0
def test_probabilistic_pca_3():
    """The homoscedastic model should work slightly worth
    than the heteroscedastic one in over-fitting condition
    """
    n, p = 100, 3
    X = randn(n, p)*.1 + np.array([3, 4, 5])
    ppca = ProbabilisticPCA(n_comp=2)
    ppca.fit(X)
    ll1 = ppca.score(X)
    ppca.fit(X, False)
    ll2 = ppca.score(X)
    assert_true(ll1.mean() < ll2.mean())