GCOP
1.0
|
00001 #ifndef GCOP_UNSCENTEDBASE_H 00002 #define GCOP_UNSCENTEDBASE_H 00003 00004 #include "manifold.h" 00005 00006 namespace gcop { 00007 00008 using namespace std; 00009 00010 template <typename T = VectorXd, 00011 int _nx = Dynamic> class UnscentedBase { 00012 public: 00013 00014 typedef Matrix<double, _nx, 1> Vectornd; 00015 typedef Matrix<double, _nx, _nx> Matrixnd; 00016 00017 UnscentedBase(Manifold<T, _nx> &X); 00018 00019 virtual ~UnscentedBase(); 00020 00027 void Points(vector<T> &xs, 00028 const T& x); 00029 00030 Manifold<T, _nx> &X; 00031 00032 double a; 00033 double k; 00034 double b; 00035 00036 protected: 00037 int L; 00038 double l; 00039 00040 vector<T> Xs; 00041 00042 vector<double> Ws; 00043 vector<double> Wc; 00044 00045 Matrixnd A; 00046 }; 00047 00048 00049 00050 template <typename T, int _nx> 00051 UnscentedBase<T, _nx>::UnscentedBase(Manifold<T, _nx> &X) : 00052 X(X), 00053 Xs(2*X.n + 1), 00054 Ws(2*X.n + 1), 00055 Wc(2*X.n + 1) { 00056 00057 this->L = X.n; 00058 this->a = .01; 00059 // this->a = 1; 00060 this->k = 0; 00061 this->b = 2; 00062 // this->b = 0; 00063 this->l = a*a*(L+k)-L; 00064 00065 for (int i = 0; i < 2*L + 1; ++i) { 00066 if (i == 0) { 00067 Ws[0] = l/(L+l); 00068 Wc[0] = l/(L+l) + (1-a*a+b); 00069 } else { 00070 Ws[i] = 1/(2*(L+l)); 00071 Wc[i] = 1/(2*(L+l)); 00072 } 00073 } 00074 00075 if (_nx == Dynamic) { 00076 A.resize(X.n, X.n); 00077 } 00078 } 00079 00080 template <typename T, int _nx> 00081 UnscentedBase<T, _nx>::~UnscentedBase() { 00082 } 00083 template <typename T, int _nx> 00084 void UnscentedBase<T, _nx>::Points(vector<T> &Xs, 00085 const T &x) { 00086 Xs[0] = x; 00087 00088 A = x.P.llt().matrixL().transpose(); 00089 bool pd = true; 00090 00091 if (!pd) { 00092 cout << "[W] UKF::Predict: Cholesky failed!" << endl; 00093 } 00094 00095 // cout << "A=" << A << endl; 00096 00097 for (int i = 0; i < L; ++i) { 00098 Vectornd dx = sqrt(L+l)*A.col(i); 00099 Vectornd dxm = -sqrt(L+l)*A.col(i); 00100 00101 this->X.Retract(Xs[i + 1], x, dx); 00102 /* 00103 cout << "#i=" << i << endl; 00104 cout << "x.R=" << x.R << endl; 00105 cout << "dx=" << dx.transpose() << endl; 00106 cout << "R=" << Xs[i+1].R << endl; 00107 */ 00108 this->X.Retract(Xs[i + 1 + L], x, dxm); 00109 } 00110 } 00111 } 00112 00113 00114 #endif