Search code examples
pythonuncertainty

Python: Uncertainties' ufloat functionality


I am using behalf of python 2.7 the module uncertainties. Who did ever type the following lines of code:

import uncertainties
counts = uncertainties.ufloat(1,1)
auto_correlator = (counts - counts) / (2 * counts)
print auto_correlator
#0.0+/-0

Do you wonder about the uncertainty of the result? I expect a finite error: 0.0+/-0.5 according to my understanding of statistics. The formula of error propagation that I used is the following:

Error Propagation Formula

I do not like to do it each time by hand. How can I propagate the error efficiently and reliable or is my intuition wrong?


Solution

  • I think the result is fine. It doesn't matter how much counts is uncertain, counts - counts will always be exactly 0, because it is the same variable that is substracted from itself, we don't care about it's "real" value.

    As @elric said in their comment, if you want the same "value" (i.e. same nominal value and same uncertainty), use different variables.

    counts1 = uncertainties.ufloat(1,1)
    counts2 = uncertainties.ufloat(1,1)
    auto_correlator = (counts1 - counts2) / (counts1 + counts2)
    print auto_correlator