Registered Member
|
Hi,
I'm having problem running the function linearRegression(). I'm trying to run the example code: """ Vector3d gridPoints[5]; gridPoints[0] = Vector3d( 3.02, 6.89, -4.32 ); gridPoints[1] = Vector3d( 2.01, 5.39, -3.79 ); gridPoints[2] = Vector3d( 2.41, 6.01, -4.01 ); gridPoints[3] = Vector3d( 2.09, 5.55, -3.86 ); gridPoints[4] = Vector3d( 2.58, 6.32, -4.10 ); Vector3d coeffs; linearRegression(5, gridPoints, &coeffs, 1); """ But at the function call I get the following error: Error 1 error C2784: 'void Eigen::linearRegression(int,VectorType **,VectorType *,int)' : could not deduce template argument for 'VectorType **' from 'Eigen::Vector3d [5]' Then I tried running the function with: linearRegression(5, gridPoints, &coeffs, 1); and got the following error: Error 1 error C2664: 'Eigen::linearRegression' : cannot convert parameter 2 from 'Eigen::Vector3d [5]' to 'Eigen::Vector3d **' I'm using Visual Studio 2005 (C++). Thanks. |
Registered Member
|
Hi,
I'd try
what changes the call from 'Eigen::Vector3d [5]' (which is identical to 'VectorType *') to 'VectorType **' as the compiler states. Good luck |
Registered Member
|
Hi Seb,
tried "linearRegression(5, &gridPoints, &coeffs, 1);" still got error message: Error 1 error C2784: 'void Eigen::linearRegression(int,VectorType **,VectorType *,int)' : could not deduce template argument for 'VectorType **' from 'Eigen::Vector3d (*)[5]' any thoughts? thanks again. |
Registered Member
|
Indeed, the documentation is outdated.
linearRegression() doesn't want an array of vectors, it wants an array of pointers to vectors. That's the cause of your trouble... The use case is when you have vectors not stored as an array of vectors (e.g. coming from a more complex data structure). This function then allows you to avoid having to copy them into an array of vectors: you just need to copy pointers to them. In your case, since you are able to store your vectors in an array in the first place, it's probably easiest for you to just store them in a matrix, and then do the least squares yourself. Remember that a least-squares solution to "Ax=b" is just a solution to "A^t A x = A^t b". So if A^t A is positive definite you can use Cholesky LLT solving, otherwise i don't know what's best but you have plenty of choice with Eigen. Yes, I am not 100% sure about the usefulness of this linearRegression() function.... fitHyperplane is more useful.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
|
Registered Member
|
Thinking further about it, it's probably worth adding a few overloads of this function, one taking an array of vectors as you expected, etc.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
Hi bjacob: actually I was stumbling across the same error when I copied&pasted the example code from the documentation. So you might want to change the example some time... After changing the type to an 'array of pointers to vectors' like this
the compiler at least accepted the 'points' argument. However, now I got mysterious errors in Block.h: eigen-2.0.1/Eigen/src/LeastSquares/LeastSquares.h:118: error: no matching function for call to ‘Eigen::Block, 1, 3, 1, 32>::block(int&, int)’ eigen-2.0.1/Eigen/src/Core/Block.h:305: note: candidates are: typename Eigen::BlockReturnType::Type Eigen::MatrixBase::block(int, int, int, int) [with Derived = Eigen::Block, 1, 3, 1, 32>] eigen-2.0.1/Eigen/src/Core/Block.h:313: note: const typename Eigen::BlockReturnType::Type Eigen::MatrixBase::block(int, int, int, int) const [with Derived = Eigen::Block, 1, 3, 1, 32>] ... eigen-2.0.1/Eigen/src/Core/Matrix.h:511: error: ‘INVALID_MATRIX_TEMPLATE_PARAMETERS’ is not a member of ‘Eigen::ei_static_assert Does anyone know what to make out of it?? Or does anyone just have a simple (working) example, how to use linearRegression succesfully? Best regards, Martin |
Registered Member
|
Guys, sorry for the trouble, and thanks for reporting. All this is now fixed in both trunk and stable (2.0 branch).
The truth is that this function was untested: only fitHyperplane() was covered by the test, a long time ago it used to call linearRegression() but this is no longer the case and thus linearRegression() stayed untested. Now I updated the unit-test.
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered Member
|
For your information: linearRegression() is now a wrapper around fitHyperplane(). I am considering making linearRegression() deprecated because its API is pretty convoluted (funcOfOthers parameter, layout of the result).
I am also considering adding a variant of fitHyperplane() taking a matrix, the columns being interpreted as the input points. Opinions?
Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list! |
Registered users: Bing [Bot], Google [Bot], Sogou [Bot]