OpenCV Q&A Forum - RSS feedhttp://answers.opencv.org/questions/OpenCV answersenCopyright <a href="http://www.opencv.org">OpenCV foundation</a>, 2012-2018.Sat, 29 Feb 2020 15:08:10 -0600Mismatch of the Eigen Vector & Valuehttp://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/Hello,
I need to retrieve the eigen vector from a matrix. The problem is I don't match the result same as my matlab code.
I have a matrix symmetric 100x100 and trying to obtain eigen value and eigen vector from it. I work with double matrix (CV_64F) to have the best precision as possible (Already tried Float and it fail more).
My eigen value seems good but the vector loses some accuracy for each value ( Ex : value 1 to 25 exactly match with matlab but further you get to 100 , more I am losing precision, but I can work with that.)
But the problem is more with the eigen vector.
The result is same as eigen value, lose precision but the problem is with the sign.
If I take the firsts 25x25 results. I'm totally matching with matlab but randomly have positive or negative value. So I got wrong information at the end.
Right now I'm using cv:eigen function like this :
> cv::eigen(oResultMax,oMatValue,oMatVector);
I have already tried the SelfAdjointSolver from the library Eigen.
[Eigen](http://eigen.tuxfamily.org/index.php?title=Main_Page)
[SelfAdjointSolver](http://eigen.tuxfamily.org/dox/classEigen_1_1SelfAdjointEigenSolver.html)
Anyone have an idea ? Or suggest me something ?
EDIT : (Add image of result)
Here you can see the image of the eigen value. If you refere to the MatLab result, the double result are almost same till the 27th and for the float till 14th.
![image description](/upfiles/13660503247970353.png)
And those Image, you have Eigen Vector in order : MatLab , OpenCV Double and OpenCV Float.
As you can see double matching until 35th and float until 15th.
And the sign of the result are differente from Matlab, Double and Float
![image description](/upfiles/13660505732191637.png)
![image description](/upfiles/13660505816901852.png)
![image description](/upfiles/13660505887633373.png)
Fri, 05 Apr 2013 13:33:00 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/Comment by Alexandre Bizeau for <p>Hello,</p>
<p>I need to retrieve the eigen vector from a matrix. The problem is I don't match the result same as my matlab code.</p>
<p>I have a matrix symmetric 100x100 and trying to obtain eigen value and eigen vector from it. I work with double matrix (CV_64F) to have the best precision as possible (Already tried Float and it fail more).</p>
<p>My eigen value seems good but the vector loses some accuracy for each value ( Ex : value 1 to 25 exactly match with matlab but further you get to 100 , more I am losing precision, but I can work with that.)</p>
<p>But the problem is more with the eigen vector.
The result is same as eigen value, lose precision but the problem is with the sign.
If I take the firsts 25x25 results. I'm totally matching with matlab but randomly have positive or negative value. So I got wrong information at the end.</p>
<p>Right now I'm using cv:eigen function like this :</p>
<blockquote>
<p>cv::eigen(oResultMax,oMatValue,oMatVector);</p>
</blockquote>
<p>I have already tried the SelfAdjointSolver from the library Eigen.
<a href="http://eigen.tuxfamily.org/index.php?title=Main_Page">Eigen</a>
<a href="http://eigen.tuxfamily.org/dox/classEigen_1_1SelfAdjointEigenSolver.html">SelfAdjointSolver</a></p>
<p>Anyone have an idea ? Or suggest me something ?</p>
<p>EDIT : (Add image of result)</p>
<p>Here you can see the image of the eigen value. If you refere to the MatLab result, the double result are almost same till the 27th and for the float till 14th.</p>
<p><img alt="image description" src="/upfiles/13660503247970353.png"></p>
<p>And those Image, you have Eigen Vector in order : MatLab , OpenCV Double and OpenCV Float. </p>
<p>As you can see double matching until 35th and float until 15th.
And the sign of the result are differente from Matlab, Double and Float</p>
<p><img alt="image description" src="/upfiles/13660505732191637.png">
<img alt="image description" src="/upfiles/13660505816901852.png">
<img alt="image description" src="/upfiles/13660505887633373.png"></p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11034#post-id-11034I tried the SVD function and in same time, I tried PCA one (Suggested Eigen reference). My result for SVD are same as Eigen losing accuracy and sign problem. With PCA, the result are really not matching and looks more bad than my float with eigen. Both function were a good idea to try but they are not the answer to my problem. Thanks Philipp.Mon, 08 Apr 2013 10:59:56 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11034#post-id-11034Comment by Alexandre Bizeau for <p>Hello,</p>
<p>I need to retrieve the eigen vector from a matrix. The problem is I don't match the result same as my matlab code.</p>
<p>I have a matrix symmetric 100x100 and trying to obtain eigen value and eigen vector from it. I work with double matrix (CV_64F) to have the best precision as possible (Already tried Float and it fail more).</p>
<p>My eigen value seems good but the vector loses some accuracy for each value ( Ex : value 1 to 25 exactly match with matlab but further you get to 100 , more I am losing precision, but I can work with that.)</p>
<p>But the problem is more with the eigen vector.
The result is same as eigen value, lose precision but the problem is with the sign.
If I take the firsts 25x25 results. I'm totally matching with matlab but randomly have positive or negative value. So I got wrong information at the end.</p>
<p>Right now I'm using cv:eigen function like this :</p>
<blockquote>
<p>cv::eigen(oResultMax,oMatValue,oMatVector);</p>
</blockquote>
<p>I have already tried the SelfAdjointSolver from the library Eigen.
<a href="http://eigen.tuxfamily.org/index.php?title=Main_Page">Eigen</a>
<a href="http://eigen.tuxfamily.org/dox/classEigen_1_1SelfAdjointEigenSolver.html">SelfAdjointSolver</a></p>
<p>Anyone have an idea ? Or suggest me something ?</p>
<p>EDIT : (Add image of result)</p>
<p>Here you can see the image of the eigen value. If you refere to the MatLab result, the double result are almost same till the 27th and for the float till 14th.</p>
<p><img alt="image description" src="/upfiles/13660503247970353.png"></p>
<p>And those Image, you have Eigen Vector in order : MatLab , OpenCV Double and OpenCV Float. </p>
<p>As you can see double matching until 35th and float until 15th.
And the sign of the result are differente from Matlab, Double and Float</p>
<p><img alt="image description" src="/upfiles/13660505732191637.png">
<img alt="image description" src="/upfiles/13660505816901852.png">
<img alt="image description" src="/upfiles/13660505887633373.png"></p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11015#post-id-11015Thanks Philipp, the problem is because I need to get Eigen Vector. I know with eigen values, I can obtain the vector but more processing. But can be an idea to try it. Mon, 08 Apr 2013 08:08:21 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11015#post-id-11015Comment by Philipp Wagner for <p>Hello,</p>
<p>I need to retrieve the eigen vector from a matrix. The problem is I don't match the result same as my matlab code.</p>
<p>I have a matrix symmetric 100x100 and trying to obtain eigen value and eigen vector from it. I work with double matrix (CV_64F) to have the best precision as possible (Already tried Float and it fail more).</p>
<p>My eigen value seems good but the vector loses some accuracy for each value ( Ex : value 1 to 25 exactly match with matlab but further you get to 100 , more I am losing precision, but I can work with that.)</p>
<p>But the problem is more with the eigen vector.
The result is same as eigen value, lose precision but the problem is with the sign.
If I take the firsts 25x25 results. I'm totally matching with matlab but randomly have positive or negative value. So I got wrong information at the end.</p>
<p>Right now I'm using cv:eigen function like this :</p>
<blockquote>
<p>cv::eigen(oResultMax,oMatValue,oMatVector);</p>
</blockquote>
<p>I have already tried the SelfAdjointSolver from the library Eigen.
<a href="http://eigen.tuxfamily.org/index.php?title=Main_Page">Eigen</a>
<a href="http://eigen.tuxfamily.org/dox/classEigen_1_1SelfAdjointEigenSolver.html">SelfAdjointSolver</a></p>
<p>Anyone have an idea ? Or suggest me something ?</p>
<p>EDIT : (Add image of result)</p>
<p>Here you can see the image of the eigen value. If you refere to the MatLab result, the double result are almost same till the 27th and for the float till 14th.</p>
<p><img alt="image description" src="/upfiles/13660503247970353.png"></p>
<p>And those Image, you have Eigen Vector in order : MatLab , OpenCV Double and OpenCV Float. </p>
<p>As you can see double matching until 35th and float until 15th.
And the sign of the result are differente from Matlab, Double and Float</p>
<p><img alt="image description" src="/upfiles/13660505732191637.png">
<img alt="image description" src="/upfiles/13660505816901852.png">
<img alt="image description" src="/upfiles/13660505887633373.png"></p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=10921#post-id-10921Try doing a SVD with [cv::SVD::compute](http://docs.opencv.org/modules/core/doc/operations_on_arrays.html?highlight=svd#svd-compute), because for a symmetric matrix the singular values in W are square roots of eigenvalues.Sat, 06 Apr 2013 15:32:08 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=10921#post-id-10921Answer by StevenPuttemans for <p>Hello,</p>
<p>I need to retrieve the eigen vector from a matrix. The problem is I don't match the result same as my matlab code.</p>
<p>I have a matrix symmetric 100x100 and trying to obtain eigen value and eigen vector from it. I work with double matrix (CV_64F) to have the best precision as possible (Already tried Float and it fail more).</p>
<p>My eigen value seems good but the vector loses some accuracy for each value ( Ex : value 1 to 25 exactly match with matlab but further you get to 100 , more I am losing precision, but I can work with that.)</p>
<p>But the problem is more with the eigen vector.
The result is same as eigen value, lose precision but the problem is with the sign.
If I take the firsts 25x25 results. I'm totally matching with matlab but randomly have positive or negative value. So I got wrong information at the end.</p>
<p>Right now I'm using cv:eigen function like this :</p>
<blockquote>
<p>cv::eigen(oResultMax,oMatValue,oMatVector);</p>
</blockquote>
<p>I have already tried the SelfAdjointSolver from the library Eigen.
<a href="http://eigen.tuxfamily.org/index.php?title=Main_Page">Eigen</a>
<a href="http://eigen.tuxfamily.org/dox/classEigen_1_1SelfAdjointEigenSolver.html">SelfAdjointSolver</a></p>
<p>Anyone have an idea ? Or suggest me something ?</p>
<p>EDIT : (Add image of result)</p>
<p>Here you can see the image of the eigen value. If you refere to the MatLab result, the double result are almost same till the 27th and for the float till 14th.</p>
<p><img alt="image description" src="/upfiles/13660503247970353.png"></p>
<p>And those Image, you have Eigen Vector in order : MatLab , OpenCV Double and OpenCV Float. </p>
<p>As you can see double matching until 35th and float until 15th.
And the sign of the result are differente from Matlab, Double and Float</p>
<p><img alt="image description" src="/upfiles/13660505732191637.png">
<img alt="image description" src="/upfiles/13660505816901852.png">
<img alt="image description" src="/upfiles/13660505887633373.png"></p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?answer=10848#post-id-10848Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.
Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?Fri, 05 Apr 2013 14:03:21 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?answer=10848#post-id-10848Comment by HYPEREGO for <p>Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.</p>
<p>Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=226993#post-id-226993I know that this post is really really old, but... have you figure it out? I'm facing the same problem and unfortunately I've not much time to further investigate. I've a symmetric matrix but still getting different result from Octave especially for the tiny numberSat, 29 Feb 2020 15:08:10 -0600http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=226993#post-id-226993Comment by Alexandre Bizeau for <p>Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.</p>
<p>Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11016#post-id-11016I won't be able to found the Matlab eig function because it's a Built-in function. And I can't be sure the octave one can match. But I will try to work on that. And maybe try the SVD like Philipp said. Thanks.Mon, 08 Apr 2013 08:11:06 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11016#post-id-11016Comment by Alexandre Bizeau for <p>Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.</p>
<p>Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11787#post-id-11787@StevenPuttemans I went to OpenCV code and figured out the implementation has been create for double and float. And using the function JacobiImpl_ in modules\core\src\Lacpack.cpp. So I don't think the problem is that. But maybe @Philipp Wagner is right because the function start with eps = std::numeric_limits<>::epsilon(). But C++ EPS is equal to MatLab. I still working on this. TyTue, 16 Apr 2013 14:31:54 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11787#post-id-11787Comment by StevenPuttemans for <p>Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.</p>
<p>Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11568#post-id-11568Ever heard of the word 'comment'. I did not tell you it would be easy, far from it. I hardly get the math behind eigenvalues myself, but it can be done. Just need patience and dedication. It is the only way people will find the actual difference :)Sat, 13 Apr 2013 16:06:13 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11568#post-id-11568Comment by Alexandre Bizeau for <p>Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.</p>
<p>Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=10852#post-id-10852When I'm using float, I'm facing the same problem, sign problem with the eigen vector and bad precission on the eigen value. But It start losing accuracy at like value 9 instead of 25-30 and at value 100 with double I have a difference of 0.000001 and I have 0.01 with float. And Double - Float - Matlab have different sign result. Double and Float sign not matching either.Fri, 05 Apr 2013 14:18:34 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=10852#post-id-10852Comment by Philipp Wagner for <p>Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.</p>
<p>Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11565#post-id-11565@StevePuttemans I really want to see you going through the implementation details of an eigenvalue solver. Most of the stuff is mathematical magic to me and I don't think I would find the difference in the implementation. I guess looking at the data I feed into a solver should be the very first thing to look at. And I tend rely on the fact, that the algorithms implemented by BLAS (and associated projects) have been used by millions of mathematicans, that would have spotted errors. I don't think the OpenCV project has invented a new solver, but used the BLAS implementations.Sat, 13 Apr 2013 13:25:24 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11565#post-id-11565Comment by Alexandre Bizeau for <p>Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.</p>
<p>Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=10853#post-id-10853And I never tried to used float in Matlab, but if you think it can be a good, I can try it now.
Fri, 05 Apr 2013 14:21:09 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=10853#post-id-10853Comment by StevenPuttemans for <p>Basically a lot of functions of openCV use the CV_32F type. I am guessing since you are pushing CV_64F data, that it gets reduced and thus it looses precision.</p>
<p>Could you see if you perform the eigenvalue and vector approach on float data in matlab, and not double if the results still differ alot?</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=10856#post-id-10856Basically if you really want to know where the problem is, you should compare implementation details. Probably there is something different in the basic implementation.Fri, 05 Apr 2013 14:34:04 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=10856#post-id-10856Answer by Philipp Wagner for <p>Hello,</p>
<p>I need to retrieve the eigen vector from a matrix. The problem is I don't match the result same as my matlab code.</p>
<p>I have a matrix symmetric 100x100 and trying to obtain eigen value and eigen vector from it. I work with double matrix (CV_64F) to have the best precision as possible (Already tried Float and it fail more).</p>
<p>My eigen value seems good but the vector loses some accuracy for each value ( Ex : value 1 to 25 exactly match with matlab but further you get to 100 , more I am losing precision, but I can work with that.)</p>
<p>But the problem is more with the eigen vector.
The result is same as eigen value, lose precision but the problem is with the sign.
If I take the firsts 25x25 results. I'm totally matching with matlab but randomly have positive or negative value. So I got wrong information at the end.</p>
<p>Right now I'm using cv:eigen function like this :</p>
<blockquote>
<p>cv::eigen(oResultMax,oMatValue,oMatVector);</p>
</blockquote>
<p>I have already tried the SelfAdjointSolver from the library Eigen.
<a href="http://eigen.tuxfamily.org/index.php?title=Main_Page">Eigen</a>
<a href="http://eigen.tuxfamily.org/dox/classEigen_1_1SelfAdjointEigenSolver.html">SelfAdjointSolver</a></p>
<p>Anyone have an idea ? Or suggest me something ?</p>
<p>EDIT : (Add image of result)</p>
<p>Here you can see the image of the eigen value. If you refere to the MatLab result, the double result are almost same till the 27th and for the float till 14th.</p>
<p><img alt="image description" src="/upfiles/13660503247970353.png"></p>
<p>And those Image, you have Eigen Vector in order : MatLab , OpenCV Double and OpenCV Float. </p>
<p>As you can see double matching until 35th and float until 15th.
And the sign of the result are differente from Matlab, Double and Float</p>
<p><img alt="image description" src="/upfiles/13660505732191637.png">
<img alt="image description" src="/upfiles/13660505816901852.png">
<img alt="image description" src="/upfiles/13660505887633373.png"></p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?answer=11564#post-id-11564I thought I turn this into an answer instead of using comments, as I want to avoid confusion for people coming here from Google. If you don't provide any sample data, it is hard to say what's going on.
First of all an eigenvector has nothing like a "sign", see that's the whole point of eigenvectors. Multiplying an eigenvector with ``-1`` yields a totally valid eigenvector again. I could throw the math at you, but probably this picture already helps you understanding it (as found on the [Wikipedia page on Eigenvalues and Eigenvectors](http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors)):
* [http://upload.wikimedia.org/wikipedia/commons/3/3c/Mona_Lisa_eigenvector_grid.png](http://upload.wikimedia.org/wikipedia/commons/3/3c/Mona_Lisa_eigenvector_grid.png)
Let's recall the eigenvalue problem as:
<pre>
Av = Bv
</pre>
Now let us multiply a constant ``c`` and we end up having:
<pre>
A(cv) = c(Av) = c(Bv) = B(cv)
</pre>
So ``v`` is an eigenvector and ``cv`` is an eigenvector as well.
The following doesn't apply to your situation, as your matrix is symmetric, I just write it for reference. The solvers implemented in OpenCV solve the eigenvalue problem for *symmetric matrices*. So the given matrix has to be symmetric, else you aren't doing an eigenvalue decomposition and the (same goes for a Singular Value Decomposition). I have used a solver for the general eigenvalue problem for my Fisherfaces implementation in OpenCV, but it isn't exposed to the OpenCV API. You can find a header-only implementation in one of my GitHub repositories:
* [decomposition.hpp](https://github.com/bytefish/opencv/blob/master/lda/include/decomposition.hpp)
Now to the eigenvalue accuracy, you refer to. In case of an ill-conditioned matrix small rounding errors in the computation will lead to large errors in the result. I won't throw the math at you again, but you can read all this up at:
* [http://en.wikipedia.org/wiki/Condition_number](http://en.wikipedia.org/wiki/Condition_number)
The page is explicitly mentioning eigenvalue problems.
Now here is my practical rule of thumb. It's very easy to calculate the condition number with MATLAB or GNU Octave by simply using the ``cond`` function. See if ``rcond`` (reciprocal condition number) yields a number close to your machine eps, your matrix is most likely to be ill-conditioned and solvers are going to calculate you some totally random stuff. You can easily determine your machine eps by typing ``eps`` in GNU Octave; I guess it is similar for Matlab.
Just as a side note, usually for a given matrix ``X`` the ``log10(cond(X))`` gives you the number of decimal places that you *may* lose due to roundoff errors. The IEEE standard for double precision numbers has 16 decimal digits, and let us assume your matrix has a condition number of ``10^12``, then you should expect only 4 digits to be accurate in your result.Sat, 13 Apr 2013 13:02:23 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?answer=11564#post-id-11564Comment by Alexandre Bizeau for <p>I thought I turn this into an answer instead of using comments, as I want to avoid confusion for people coming here from Google. If you don't provide any sample data, it is hard to say what's going on.</p>
<p>First of all an eigenvector has nothing like a "sign", see that's the whole point of eigenvectors. Multiplying an eigenvector with <code>-1</code> yields a totally valid eigenvector again. I could throw the math at you, but probably this picture already helps you understanding it (as found on the <a href="http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors">Wikipedia page on Eigenvalues and Eigenvectors</a>):</p>
<ul>
<li><a href="http://upload.wikimedia.org/wikipedia/commons/3/3c/Mona_Lisa_eigenvector_grid.png"></a><a href="http://upload.wikimedia.org/wikipedia/commons/3/3c/Mona_Lisa_eigenvector_grid.png">http://upload.wikimedia.org/wikipedia/commons/3/3c/Mona_Lisa_eigenvector_grid.png</a></li>
</ul>
<p>Let's recall the eigenvalue problem as:</p>
<pre>Av = Bv
</pre>
<p>Now let us multiply a constant <code>c</code> and we end up having:</p>
<pre>A(cv) = c(Av) = c(Bv) = B(cv)
</pre>
<p>So <code>v</code> is an eigenvector and <code>cv</code> is an eigenvector as well.</p>
<p>The following doesn't apply to your situation, as your matrix is symmetric, I just write it for reference. The solvers implemented in OpenCV solve the eigenvalue problem for <em>symmetric matrices</em>. So the given matrix has to be symmetric, else you aren't doing an eigenvalue decomposition and the (same goes for a Singular Value Decomposition). I have used a solver for the general eigenvalue problem for my Fisherfaces implementation in OpenCV, but it isn't exposed to the OpenCV API. You can find a header-only implementation in one of my GitHub repositories:</p>
<ul>
<li><a href="https://github.com/bytefish/opencv/blob/master/lda/include/decomposition.hpp">decomposition.hpp</a></li>
</ul>
<p>Now to the eigenvalue accuracy, you refer to. In case of an ill-conditioned matrix small rounding errors in the computation will lead to large errors in the result. I won't throw the math at you again, but you can read all this up at:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Condition_number"></a><a href="http://en.wikipedia.org/wiki/Condition_number">http://en.wikipedia.org/wiki/Condition_number</a></li>
</ul>
<p>The page is explicitly mentioning eigenvalue problems. </p>
<p>Now here is my practical rule of thumb. It's very easy to calculate the condition number with MATLAB or GNU Octave by simply using the <code>cond</code> function. See if <code>rcond</code> (reciprocal condition number) yields a number close to your machine eps, your matrix is most likely to be ill-conditioned and solvers are going to calculate you some totally random stuff. You can easily determine your machine eps by typing <code>eps</code> in GNU Octave; I guess it is similar for Matlab.</p>
<p>Just as a side note, usually for a given matrix <code>X</code> the <code>log10(cond(X))</code> gives you the number of decimal places that you <em>may</em> lose due to roundoff errors. The IEEE standard for double precision numbers has 16 decimal digits, and let us assume your matrix has a condition number of <code>10^12</code>, then you should expect only 4 digits to be accurate in your result.</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11758#post-id-11758I tought my accuracy problem were maybe about something like that ( Condition number). I read the article you give me and I try it. So my 100x100 is K. It the one I need to do rcond on it right ? If yes, rcond result is really bad : 6.8180e-020 and my MatLab eps is : 2.2.04e-016, so I'm really near 0.0 then my matrix(K) is really ill-conditioned. So what can I do ? I will continue to read about it because it can be a good point and maybe this is why I have sign problem and same for accuracy. Working on it ! Thanks you.Tue, 16 Apr 2013 09:31:04 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11758#post-id-11758Comment by Alexandre Bizeau for <p>I thought I turn this into an answer instead of using comments, as I want to avoid confusion for people coming here from Google. If you don't provide any sample data, it is hard to say what's going on.</p>
<p>First of all an eigenvector has nothing like a "sign", see that's the whole point of eigenvectors. Multiplying an eigenvector with <code>-1</code> yields a totally valid eigenvector again. I could throw the math at you, but probably this picture already helps you understanding it (as found on the <a href="http://en.wikipedia.org/wiki/Eigenvalues_and_eigenvectors">Wikipedia page on Eigenvalues and Eigenvectors</a>):</p>
<ul>
<li><a href="http://upload.wikimedia.org/wikipedia/commons/3/3c/Mona_Lisa_eigenvector_grid.png"></a><a href="http://upload.wikimedia.org/wikipedia/commons/3/3c/Mona_Lisa_eigenvector_grid.png">http://upload.wikimedia.org/wikipedia/commons/3/3c/Mona_Lisa_eigenvector_grid.png</a></li>
</ul>
<p>Let's recall the eigenvalue problem as:</p>
<pre>Av = Bv
</pre>
<p>Now let us multiply a constant <code>c</code> and we end up having:</p>
<pre>A(cv) = c(Av) = c(Bv) = B(cv)
</pre>
<p>So <code>v</code> is an eigenvector and <code>cv</code> is an eigenvector as well.</p>
<p>The following doesn't apply to your situation, as your matrix is symmetric, I just write it for reference. The solvers implemented in OpenCV solve the eigenvalue problem for <em>symmetric matrices</em>. So the given matrix has to be symmetric, else you aren't doing an eigenvalue decomposition and the (same goes for a Singular Value Decomposition). I have used a solver for the general eigenvalue problem for my Fisherfaces implementation in OpenCV, but it isn't exposed to the OpenCV API. You can find a header-only implementation in one of my GitHub repositories:</p>
<ul>
<li><a href="https://github.com/bytefish/opencv/blob/master/lda/include/decomposition.hpp">decomposition.hpp</a></li>
</ul>
<p>Now to the eigenvalue accuracy, you refer to. In case of an ill-conditioned matrix small rounding errors in the computation will lead to large errors in the result. I won't throw the math at you again, but you can read all this up at:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Condition_number"></a><a href="http://en.wikipedia.org/wiki/Condition_number">http://en.wikipedia.org/wiki/Condition_number</a></li>
</ul>
<p>The page is explicitly mentioning eigenvalue problems. </p>
<p>Now here is my practical rule of thumb. It's very easy to calculate the condition number with MATLAB or GNU Octave by simply using the <code>cond</code> function. See if <code>rcond</code> (reciprocal condition number) yields a number close to your machine eps, your matrix is most likely to be ill-conditioned and solvers are going to calculate you some totally random stuff. You can easily determine your machine eps by typing <code>eps</code> in GNU Octave; I guess it is similar for Matlab.</p>
<p>Just as a side note, usually for a given matrix <code>X</code> the <code>log10(cond(X))</code> gives you the number of decimal places that you <em>may</em> lose due to roundoff errors. The IEEE standard for double precision numbers has 16 decimal digits, and let us assume your matrix has a condition number of <code>10^12</code>, then you should expect only 4 digits to be accurate in your result.</p>
http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11681#post-id-11681@Philipp Wagner : Thank you for your time. Right now, I have found some implementation of eig in MatLab in some toolbox and I just trying to see if there a lot of difference between the built-in and those function. Stay alert, I'll post an edit on my answer with more details about my result and every thing.Mon, 15 Apr 2013 12:58:11 -0500http://answers.opencv.org/question/10841/mismatch-of-the-eigen-vector-value/?comment=11681#post-id-11681