This forum has been archived. All content is frozen. Please use KDE Discuss instead.

Quadratic form with dense and sparse matrix

Tags: None
(comma "," separated)
simoneceriani
Registered Member
Posts
2
Karma
0
Hi

I'm using eigen for the implementation of an efficient extended kalman filter and I have some question about optimization of calculus with symmetric matrix:

The first question is:
I need to use a lot of quadratic form multiplication in the form

P = J * P * J.transpose();

and P is a square symmetric matrix.

There is a special function to call to have the better performance or the best way is to tall that P is selfAdjoint?

And what about if J will be sparse?

The second question is about a different operation, that is:
P = P - K * H * P;

where
- P is a dense symmetric matrix with n-by-n elements (order of hundreds of elements)
- K is a dense matrix with n-by-m elements (m very small, let say 2,3 elements)
- H is a sparse matrix with total size of m-by-n elements

Up to now this is the most time consuming operation in my tests...
what is the more efficient way to calculate it?


thanks in advance!!
User avatar
bjacob
Registered Member
Posts
658
Karma
3
Hm, I don't think that we have something for computing J*P*J^T efficiently in general...

We do have efficient X*X^T computation, but that won't float your boat unless your P matrix is positive and you already know a square root of it. If that is the case, you could let X = J*sqrt(P) and compute X*X^T.

In your second problem,

P = P - K * H * P;

I think you can make good use of the sparsity of H. Let's see. If H had only one nonzero coefficient H at (i,j), this would be equivalent to:

P -= H(i,j) * K.col(j) * P.row(i);

this is called a "rank 1 update". We have optimized code for self-adjoint rank updates, but here yours is not self-adjoint. Nevertheless I am rather confident that Eigen should optimize well the above line of code, as an outer product.

EDIT: oops, as soon as H has more than 1 nonzero coefficient, the efficiency of this decreases sharply, as the whole P matrix is traversed as many times as H has nonzero coeffs.

One thing is very important: when a size is known at compile time to be very small, do tell Eigen this. For example, if K has 3 columns, declare it as:

Matrix<float,Dynamic,3> K;


Join us on Eigen's IRC channel: #eigen on irc.freenode.net
Have a serious interest in Eigen? Then join the mailing list!


Bookmarks



Who is online

Registered users: Bing [Bot], blue_bullet, Google [Bot], rockscient, Yahoo [Bot]