Skip to content
Snippets Groups Projects
Commit cebf5f26 authored by Nikolai's avatar Nikolai
Browse files

switch to np.digitize for histogram error calculation

parent 9b68e0b4
No related branches found
No related tags found
No related merge requests found
......@@ -828,13 +828,19 @@ class ClassificationProject(object):
hist, bins = np.histogram(x, **np_kwargs)
centers = (bins[:-1] + bins[1:]) / 2
if "weights" in np_kwargs:
errors = []
for left, right in zip(bins, bins[1:]):
indices = np.where((x >= left) & (x < right))[0]
sumw2 = np.sum(np_kwargs["weights"][indices]**2)
content = np.sum(np_kwargs["weights"][indices])
errors.append(math.sqrt(sumw2)/content)
errors = np.array(errors)
bin_indices = np.digitize(x, bins)
sumw2 = np.array([np.sum(np_kwargs["weights"][bin_indices==i]**2)
for i in range(1, len(bins)+1)])
sumw = np.array([np.sum(np_kwargs["weights"][bin_indices==i])
for i in range(1, len(bins)+1)])
# move overflow to last bin
# (since thats what np.histogram gives us)
sumw2[-2] += sumw2[-1]
sumw2 = sumw2[:-1]
sumw[-2] += sumw[-1]
sumw = sumw[:-1]
# calculate relative error
errors = np.sqrt(sumw2)/sumw
else:
errors = np.sqrt(hist)/hist
if scale_factor is not None:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment