Variance of complex numbers
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)
-
reporter -
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.
-
repo owner - changed status to resolved
Fixes issue 595.
→ <<cset 22d3794929e4>>
-
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.
-
repo owner -
assigned issue to
- changed milestone to 0.12
-
assigned issue to
-
repo owner - changed status to closed
- Log in to comment
I am just going to have it reject complex arguments.