-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make var and std work for Vector{Vector{T}} #23897
Conversation
…ction from some signatures as well as using broadcasting in std. Fixes #23884
Does this not go in the opposite direction to the strategy of not auto-vectorizing functions? Why not just use: |
It is not the same thing. julia> x = [[2,4,6],[4,6,8]];
julia> var(x)
3-element Array{Float64,1}:
2.0
2.0
2.0
julia> var.(x)
2-element Array{Float64,1}:
4.0
4.0 You can compute the variance of a vector. In Julia, we have decided that it is just the diagonal of the covariance matrix. The standard deviation is a bit tricky, though. It could either be the diagonal of the matrix square root of the covariance matrix or the element wise square root of the diagonal of the covariance matrix. This PR uses the latter definition. |
@DNF2 The empirical covariance is a function which maps a collection of equal-length vectors to a matrix (this involves the outer product |
Hm. In #23884 I guess I misread the answer to
probably because the example vectors were so similar. I thought the request was to auto-broadcast. Thanks for the explanation. |
Cases like this could be caught in the signature, right? E.g.
but maybe it is better to fix that at the root. |
9bdbd57
to
ebda0b2
Compare
@andreasnoack We do have an issue for it: #18379 |
I have to admit, I find this a bit surprising. I'm trying to put my finger on it - but I think that it has something to do with the fact the the properties of If you were to ask me what I thought the "variance" of a set of vectors was, I would answer the covariance or it's determinant or the RMS L2 distance from the mean, not some element wise calculation. The covariance works generically with number as |
Returning the "diagonal of the covariance matrix" is basically component-wise application of the var function. So that is a case of automatic broadcasting which is not easily expressed in dot operations for |
I'd also prefer the covariance matrix but we have kind of already made the decision since julia> X = randn(10,2);
julia> var(X, 1)
1×2 Array{Float64,2}:
0.69424 0.894716 whereas julia> cov(X, 1)
2×2 Array{Float64,2}:
0.69424 -0.0762704
-0.0762704 0.894716 |
This seems like a job for a zip-like iterator. |
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
I just discovered this — it seems quite strange to me. How are we defining |
Ok, after discussing this more with Andreas, I'm on board with the behaviors here… but we might want to look into updating the docstring… and possibly moving away from broadcasting. Basically, Moreover, this is an operation that is good to support because we implicitly do it with Using broadcasting here still tastes a little funny to me, because it is effectively imposing |
by removing Number restriction from some signatures as well as using broadcasting in
std
.I'd also like to do something similar for
cov
but hit the issue thatbroadcast
is not doing the right thing forVector{Vector{T}}
. E.g.Do we have an issue for that?
Fixes #23884