Re: [eigen] Convert 1x1 matrix to internal type?

[ Thread Index | Date Index | More lists.tuxfamily.org/eigen Archives ]


Indeed, a Cholesky decomposition is a better option. However, the below does not appear to be correct. I'm going to keep working the problem, but in the meantime does anyone know how the Eigen expression to compute Mahalanobis distance from the origin using a Cholesky decomposition?


-----Original Message-----
From: Márton Danóczy <marton78@xxxxxxxxx>
To: eigen@xxxxxxxxxxxxxxxxxxx <eigen@xxxxxxxxxxxxxxxxxxx>
Sent: Fri, Sep 17, 2010 5:36 am
Subject: Re: [eigen] Convert 1x1 matrix to internal type?


What about (untested):


double d = covariance.llt().matrixL().solve(data).squaredNorm();


Not that it answers your question, but this is the faster and numerically more stable way to compute it :)


Marton

On 17.09.2010, at 03:48, Li Wei <lwthucs@xxxxxxxxx> wrote:




How about converts to any matrix double type to its first element(top-left corner) in release mode by default, but with dimensionality check in debug mode.


On Thu, Sep 16, 2010 at 3:33 AM,  <lfrfly@xxxxxxxxxxx> wrote:

It seems to me that a 1x1 matrix ought to be convertible to its internal type. Maybe it is, but if so, there's some kind of problem. Consider the computation for Mahalanobis distance:

Matrix2d covariance, covInverse;
Vector2d data;

covariance.computeInverse(&covInverse);
double mdist = data.transpose()*covInverse*data;

You would think this would work fine, since the result ix 1x1. However, it gives an error that an Eigen::Multiply cannot be converted to a double.

I can get around this by doing

double mdist = (data.transpose()*covInverse*data)[0];

but that's a bit awkward. What is the "correct" solution to this issue?






--

Best Wishes From
Wei Li
Moblie:86-13810480212
Dep. of Computer Science and Technology, Tshinghua Univ.




Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/