1
$\begingroup$

From the python uncertainties package:

Correlations between expressions are correctly taken into account. Thus, x-x is exactly zero, for instance (most implementations found on the web yield a non-zero uncertainty for x-x, which is incorrect).

x is a single value, with an uncertainty. What does correlation mean in this context?

Example code to illustrate what it's talking about:

In [1]: from uncertainties import ufloat, umath

In [2]: x = ufloat(2,1)

In [3]: x
Out[3]: 2.0+/-1.0

In [4]: y = ufloat(2,1)

In [5]: y
Out[5]: 2.0+/-1.0

In [6]: z = umath.log(umath.exp(x))

In [7]: z
Out[7]: 2.0+/-1.0

In [8]: x-y
Out[8]: 0.0+/-1.4142135623730951

In [9]: x-z
Out[9]: 0.0+/-0

In this example, x, y, and z are all single values with an uncertainty. I don't understand how two single values can be "correlated".

In a practical sense, I'd also be interested to know how uncertainties actually keeps track of this "correlation".

Further, why doesn't this include some of the uncorrelated error between x and z?

In [10]: b=x+y

In [11]: c=y+z

In [12]: b-c
Out[12]: 0.0+/-0
$\endgroup$
2
$\begingroup$

$x$ is perfectly correlated with itself, so $x-x$ is $0$, with no uncertainty. The example given in the documentation is not really a very good one, since this isn't a common situation and the result is trivial. More importantly, if $x$ and $y$ are correlated, than the documentation is claiming that the code will take this correlation into account when computing an uncertainty for $x-y$.

The OP edited his question, so I've edited this response to try to answer the new question:

In this code, $x$, $y$, and $z$ are random variables with given expected values, standard deviations, and correlations. In your example, $x$ is a random variable with expected value 2.0 and standard deviation 1.0. $z$ is also a random variable with expected value 2.0 and standard deviation 1.0. Furthermore, by keeping track of the operations that connected $x$ to $z$, the code knows that the correlation between $x$ and $z$ is 1. Thus $x-z$ is a random variable with expected value 0 and standard deviation 0.

Meanwhile $y$ is an independent random variable with expected value 2.0 and standard deviation $1$. $x-y$ is then a random variable with expected value 0.0 and standard deviation 1.414...

The software is propagating variances using the basic formulas that

$E[aX+bY]=aE[X]+bE[Y]$.

and

$\mbox{Var}(aX+bY)=a^2\mbox{Var}(X)+b^{2}\mbox{Var}(Y)+2ab\mbox{Cov}(X,Y)$

The package is presumably capable of using simple Taylor series expansions to compute means and variances for expressions involving more complicated functions (It may have handled the log(exp(x)) by Taylor series expansion or it may have simplified log(exp(x)) to x directly- I'm not familiar with the innards of the package.)

| cite | improve this answer | |
$\endgroup$
  • $\begingroup$ I understand what the code is doing, I'm just not clear why. $\endgroup$ – naught101 Feb 26 '15 at 2:53
  • $\begingroup$ Which of the answers in Out[7], Out[8], Out[9], and out[12] do you think is incorrect, and what part of the answer (the expected value or the standard deviation or perhaps both) do you feel is wrong? $\endgroup$ – Brian Borchers Feb 26 '15 at 3:21
  • $\begingroup$ Or, if you're willing to accept that these outputs are correct, which output would you like to have explained in more detail? $\endgroup$ – Brian Borchers Feb 26 '15 at 3:52
  • $\begingroup$ Thanks for the added details. Given your answer, I understand the $x-y$ having a standard deviation of 0 (mistake in your answer there), and $x-z$ having a std dev of $\sqrt{2}$, but I would expect $b-c$ to have a non-zero variance, because it is effectively two partially correlated variables - $(x+y) - (y+z)$ where $x$ and $y$ are correlated. Is that different to $(x+y-y)-z = x-z$ (std.dev=1.414...)? $\endgroup$ – naught101 Feb 26 '15 at 4:08
  • $\begingroup$ Both the output quoted in your edited question and my answer above say that $x-z$ is a constant (standard deviation 0) and that $x-y$ is a random variable with standard deviation 1.414... Your most recent comment disagrees with this, so I can't make sense of what's you've written. $\endgroup$ – Brian Borchers Feb 26 '15 at 4:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.