Bug #2765
cscripts.obutils.residuals may have a floating-point math glitch
Status: | Closed | Start date: | 11/29/2018 | |
---|---|---|---|---|
Priority: | Low | Due date: | ||
Assigned To: | Knödlseder Jürgen | % Done: | 100% | |
Category: | - | |||
Target version: | 1.7.0 | |||
Duration: |
Description
I’ve been looking at the statistics of csresmap when using algorithm='SIGNIFICANCE’ (calculated here), and I ran into something odd when recreating the calculation in my python script.
The situation is: you’re calculating the significance of a bin that has 7 observed counts, and 6.9999999999999... modeled counts (7-<a really small number>).
$ python >>> d = 7 >>> m = d - 1e-14 >>> print(sqrt(d*log(d/m) + m - d)) Traceback (most recent call last): File "<stdin>", line 1, in <module> ValueError: math domain error >>> d*log(d/m) + m - d -8.881784197001252e-16
When calculating the significance (done here in csresmap), the value of
d*log(d/m) + m - dbecomes negative, and then the sqrt() throws an exception, ruining your wednesday night statistical experiments. I think its due to how python handles long floating point numbers, but I’m not sure.
Just to emphasize, I haven’t actually seen this happen yet in csresmap since I don’t have enough time to test it out. But I did see this when doing the same calculation with some MC statistical sims in a standalone python script, so I’m marking this as low priority, but it may be worth checking out.
Recurrence
No recurrence.
History
#1 Updated by Kelley-Hoskins Nathan about 6 years ago
*The next thing that’s done with that negative number is square-rooted, which is where the sqrt() comes in.
#2 Updated by Knödlseder Jürgen over 4 years ago
- Status changed from New to Pull request
- Assigned To set to Knödlseder Jürgen
- Target version set to 1.7.0
- % Done changed from 0 to 100
Thanks for pointing this out. This looks indeed like a numerical glitch. I force now negative residual values in obsutils.residual() to zero so that no square root error will occur.
#3 Updated by Knödlseder Jürgen over 4 years ago
- Status changed from Pull request to Closed
Merged into devel
.