Adding epsilon after normalizing wrt total weight
@@ -127,10 +127,6 @@ class Histo:
histo, _ = np.histogramdd(x, bins=self.edges, range=ranges, normed=False, weights=weights)
histo_w2, _ = np.histogramdd(x, bins=self.edges, range=ranges, normed=False, weights=weights ** 2)
- # Avoid empty bins
- histo[:] += epsilon
- histo_w2[:] += epsilon ** 2
-
# Uncertainties
histo_uncertainties = histo_w2 ** 0.5
@@ -138,6 +134,12 @@ class Histo:
histo_uncertainties /= np.sum(histo)
histo /= np.sum(histo)
+ # Avoid empty bins, and normalize again
+ histo[:] += epsilon
+ histo_uncertainties[:] += epsilon
+ histo_uncertainties /= np.sum(histo)
+ histo /= np.sum(histo)
+
# Calculate cell volumes
# Fix edges for bvolume calculation (to avoid larger volumes for more training data)
modified_histo_edges = []
