def test_bootstrap_lsqfit(self): fitter = MultiFitter(models=self.make_models(ncg=1)) fit = fitter.lsqfit(data=self.data, prior=self.prior) datalist = gv.bootstrap_iter(self.data, n=10) ds = gv.dataset.Dataset() for bf in fit.bootstrapped_fit_iter(datalist=datalist): ds.append(bf.pmean) p = gv.dataset.avg_data(ds, bstrap=True) self.assertTrue(abs(p['a'].mean - 1.) < 5 * p['a'].sdev) self.assertTrue(abs(p['b'].mean - 0.5) < 5 * p['b'].sdev) self.assertEqual(ds.samplesize, 10) pdatalist = (fitter.process_data(d, fitter.models) for d in gv.bootstrap_iter(self.data, n=10)) ds = gv.dataset.Dataset() for bf in fit.bootstrapped_fit_iter(pdatalist=pdatalist): ds.append(bf.pmean) p = gv.dataset.avg_data(ds, bstrap=True) self.assertTrue(abs(p['a'].mean - 1.) < 5 * p['a'].sdev) self.assertTrue(abs(p['b'].mean - 0.5) < 5 * p['b'].sdev) self.assertEqual(ds.samplesize, 10) ds = gv.dataset.Dataset() for bf in fit.bootstrapped_fit_iter(n=10): ds.append(bf.pmean) p = gv.dataset.avg_data(ds, bstrap=True) self.assertTrue(abs(p['a'].mean - 1.) < 5 * p['a'].sdev) self.assertTrue(abs(p['b'].mean - 0.5) < 5 * p['b'].sdev) self.assertEqual(ds.samplesize, 10)
def test_process_data(self): data = gv.BufferDict() data['l'] = ['1.0(3)', '2.0(4)', '3.0(3)', '4.0(4)'] data['c1'] = ['1.0(3)', '2.0(4)', '3.0(3)', '4.0(4)'] data['c2'] = ['1.0(3)', '2.0(4)', '3.0(3)', '4.0(4)'] data['dummy'] = ['10(10)'] data = gv.gvar(data) models = self.make_models(ncg=1) pdata = MultiFitter.process_data(data, models) self.assertTrue('dummy' not in pdata) for tag in pdata: self.assertEqual(str(pdata[tag]), str(data[tag])) models = self.make_models(ncg=2) pdata = MultiFitter.process_data(data, models) self.assertTrue('dummy' not in pdata) for tag in pdata: cgdata = np.sum([data[tag][:2], data[tag][2:]], axis=1) / 2. self.assertEqual(str(pdata[tag]), str(cgdata))
def test_lsqfit_pdata_coarse_grain(self): " MultiFitter.lsqfit(pdata=..., ..., ncg=2) " fitter = MultiFitter(models=self.make_models(ncg=2)) pdata = MultiFitter.process_data(data=self.data, models=fitter.models) fit3 = fitter.lsqfit(pdata=pdata, prior=self.prior) self.assertTrue(self.agree_ref(fit3.p))
def test_lsqfit_pdata_coarse_grain(self): " MultiFitter.lsqfit(pdata=..., ..., ncg=2) " fitter = MultiFitter(models=self.make_models(ncg=2)) pdata = MultiFitter.process_data(data=self.data, models=fitter.models) fit3 = fitter.lsqfit(pdata=pdata, prior=self.prior) self.assertEqual(str(fit3.p), "{'a': 0.99937(46),'b': 0.49994(78)}")