def test_rmargll_after_optimization(self): model = LaplaceGLMM_N3K1('logistic') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) model.optimize() self.assertAlmostEqual(-6.75677866924, model._regular_marginal_loglikelihood()) model = EPGLMM_N3K1('erf') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) model.optimize() self.assertAlmostEqual(-6.75424440734, model._regular_marginal_loglikelihood()) model = LaplaceGLMM_N3K1('logistic', 'l2') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) model.optimize() self.assertAlmostEqual(-6.7584132443836662, model._regular_marginal_loglikelihood()) model = EPGLMM_N3K1('erf', 'l2') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) model.optimize() self.assertAlmostEqual(-6.7545709287754718, model._regular_marginal_loglikelihood())
def test_prediction(self): model = LaplaceGLMM_N3K1('logistic') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) ps = NP.array([0.30481858,0.22520247,0.78060709,0.44734337,0.58824651,0.052388,\ 0.60337951,0.22886631,0.54169641,0.71888192]) p = model.predict(self._X, self._G0, self._G1) for i in range(ps.shape[0]): self.assertAlmostEqual(ps[i], p[i], places=4) model = EPGLMM_N3K1('erf') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) ps = NP.array([0.35487175, 0.20959901, 0.77285232, 0.48305102, 0.59542164,\ 0.02770879, 0.6205743 , 0.14239838, 0.45330375, 0.77123692]) p = model.predict(self._X, self._G0, self._G1) for i in range(ps.shape[0]): self.assertAlmostEqual(ps[i], p[i])
def test_setK_rmargll_after_optimization(self): model = LaplaceGLMM_N3K1('logistic') model.setK(NP.dot(self._G0, self._G0.T), NP.dot(self._G1, self._G1.T)) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) model.optimize() self.assertAlmostEqual(-6.75677866924, model._regular_marginal_loglikelihood()) model = EPGLMM_N3K1('erf') model.setK(NP.dot(self._G0, self._G0.T), NP.dot(self._G1, self._G1.T)) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) model.optimize() self.assertAlmostEqual(-6.75424440734, model._regular_marginal_loglikelihood())
def test_margll_gradient(self): def func(x, model): model.sig02 = x[0] model.sig12 = x[1] model.sign2 = x[2] model.beta = x[3:] return model.marginal_loglikelihood() def grad(x, model): model.sig02 = x[0] model.sig12 = x[1] model.sign2 = x[2] model.beta = x[3:] return model._mll_gradient() model = LaplaceGLMM_N3K1('logistic', 'l2') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) self.assertAlmostEqual( 0.0, SP.optimize.check_grad(func, grad, NP.array([1.0,1.2,1.5,-3.0,0.4]), model), places=5 ) model = EPGLMM_N3K1('erf', 'l2') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) self.assertAlmostEqual( 0.0, SP.optimize.check_grad(func, grad, NP.array([1.0,1.2,1.5,-3.0,0.4]), model), places=5 )
def test_margll(self): model = LaplaceGLMM_N3K1('logistic', 'l2') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) self.assertAlmostEqual(-14.635329282675063, model.marginal_loglikelihood()) model = EPGLMM_N3K1('erf', 'l2') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) self.assertAlmostEqual(-17.413719862714526, model.marginal_loglikelihood())
def test_rmargll(self): model = LaplaceGLMM_N3K1('logistic') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) self.assertAlmostEqual(-13.821329282675068, model._regular_marginal_loglikelihood()) model = EPGLMM_N3K1('erf') model.setG(self._G0, self._G1) model.setX(self._X) model.sety(self._y) model.sig02 = 1.5 model.sig12 = 0.5 model.sign2 = 0.8 model.beta = NP.array([2.0, -1.0]) self.assertAlmostEqual(-16.599719862714529, model._regular_marginal_loglikelihood())