Go to the documentation of this file.00001
00016 #ifndef PERTURBATION_HPP_
00017 #define PERTURBATION_HPP_
00018
00019 #include "jmath/jblas.hpp"
00020 #include "jmath/ublasExtra.hpp"
00021
00022 #include "rtslam/gaussian.hpp"
00023
00024 namespace jafar {
00025 namespace rtslam {
00026 using namespace jblas;
00027 using namespace jmath::ublasExtra;
00028
00040 class Perturbation: public Gaussian {
00041 private:
00042 vec x_ct;
00043 sym_mat P_ct;
00044 jblas::ind_array ia_deterministic;
00045
00046 public:
00047 Perturbation(): x_ct(0), P_ct(0) {}
00048
00049 Perturbation(const size_t _size) :
00050 Gaussian(_size), x_ct(_size), P_ct(_size) {
00051 x_ct.clear();
00052 P_ct.clear();
00053 }
00054 virtual void resize(size_t _size, bool preserve = true)
00055 {
00056 Gaussian::resize(_size, preserve);
00057 x_ct.resize(_size, preserve);
00058 P_ct.resize(_size, _size, preserve);
00059 }
00060
00061 Perturbation(const vec & p, const sym_mat & P) :
00062 Gaussian(p, P), x_ct(p.size()), P_ct(p.size()) {
00063 x_ct.clear();
00064 P_ct.clear();
00065 }
00066 Perturbation(const vec & p, const vec & _std) :
00067 Gaussian(p.size()), x_ct(p.size()), P_ct(p.size()) {
00068 x_ct.clear();
00069 P_ct.clear();
00070 this->x(p);
00071 this->std(_std);
00072 }
00073
00080 Perturbation(const vec & p, const sym_mat & P, double dt) ;
00087 Perturbation(const vec & p, const vec & _std, double dt) ;
00088
00089 Perturbation(const Gaussian & p) :
00090 Gaussian(p), x_ct(p.size()), P_ct(p.size()) {
00091 x_ct.clear();
00092 P_ct.clear();
00093 }
00094
00095 void clear()
00096 {
00097 Gaussian::clear();
00098 x_ct.clear();
00099 P_ct.clear();
00100 }
00101
00102 template<class SymMat>
00103 void set_P_continuous(SymMat & _P_ct) {
00104 JFR_ASSERT(_P_ct.size1() == size(), "Matrix sizes mismatch.");
00105 P_ct = _P_ct;
00106 }
00107 template<class V>
00108 void set_x_continuous(V & _x_ct) {
00109 JFR_ASSERT(_x_ct.size() == size(), "Vector sizes mismatch.");
00110 x_ct = _x_ct;
00111 }
00116 void set_std_continuous(const vec & _std) {
00117 JFR_ASSERT(size() == _std.size(), "Sizes mismatch");
00118 P_ct.clear();
00119 size_t i;
00120 for (i = 0 ; i< _std.size() ; i++)
00121 P_ct(i,i) = _std(i)*_std(i);
00122
00123 }
00127 void set_continuous(const vec & _x, const vec & _std){
00128 set_x_continuous(_x);
00129 set_std_continuous(_std);
00130 }
00134 void set_continuous(const vec & _x, const sym_mat & _P){
00135 set_x_continuous(_x);
00136 set_P_continuous(_P);
00137 }
00138
00139 void set_deterministic(jblas::ind_array ia) { ia_deterministic = ia; }
00140 void set_deterministic(ublas::range ia) { ia_deterministic = jmath::ublasExtra::ia_set(ia); }
00141
00142
00151 void set_P_from_continuous(double _dt) {
00152 JFR_ASSERT(P_ct.size1() == size(), "Continuous-time covariance not yet initialized.");
00153 P(P_ct * _dt);
00154 ublas::project(P(), ia_deterministic, ia_deterministic) *= _dt;
00155 }
00156
00165 void set_P_from_continuous(sym_mat & _P_ct, double _dt) {
00166 JFR_ASSERT(_P_ct.size1() == size(), "Matrix sizes mismatch.");
00167 set_P_continuous(_P_ct);
00168 P(P_ct * _dt);
00169 ublas::project(P(), ia_deterministic, ia_deterministic) *= _dt;
00170 }
00182 void set_from_continuous(double _dt) {
00183 JFR_ASSERT(x_ct.size() == size(), "Continuous-time values not yet initialized.");
00184 double sqdt = sqrt(_dt);
00185 x(x_ct * sqdt);
00186 ublas::project(x(), ia_deterministic) *= sqdt;
00187 P(P_ct * _dt);
00188 ublas::project(P(), ia_deterministic, ia_deterministic) *= _dt;
00189
00190 }
00201 void set_from_continuous(Gaussian & Pct, double _dt) {
00202 JFR_ASSERT(Pct.size() == size(), "Sizes mismatch");
00203 set_x_continuous(Pct.x());
00204 set_P_continuous(Pct.P());
00205 set_from_continuous(_dt);
00206 }
00207
00208 };
00209
00210
00211 }
00212 }
00213
00214 #endif