OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 09 Feb 2013 07:22:24 -0600Get k largest singular values from SVDhttp://answers.opencv.org/question/6957/get-k-largest-singular-values-from-svd/Hi all, I'm using OpenCV to implement a PLS algorithm, and I need to run SVD in a big matrix.
But I don't want all the singular values, just the largest one.
In matlab I can do this by calling:
[u,s,v] = svds(A, 1);
In OpenCV I'm doing:
cv::SVD::compute(A, s, u, v);
Anyone has any idea?
thxTue, 05 Feb 2013 15:46:53 -0600http://answers.opencv.org/question/6957/get-k-largest-singular-values-from-svd/Answer by monstropizza for <p>Hi all, I'm using OpenCV to implement a PLS algorithm, and I need to run SVD in a big matrix.
But I don't want all the singular values, just the largest one.</p>
<p>In matlab I can do this by calling:</p>
<pre><code>[u,s,v] = svds(A, 1);
</code></pre>
<p>In OpenCV I'm doing:</p>
<pre><code>cv::SVD::compute(A, s, u, v);
</code></pre>
<p>Anyone has any idea?</p>
<p>thx</p>
http://answers.opencv.org/question/6957/get-k-largest-singular-values-from-svd/?answer=7155#post-id-7155For now I'm just getting the first column of each matrix, like:
<pre><code>cv::SVD::compute(A, s, u, v);
u = u.col(0);
v = v.col(0);</code></pre>
With this, I'm getting a mean error of less than 0,0002 in my Wstar matrix (comparing with matlab result).
Anyone has a better idea than this?Fri, 08 Feb 2013 10:20:59 -0600http://answers.opencv.org/question/6957/get-k-largest-singular-values-from-svd/?answer=7155#post-id-7155Comment by Guanta for <p>For now I'm just getting the first column of each matrix, like:</p>
<pre><code>cv::SVD::compute(A, s, u, v);
u = u.col(0);
v = v.col(0);</code></pre>
<p>With this, I'm getting a mean error of less than 0,0002 in my Wstar matrix (comparing with matlab result).</p>
<p>Anyone has a better idea than this?</p>
http://answers.opencv.org/question/6957/get-k-largest-singular-values-from-svd/?comment=7188#post-id-7188You could use the SVD flags SVD::MODIFY_A (if you don't need A anymore) and/ or the flag SVD::NO_UV if you only need the singular values. Both flags will speed up your computation process, i.e. cv::SVD::compute(A, s, u, v, cv::SVD::MODIFY_A | cv::SVD::NO_UV);Sat, 09 Feb 2013 07:22:24 -0600http://answers.opencv.org/question/6957/get-k-largest-singular-values-from-svd/?comment=7188#post-id-7188