Variance of complex numbers

Issue #595 closed
Pol Welter created an issue

The current implementation of variance allows complex numbers as input. This is sort of misleading. In fact, a complex number is really a 2-vector, so actually variance(z1; z2) should give us the corresponding covariance matrix. Since we don't support matrices, this is not an option.

I suggest we either drop support for complex numbers by variance(), or take the Numpy approach:

Note that for complex numbers, the absolute value is taken before squaring, so that the result is always real and nonnegative.

I don't like the latter solution all that much. Thoughts? @thadrien ?

Since we are already taking about variances; is it a good solution to only offer the function more properly known as population variance, but not the sample variance? See wikipedia.

Comments (6)

  1. Hadrien Theveneau

    I would define the variance as the mean of the square of the differences between the values and the mean. The shortcuts used for real calculation of the variance doesn't work for complex numbers. However, I think the mere definition of the variance can give sensible results.

    I agree that the real variance should be a matrix, but a simplified scalar variance is usefull for a lot of purposes.

    Your solution to have it reject complex arguments is a suitable short-term solution. Personnally, I can't give too much time in this because I never do statistics. But adding a complex variance is a point on the global todo list.

  2. Pol Welter reporter
    • changed status to open

    Hadrien, you are absolutely right of course. It's a bit embarrassing that the possibility of a scalar variance never crossed my mind. Should be easy to fix. Will reopen the issue.

  3. Log in to comment