Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent filling of values on bin edges [BUG] #752

Open
Dominic-Stafford opened this issue Jun 16, 2022 · 1 comment
Open

Inconsistent filling of values on bin edges [BUG] #752

Dominic-Stafford opened this issue Jun 16, 2022 · 1 comment

Comments

@Dominic-Stafford
Copy link

When creating a Regular axis with an integer step size, integers that fall on the bin edges aren't consistently assigned to the same side of the bin edges:

>>> hist=bh.Histogram(bh.axis.Regular(100, 0, 200))
>>> hist.fill([56, 58, 60])
Histogram(Regular(100, 0, 200), storage=Double()) # Sum: 3.0
>>> hist.values()    
array([0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 2., 0., 1., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
       0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.])

I guess this is due to some sort of numerical precision issue, and one can see a similar behaviour with the edges, though this is clearly not exactly the same as from these one would expect neither of 56 or 58 to fall in the 28th bin, when in fact both do:

>>> bh.axis.Regular(100, 0, 200).edges[28]
56.00000000000001
>>> bh.axis.Regular(100, 0, 200).edges[29]
57.99999999999999

If it's difficult to fix this issue for regular axes, would it be possible to have a step option on integer axes? I observed the same problem for bh.axis.Regular(100, 0, 100), but there one can just use bh.axis.Integer(0, 100) instead, which doesn't have this problem

@henryiii
Copy link
Member

This is discussed in boostorg/histogram somewhere, such as boostorg/histogram#336. It's really an issue there, rather than here. The algorithm for computing edges has different numerical precision issues than the one for computing the fill, which is why they can be off. The Regular axis is optimized for performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants