Registered Member
|
Hello, I'm trying to use the LeastSquare to do a linear regression, but it gives an innacurate (although close) answer.
The code I'm using is the exemple code on the LeastSquare module page : http://eigen.tuxfamily.org/dox-2.0/grou ... odule.html
I just changed one detail in the declaration of points_ptr : It is an array of pointer, so I think it should be std::vector<Vector3d*> and not std::vector<Vector3d>, like in the doc page. This gives me the following results :
And the correct results should be (0.495, -1.927, -2.906), just as the page said, as I also checked on Matlab, and lsqlin gives me the same result. Any idea what could be wrong ? (I tried in Eigen2 and Eigen3, so I dont think it's a version incompatibility problem). Thank you in advance.
Last edited by demod on Mon Jan 13, 2014 1:43 pm, edited 2 times in total.
|
Registered Member
|
You may be aware of this, but the documentation page you cite pertains to Eigen 2.0. The current version is Eigen 3.2; the last release in the Eigen 2.0 series was done more than two years ago. It would probably be best for you to upgrade as I think it is unlikely that there will be any further releases.
The LeastSquares module was removed in Eigen 3; its C-style API was not consistent with the rest of the library. Have a look at http://eigen.tuxfamily.org/dox/group__T ... tml#title4 for an explanation on how to do least squares using the SVD decomposition. |
Registered Member
|
Thank you, I just saw that.
I directly made a search for "least square" in the API, and that was the only result that came, I knew it was from 2.0, but I didn't know it was that obsolete. I tested the SV Decomposition, it works. Thank you. |
Registered Member
|
However, if it is an obsolete module, why keep it in Eigen3 ?
|
Registered Member
|
This is a simple self contained example how to do LS using the QR decomposition using the latest Eigen 3.2 version:
This works because you try to solve: x = (A^T*A)^-1*A^t*b or (A^T*A)*x = A^t*b if you replace A by A=QR then you get (R^T*Q^T*Q*R)*x=R^T*Q^T*b => simplifies to R*x=Q^T*b right solve which is exactly what the code above does. Note how here the solution is numerically very stable since we don't have to do A^T*A nor invert it. |
Registered users: Baidu [Spider], Bing [Bot], Google [Bot], Yahoo [Bot]