def test_glmmexpfam_precise(): nsamples = 10 random = RandomState(0) X = random.randn(nsamples, 5) K = linear_eye_cov().value() QS = economic_qs(K) ntri = random.randint(1, 30, nsamples) nsuc = [random.randint(0, i) for i in ntri] glmm = GLMMExpFam(nsuc, ["binomial", ntri], X, QS) glmm.beta = asarray([1.0, 0, 0.5, 0.1, 0.4]) glmm.scale = 1.0 assert_allclose(glmm.lml(), -44.74191041468836, atol=ATOL, rtol=RTOL) glmm.scale = 2.0 assert_allclose(glmm.lml(), -36.19907331929086, atol=ATOL, rtol=RTOL) glmm.scale = 3.0 assert_allclose(glmm.lml(), -33.02139830387104, atol=ATOL, rtol=RTOL) glmm.scale = 4.0 assert_allclose(glmm.lml(), -31.42553401678996, atol=ATOL, rtol=RTOL) glmm.scale = 5.0 assert_allclose(glmm.lml(), -30.507029479473243, atol=ATOL, rtol=RTOL) glmm.scale = 6.0 assert_allclose(glmm.lml(), -29.937569702301232, atol=ATOL, rtol=RTOL) glmm.delta = 0.1 assert_allclose(glmm.lml(), -30.09977907145003, atol=ATOL, rtol=RTOL) assert_allclose(glmm._check_grad(), 0, atol=1e-3, rtol=RTOL)
def test_glmmexpfam_delta_one_zero(): random = RandomState(1) n = 30 X = random.randn(n, 6) K = dot(X, X.T) K /= K.diagonal().mean() QS = economic_qs(K) ntri = random.randint(1, 30, n) nsuc = [random.randint(0, i) for i in ntri] glmm = GLMMExpFam(nsuc, ("binomial", ntri), X, QS) glmm.beta = asarray([1.0, 0, 0.5, 0.1, 0.4, -0.2]) glmm.delta = 0 assert_allclose(glmm.lml(), -113.24570457063275) assert_allclose(glmm._check_grad(step=1e-4), 0, atol=1e-2) glmm.fit(verbose=False) assert_allclose(glmm.lml(), -98.21144899310399, atol=ATOL, rtol=RTOL) assert_allclose(glmm.delta, 0, atol=ATOL, rtol=RTOL) glmm.delta = 1 assert_allclose(glmm.lml(), -98.00058169240869, atol=ATOL, rtol=RTOL) assert_allclose(glmm._check_grad(step=1e-4), 0, atol=1e-1) glmm.fit(verbose=False) assert_allclose(glmm.lml(), -72.82680948264196, atol=ATOL, rtol=RTOL) assert_allclose(glmm.delta, 0.9999999850988439, atol=ATOL, rtol=RTOL)
def test_glmmexpfam_scale_very_high(): nsamples = 10 random = RandomState(0) X = random.randn(nsamples, 5) K = linear_eye_cov().value() QS = economic_qs(K) ntri = random.randint(1, 30, nsamples) nsuc = [random.randint(0, i) for i in ntri] glmm = GLMMExpFam(nsuc, ("binomial", ntri), X, QS) glmm.beta = asarray([1.0, 0, 0.5, 0.1, 0.4]) glmm.scale = 30.0 assert_allclose(glmm.lml(), -29.632791380478736, atol=ATOL, rtol=RTOL) assert_allclose(glmm._check_grad(), 0, atol=1e-3)
def test_glmmexpfam_delta1(): nsamples = 10 random = RandomState(0) X = random.randn(nsamples, 5) K = linear_eye_cov().value() QS = economic_qs(K) ntri = random.randint(1, 30, nsamples) nsuc = [random.randint(0, i) for i in ntri] glmm = GLMMExpFam(nsuc, ("binomial", ntri), X, QS) glmm.beta = asarray([1.0, 0, 0.5, 0.1, 0.4]) glmm.delta = 1 assert_allclose(glmm.lml(), -47.09677870648636, atol=ATOL, rtol=RTOL) assert_allclose(glmm._check_grad(), 0, atol=1e-4)