def test_parameter_estimation_resampling(self):
     X = RNG.uniform(0, 4, 1000)
     y = X + RNG.normal(0, 1, 1000)
     m = BayesianBootstrapBagging(LinearRegression(),
                                  10000,
                                  1000,
                                  low_mem=False)
     m.fit(X.reshape(-1, 1), y)
     coef_samples = [b.coef_ for b in m.base_models_]
     intercept_samples = [b.intercept_ for b in m.base_models_]
     self.assertAlmostEqual(np.mean(coef_samples), 1, delta=0.3)
     l, r = central_credible_interval(coef_samples, alpha=0.05)
     self.assertLess(l, 1)
     self.assertGreater(r, 1)
     l, r = highest_density_interval(coef_samples, alpha=0.05)
     self.assertLess(l, 1)
     self.assertGreater(r, 1)
     self.assertAlmostEqual(np.mean(intercept_samples), 0, delta=0.3)
     l, r = central_credible_interval(intercept_samples, alpha=0.05)
     self.assertLess(l, 0)
     self.assertGreater(r, 0)
     self.assertAlmostEqual(np.mean(intercept_samples), 0, delta=0.3)
     l, r = highest_density_interval(intercept_samples, alpha=0.05)
     self.assertLess(l, 0)
     self.assertGreater(r, 0)
 def test_central_credible_interval(self):
     l, r = central_credible_interval(self._shuffle(range(10)), alpha=0.2)
     self.assertEqual(l, 0.9)
     self.assertEqual(r, 8.1)
     l, r = central_credible_interval(self._shuffle(range(10)), alpha=0.19)
     self.assertEqual(l, 0.855)
     self.assertEqual(r, 8.145)
     l, r = central_credible_interval(self._shuffle(range(20)), alpha=0.1)
     self.assertAlmostEqual(l, 0.95)
     self.assertEqual(r, 18.05)