Note that there are some explanatory texts on larger screens.

plurals
  1. POC++ eigenvalue/vector decomposition, only need first n vectors fast
    text
    copied!<p>I have a ~3000x3000 covariance-alike matrix on which I compute the eigenvalue-eigenvector decomposition (it's a OpenCV matrix, and I use <code>cv::eigen()</code> to get the job done).</p> <p>However, I actually only need the, say, first 30 eigenvalues/vectors, I don't care about the rest. Theoretically, this should allow to speed up the computation significantly, right? I mean, that means it has 2970 eigenvectors less that need to be computed.</p> <p>Which C++ library will allow me to do that? Please note that OpenCV's <code>eigen()</code> method does have the parameters for that, but the documentation says they are ignored, and I tested it myself, they are indeed ignored :D</p> <p><em><strong>UPDATE:</em></strong> I managed to do it with ARPACK. I managed to compile it for windows, and even to use it. The results look promising, an illustration can be seen in this toy example:</p> <pre><code>#include "ardsmat.h" #include "ardssym.h" int n = 3; // Dimension of the problem. double* EigVal = NULL; // Eigenvalues. double* EigVec = NULL; // Eigenvectors stored sequentially. int lowerHalfElementCount = (n*n+n) / 2; //whole matrix: /* 2 3 8 3 9 -7 8 -7 19 */ double* lower = new double[lowerHalfElementCount]; //lower half of the matrix //to be filled with COLUMN major (i.e. one column after the other, always starting from the diagonal element) lower[0] = 2; lower[1] = 3; lower[2] = 8; lower[3] = 9; lower[4] = -7; lower[5] = 19; //params: dimensions (i.e. width/height), array with values of the lower or upper half (sequentially, row major), 'L' or 'U' for upper or lower ARdsSymMatrix&lt;double&gt; mat(n, lower, 'L'); // Defining the eigenvalue problem. int noOfEigVecValues = 2; //int maxIterations = 50000000; //ARluSymStdEig&lt;double&gt; dprob(noOfEigVecValues, mat, "LM", 0, 0.5, maxIterations); ARluSymStdEig&lt;double&gt; dprob(noOfEigVecValues, mat); // Finding eigenvalues and eigenvectors. int converged = dprob.EigenValVectors(EigVec, EigVal); for (int eigValIdx = 0; eigValIdx &lt; noOfEigVecValues; eigValIdx++) { std::cout &lt;&lt; "Eigenvalue: " &lt;&lt; EigVal[eigValIdx] &lt;&lt; "\nEigenvector: "; for (int i = 0; i &lt; n; i++) { int idx = n*eigValIdx+i; std::cout &lt;&lt; EigVec[idx] &lt;&lt; " "; } std::cout &lt;&lt; std::endl; } </code></pre> <p>The results are:</p> <pre><code>9.4298, 24.24059 </code></pre> <p>for the eigenvalues, and</p> <pre><code>-0.523207, -0.83446237, -0.17299346 0.273269, -0.356554, 0.893416 </code></pre> <p>for the 2 eigenvectors respectively (one eigenvector per row) The code fails to find 3 eigenvectors (it can only find 1-2 in this case, an assert() makes sure of that, but well, that's not a problem).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload