39 #ifndef KALMANLINEARALGEBRA_H 40 #define KALMANLINEARALGEBRA_H 43 #include "boost/serialization/array_wrapper.hpp" 44 #include "boost/numeric/ublas/vector.hpp" 45 #include "boost/numeric/ublas/matrix.hpp" 46 #include "boost/numeric/ublas/symmetric.hpp" 47 #include "boost/numeric/ublas/lu.hpp" 52 namespace ublas = boost::numeric::ublas;
58 typedef ublas::vector<double, ublas::bounded_array<double, N> >
type;
65 typedef ublas::symmetric_matrix<double, ublas::lower, ublas::row_major, ublas::bounded_array<double,
N*(
N+1)/2> >
type;
69 template<
int N,
int M>
72 typedef ublas::matrix<double, ublas::row_major, ublas::bounded_array<double, N*M> >
type;
108 template <
class T,
class TRI,
class L,
class A>
111 typedef typename ublas::symmetric_matrix<T, TRI, L, A>::size_type size_type;
112 typedef typename ublas::symmetric_matrix<T, TRI, L, A>::value_type value_type;
118 for(size_type i = 0; i < m.size1(); ++i) {
119 for(size_type j = 0; j <= i; ++j) {
121 value_type ele =
m(i,j);
123 for(size_type
k = 0;
k < j; ++
k)
124 ele -=
m(
k,
k) *
m(i,
k) *
m(j,
k);
147 for(size_type i = 0; i < m.size1(); ++i) {
148 for(size_type j = 0; j <= i; ++j) {
150 value_type ele =
m(i,j);
160 value_type sum = -ele;
161 for(size_type
k = j+1;
k < i; ++
k)
162 sum -=
m(i,
k) *
m(
k,j);
170 for(size_type i = 0; i < m.size1(); ++i) {
171 for(size_type j = 0; j <= i; ++j) {
173 value_type sum =
m(i,i);
177 for(size_type
k = i+1;
k < m.size1(); ++
k)
178 sum +=
m(
k,
k) *
m(
k,i) *
m(
k,j);
192 template <
class T,
class L,
class A>
197 if(m.size1() != m.size2())
202 ublas::permutation_matrix<std::size_t>
pm(m.size1());
206 ublas::matrix<T, L, A> mcopy(m);
211 int res = lu_factorize(mcopy,
pm);
217 m.assign(ublas::identity_matrix<T>(m.size1()));
221 lu_substitute(mcopy,
pm, m);
233 typename M::size_type
n =
std::min(m.size1(), m.size2());
234 typename M::value_type
result = 0.;
236 for(
typename M::size_type i = 0; i <
n; ++i)
Kalman gain matrix, dimension 5xN.
ublas::matrix< double, ublas::row_major, ublas::bounded_array< double, N *M > > type
KSymMatrix< 5 >::type TrackError
Track error matrix, dimension 5x5.
Define a shortened alias for ublas namespace.
M::value_type trace(const M &m)
KMatrix< N, 5 >::type type
ublas::vector< double, ublas::bounded_array< double, N > > type
bool syminvert(ublas::symmetric_matrix< T, TRI, L, A > &m)
General matrix, dimension NxM.
bool invert(ublas::matrix< T, L, A > &m)
KVector< 5 >::type TrackVector
Track state vector, dimension 5.
Kalman H-matrix, dimension Nx5.
T min(sqlite3 *const db, std::string const &table_name, std::string const &column_name)
KMatrix< 5, 5 >::type TrackMatrix
General 5x5 matrix.
KMatrix< 5, N >::type type
Symmetric matrix, dimension NxN.