I have to compute the covariance of 50 very large integer matrices (2500x2000 elements). However, according to my estimation this will take around 10 days. Do you have any ideas how to speed things up?
1 Answer
$\begingroup$
$\endgroup$
2
If the matrix contains exact integers, Mathematica will compute an exact result (in terms of exact rational numbers). This is very slow.
If you convert your matrix to (inexact) machine precision numbers, the calculation will be much much faster.
Use Covariance@N[matrix]
instead of Covariance[matrix]
.
-
$\begingroup$ Thanks, I will try it tomorrow and let you know (I don't have Mathematica on this computer). $\endgroup$ Commented Nov 14, 2013 at 22:14
-
$\begingroup$ This definitely works. Thanks a lot. $\endgroup$ Commented Nov 15, 2013 at 21:12
Covariance[RandomReal[1, {5000, 5000}]]; // AbsoluteTiming
What type of elements do you have? $\endgroup$N[matrix]
instead ofmatrix
. $\endgroup$N
on them. Otherwise Mathematica will attempt to calculate an exact solution, which is very slow and likely not what you need. $\endgroup$