You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm not sure if I'm understanding the behavior of cov correctly, but it seems like the current implementation for between two vectors only works on a vector of numbers. It currently gives the dot product between the vectors, which is only equivalent to what the documentation says when the vectors only contain scalars (since it's doing an inner product). At some point before bringing it over from StatsBase.jl, this probably worked according to this comment, but right now it doesn't give the behavior I expect. For example,
julia> N =1000;
julia> A = [randn(5) for _ in1:N];
julia> B = [randn(5) for _ in1:N];
julia>using Statistics
julia>cov(A,B) # This is unexpected0.15626480407767923
julia>sum((a-mean(A))*(b-mean(B))'for (a,b) inzip(A,B))/(N-1) # This is expected5×5 Matrix{Float64}:9.35299e-16-5.73004e-16-4.02748e-169.26408e-16-3.28066e-16-7.09476e-161.65189e-152.7001e-15-9.89532e-16-2.72944e-162.08931e-163.56516e-167.28591e-169.61526e-16-1.33894e-153.51182e-16-1.68034e-16-1.23136e-16-2.57385e-169.51302e-16-1.97373e-165.99676e-162.97838e-16-1.7159e-16-1.01532e-15
I'm not saying the above is the best possible implementation, just that it gives the answer I expect. I would propose (and be willing to put up a PR for!) a change where the current implementation of unscaled_covzm is specialized to AbstractVector{<:Number} and there's a different general implementation of it for AbstractVector, similar to what I put up above.
The text was updated successfully, but these errors were encountered:
I'm not sure if I'm understanding the behavior of
cov
correctly, but it seems like the current implementation for between two vectors only works on a vector of numbers. It currently gives the dot product between the vectors, which is only equivalent to what the documentation says when the vectors only contain scalars (since it's doing an inner product). At some point before bringing it over from StatsBase.jl, this probably worked according to this comment, but right now it doesn't give the behavior I expect. For example,I'm not saying the above is the best possible implementation, just that it gives the answer I expect. I would propose (and be willing to put up a PR for!) a change where the current implementation of
unscaled_covzm
is specialized toAbstractVector{<:Number}
and there's a different general implementation of it forAbstractVector
, similar to what I put up above.The text was updated successfully, but these errors were encountered: