コード例 #1
0
ファイル: test_abc.py プロジェクト: jontycarruthersphe/pygom
    def test_SIR_abc_SquareLoss(self):
        y = self.solution[1::, 1:3]

        # setting the parameters in the inference
        parameters = [
            pgabc.Parameter('beta', 'unif', 0, 3, logscale=False),
            pgabc.Parameter('gamma', 'unif', 0, 3, logscale=False)
        ]

        # creating the loss and abc objects
        sir_obj = pgabc.create_loss("SquareLoss", parameters, self.ode,
                                    self.x0, self.t[0], self.t[1::], y,
                                    ['I', 'R'])
        sir_abc = pgabc.ABC(sir_obj, parameters)

        # getting the posterior sample
        sir_abc.get_posterior_sample(N=100, tol=np.inf, G=10, q=0.5)
        sir_abc.continue_posterior_sample(N=100,
                                          tol=sir_abc.next_tol,
                                          G=10,
                                          q=0.5)

        # the estimate for beta must be between 0.485 and 0.515
        # the estimate for gamma must be between 0.32 and 0.3466
        med_est = np.median(sir_abc.res, axis=0)
        self.assertTrue(np.allclose(med_est, self.target, 1e-2, 1e-2))
コード例 #2
0
 def test_SIR_abc_NormalLoss(self):
     y = self.solution[1::, 1:3]
     parameters = [pgabc.Parameter('beta', 'unif', 0, 3, logscale=False), 
                   pgabc.Parameter('gamma', 'unif', 0, 3, logscale=False)]
     sir_obj = pgabc.create_loss(NormalLoss, parameters, self.ode, self.x0, self.t[0],
                               self.t[1::], y, ['I', 'R'])
     sir_abc = pgabc.ABC(sir_obj, parameters)
     sir_abc.get_posterior_sample(N=100, tol=np.inf, G=10, q=0.5)
     sir_abc.continue_posterior_sample(N=100, tol=sir_abc.next_tol, G=10, q=0.5)
     med_est = np.median(sir_abc.res, axis=0)
     self.assertTrue(np.allclose(med_est, self.target, 1e-2, 1e-2))