コード例 #1
0
def test_gp_nonfinite_phenotype():
    random = RandomState(94584)
    N = 50
    X = random.randn(N, 100)
    offset = 0.5

    mean = OffsetMean(N)
    mean.offset = offset
    mean.fix_offset()

    cov = LinearCov(X)
    cov.scale = 1.0

    y = zeros(N)

    y[0] = nan
    with pytest.raises(ValueError):
        GP(y, mean, cov)

    y[0] = -inf
    with pytest.raises(ValueError):
        GP(y, mean, cov)

    y[0] = +inf
    with pytest.raises(ValueError):
        GP(y, mean, cov)
コード例 #2
0
ファイル: test_ggp_expfam.py プロジェクト: mindis/glimix-core
def _get_data():
    random = RandomState(0)
    N = 10
    X = random.randn(N, N + 1)
    X -= X.mean(0)
    X /= X.std(0)
    X /= sqrt(X.shape[1])
    offset = 1.0

    mean = OffsetMean(N)
    mean.offset = offset

    cov_left = LinearCov(X)
    cov_left.scale = 1.5

    cov_right = EyeCov(N)
    cov_right.scale = 1.5

    cov = SumCov([cov_left, cov_right])

    lik = BernoulliProdLik(LogitLink())

    y = GGPSampler(lik, mean, cov).sample(random)

    return dict(mean=mean,
                cov=cov,
                lik=lik,
                y=y,
                cov_left=cov_left,
                cov_right=cov_right)
コード例 #3
0
def _outcome_sample(random, offset, X):
    n = X.shape[0]
    mean = OffsetMean(n)
    mean.offset = offset

    cov_left = LinearCov(X)
    cov_left.scale = 1.5

    cov_right = EyeCov(n)
    cov_right.scale = 1.5

    cov = SumCov([cov_left, cov_right])

    lik = DeltaProdLik()

    return GGPSampler(lik, mean, cov).sample(random)
コード例 #4
0
def test_gp_value_1():
    random = RandomState(94584)
    N = 50
    X = random.randn(N, 100)
    offset = 0.5

    mean = OffsetMean(N)
    mean.offset = offset
    mean.fix_offset()

    cov = LinearCov(X)
    cov.scale = 1.0

    y = random.randn(N)

    gp = GP(y, mean, cov)
    assert_allclose(gp.value(), -153.623791551399108)
コード例 #5
0
def test_gp_gradient():
    random = RandomState(94584)
    N = 50
    X = random.randn(N, 100)
    offset = 0.5

    mean = OffsetMean(N)
    mean.offset = offset
    mean.fix_offset()

    cov = LinearCov(X)
    cov.scale = 1.0

    y = random.randn(N)

    gp = GP(y, mean, cov)

    assert_allclose(gp._check_grad(), 0, atol=1e-5)
コード例 #6
0
def test_gp_value_2():
    random = RandomState(94584)
    N = 50
    X1 = random.randn(N, 3)
    X2 = random.randn(N, 100)

    mean = LinearMean(X1)

    cov = LinearCov(X2)
    cov.scale = 1.0

    y = random.randn(N)

    gp = GP(y, mean, cov)
    assert_allclose(gp.value(), -153.091074766)

    mean.effsizes = [3.4, 1.11, -6.1]
    assert_allclose(gp.value(), -178.273116338)
コード例 #7
0
def test_sumcov():
    random = np.random.RandomState(0)
    X = random.randn(3, 2)
    cov_left = LinearCov(X)

    K = random.randn(3, 3)
    K = K @ K.T
    cov_right = GivenCov(K)

    cov = SumCov([cov_left, cov_right])
    assert_allclose(cov.value(), cov_left.value() + cov_right.value())
    assert_allclose(cov._check_grad(), 0, atol=1e-5)
    cov_left.scale = 0.1
    assert_allclose(cov._check_grad(), 0, atol=1e-5)

    with pytest.raises(ValueError):
        K = random.randn(3, 3)
        GivenCov(K)
コード例 #8
0
ファイル: __init__.py プロジェクト: mindis/glimix-core
def linear_eye_cov():
    from numpy import sqrt
    from numpy.random import RandomState
    from glimix_core.cov import EyeCov, LinearCov, SumCov

    random = RandomState(458)
    X = random.randn(_nsamples(), _nsamples() + 1)
    X -= X.mean(0)
    X /= X.std(0)
    X /= sqrt(X.shape[1])

    cov_left = LinearCov(X)
    cov_left.scale = 1.0

    cov_right = EyeCov(_nsamples())
    cov_right.scale = 1.0

    return SumCov([cov_left, cov_right])
コード例 #9
0
def test_gp_maximize():
    random = RandomState(94584)
    N = 50
    X = random.randn(N, 100)
    offset = 0.5

    mean = OffsetMean(N)
    mean.offset = offset
    mean.fix_offset()

    cov = LinearCov(X)
    cov.scale = 1.0

    y = random.randn(N)

    gp = GP(y, mean, cov)

    assert_allclose(gp.value(), -153.623791551)
    gp.fit(verbose=False)
    assert_allclose(gp.value(), -79.8992122415)
コード例 #10
0
ファイル: test_cov_linear.py プロジェクト: mindis/glimix-core
def test_linearcov():
    X = RandomState(0).randn(3, 2)
    cov = LinearCov(X)
    assert_allclose(cov.value(), X @ X.T)
    assert_allclose(cov._check_grad(), 0, atol=1e-5)
    assert_allclose(cov.scale, 1.0)
    cov.scale = 1.5
    assert_allclose(cov.scale, 1.5)
    assert_allclose(cov.value(), 1.5 * (X @ X.T))
    assert_allclose(cov._check_grad(), 0, atol=1e-5)
コード例 #11
0
def test_lmm_predict():
    random = RandomState(9458)
    n = 30

    X = random.randn(n, n + 1)
    X -= X.mean(0)
    X /= X.std(0)
    X /= sqrt(X.shape[1])

    offset = 1.0

    mean = OffsetMean(n)
    mean.offset = offset

    cov_left = LinearCov(X)
    cov_left.scale = 1.5

    cov_right = EyeCov(n)
    cov_right.scale = 1.5

    cov = SumCov([cov_left, cov_right])

    lik = DeltaProdLik()

    y = GGPSampler(lik, mean, cov).sample(random)

    QS = economic_qs_linear(X)

    lmm = LMM(y, ones((n, 1)), QS)

    lmm.fit(verbose=False)

    plmm = LMMPredict(y, lmm.beta, lmm.v0, lmm.v1, lmm.mean(),
                      lmm.covariance())

    K = dot(X, X.T)
    pm = plmm.predictive_mean(ones((n, 1)), K, K.diagonal())
    assert_allclose(corrcoef(y, pm)[0, 1], 0.8358820971891354)