Exemplo n.º 1
0
    def test_prediction_linearn(self):
        model = LaplaceGLMM_N1K3('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.30483881,0.2252297,0.78056257,0.44734442,0.58824122,0.05238813,\
                       0.60337305,0.22889891,0.54169378,0.71885939])

        p = model.predict(self._X, self._G0, self._G1)
        for i in range(ps.shape[0]):
            self.assertAlmostEqual(ps[i], p[i])

        model = EPGLMM_N1K3('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])
Exemplo n.º 2
0
    def test_rmargll_gradient_linearn(self):
        def func(x, model):
            model.sig02 = x[0]
            model.sig12 = x[1]
            model.sign2 = x[2]
            model.beta = x[3:]
            return model._regular_marginal_loglikelihood()

        def grad(x, model):
            model.sig02 = x[0]
            model.sig12 = x[1]
            model.sign2 = x[2]
            model.beta = x[3:]
            return model._rmll_gradient()

        model = LaplaceGLMM_N1K3('logistic')
        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_N1K3('erf')
        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 )
Exemplo n.º 3
0
    def testr_rmargll_after_optimization_linearn(self):
        model = LaplaceGLMM_N1K3('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_N1K3('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())
Exemplo n.º 4
0
    def test_rmargll_linearn(self):
        model = LaplaceGLMM_N1K3('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_N1K3('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.5997198627, model._regular_marginal_loglikelihood())