def test_compute_criteria_computes_criteria_correctly(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) test_aic = 169440.83719024697 test_bic = 169245.62163088709 test_deviance = 337950.6823459795 assert np.isclose(res.aic, test_aic, atol=0.1, rtol=0.1) assert np.isclose(res.bic, test_bic, atol=0.1, rtol=0.1) assert np.isclose(res.deviance, test_deviance, atol=0.1, rtol=0.1)
def test_object_has_right_attributes(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) assert hasattr(res, "p_opt") assert hasattr(res, "result") assert hasattr(res, "deviance") assert hasattr(res, "aic") assert hasattr(res, "bic") assert hasattr(res, "model") assert isinstance(res.model, models.Const1D)
def test_compute_criteria_works_correctly(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) test_aic = res.result + 2.0 * res.p_opt.shape[0] test_bic = res.result + res.p_opt.shape[0] * \ np.log(self.lpost.x.shape[0]) test_deviance = -2 * self.lpost.loglikelihood(res.p_opt, neg=False) assert np.isclose(res.aic, test_aic, atol=0.1, rtol=0.1) assert np.isclose(res.bic, test_bic, atol=0.1, rtol=0.1) assert np.isclose(res.deviance, test_deviance, atol=0.1, rtol=0.1)
def test_object_initializes_correctly(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) assert hasattr(res, "p_opt") assert hasattr(res, "result") assert hasattr(res, "deviance") assert hasattr(res, "aic") assert hasattr(res, "bic") assert hasattr(res, "model") assert isinstance(res.model, models.Const1D) assert res.p_opt == self.opt.x, "res.p_opt must be the same as opt.x!" assert np.isclose(res.p_opt[0], 2.0, atol=0.1, rtol=0.1) assert res.model == self.lpost.model assert res.result == self.opt.fun mean_model = np.ones_like(self.lpost.x) * self.opt.x[0] assert np.allclose(res.mfit, mean_model), "res.model should be exactly " \ "the model for the data."
def test_merit_calculated_correctly(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) test_merit = np.sum(((self.ps.power - 2.0)/2.0)**2.) assert np.isclose(res.merit, test_merit, rtol=0.2)
def test_merit_calculated_correctly(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) test_merit = 98770.654981073574 assert np.isclose(res.merit, test_merit, atol=0.1, rtol=0.1)
def test_compute_model_works_correctly(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) mean_model = np.ones_like(self.lpost.x) * self.opt.x[0] assert np.all( res.mfit == mean_model), "res.model should be exactly " \ "the model for the data."
def test_result_is_same_as_in_opt(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) assert res.result == self.opt.fun
def test_model_is_same_as_in_lpost(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) assert res.model == self.lpost.model
def test_p_opt_is_correct(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg) assert res.p_opt == self.opt.x, "res.p_opt must be the same as opt.x!" assert np.isclose(res.p_opt[0], 2.0, atol=0.1, rtol=0.1)
def test_object_initializes(self): res = OptimizationResults(self.lpost, self.opt, neg=self.neg)