def test_template_init_state_with_empty_bins(self): self.df = pd.DataFrame({ "x": np.array([0.5, 0.2, 0.4, 2.4, 2.7, 2.8]), "weight": np.array([2, 2, 1, 2, 2, 2]) }) self.x_hist = scipy.stats.binned_statistic(self.df.x, self.df.weight, "sum", bins=self.num_bins, range=self.limits)[0] self.x_errors = np.sqrt( scipy.stats.binned_statistic(self.df.x, self.df.weight.values**2, "sum", bins=self.num_bins, range=self.limits)[0]) expected_rel_errors = np.divide(self.x_errors, self.x_hist, out=np.full(self.num_bins, 1e-7), where=self.x_hist != 0) template = Template("test", self.var, self.num_bins, self.limits, self.df) np.testing.assert_equal(template.yield_param.value, np.sum(self.df.weight)) np.testing.assert_equal(template.yield_param.error, np.sqrt(np.sum(self.df.weight.values**2))) np.testing.assert_array_equal(template.nui_params.value, np.zeros(self.num_bins)) np.testing.assert_array_equal(template.nui_params.error, np.ones(self.num_bins)) np.testing.assert_array_equal(template.values(), self.x_hist) np.testing.assert_array_equal(template._relative_errors, expected_rel_errors) np.testing.assert_array_equal(template.errors(), expected_rel_errors * self.x_hist)
def test_template_init_state(self): template = Template("test", self.var, self.num_bins, self.limits, self.df) np.testing.assert_equal(template.yield_param.value, np.sum(self.df.weight)) np.testing.assert_equal(template.yield_param.error, np.sqrt(np.sum(self.df.weight.values**2))) np.testing.assert_array_equal(template.nui_params.value, np.zeros(self.num_bins)) np.testing.assert_array_equal(template.nui_params.error, np.ones(self.num_bins)) np.testing.assert_array_equal(template.values(), self.x_hist) np.testing.assert_array_equal(template._relative_errors, self.x_errors / self.x_hist) np.testing.assert_array_equal(template.errors(), self.x_errors) np.testing.assert_array_almost_equal(template._cov, np.diag(self.x_errors**2)) np.testing.assert_array_equal(template._corr, np.diag(np.ones(self.num_bins))) np.testing.assert_array_equal(template._inv_corr, np.diag(np.ones(self.num_bins)))