KalmanFilter
eigen.h
1 #ifndef VECTOREIGEN
2 #define VECTOREIGEN
3 #include "../Eigen.h"
4 #include <stdexcept>
5 
6 
7 class vectorEigen{
8  private:
9  Eigen::VectorXd value;
10  public:
11  /*
12  * Reason this empty constructor is allowed is because
13  * of the discreteSolver<K>/continuousSolver<K> class that allows
14  * a constructor with just the discreteModel<K>/continuousModel<K>
15  * and not initial conditions which means the private currentState
16  * variables within those classes end up defined with an empty constructor.
17  */
18  vectorEigen(){}
19 
20  vectorEigen(Eigen::VectorXd value):value(value){}
21 
22  Eigen::VectorXd getSystemValue() const{
23  return value;
24  }
25 
26  static vectorEigen randomVector(int dimension,uint32_t seed){
27  std::mt19937 generator(seed);
28  std::normal_distribution<double> distribution(0.0,1.0);
29 
30  Eigen::VectorXd tmp(dimension);
31  for(int i = 0; i < dimension; i++){
32  tmp[i] = distribution(generator);
33  }
34  return vectorEigen(tmp);
35  }
36 
37 
38 };
39 
40 vectorEigen operator-(const vectorEigen &lhs,const vectorEigen &rhs){
41  vectorEigen res(lhs.getSystemValue() - rhs.getSystemValue());
42  return res;
43 };
44 
45 vectorEigen operator+(const vectorEigen &lhs,const vectorEigen &rhs){
46  vectorEigen res(lhs.getSystemValue() + rhs.getSystemValue());
47  return res;
48 };
49 
50 std::ostream& operator<<(std::ostream& stream, const vectorEigen & vec) {
51  Eigen::VectorXd v = vec.getSystemValue();
52  stream<<v;
53  return stream;
54 }
55 
56 
57 
58 
60  private:
61  Eigen::MatrixXd value;
62 
63  public:
64  matrixEigen(){}
65 
66 
67  matrixEigen(Eigen::MatrixXd value):value(value){}
68 
69 
70  static matrixEigen Identity(int dimension,int dimension2){
71  return matrixEigen(Eigen::MatrixXd::Identity(dimension,dimension));//TODO fix
72  }
73 
74  matrixEigen transpose(){//TODO transpose proper
75  matrixEigen t(value.transpose());
76  return t;
77  }
78 
79  matrixEigen inverse(){
80  matrixEigen t(value.inverse());
81  return t;
82  }
83 
84  Eigen::MatrixXd getSystemValue() const{
85  return value;
86  }
87 };
88 
89 matrixEigen operator*(const matrixEigen &lhs, const matrixEigen &rhs){
90  matrixEigen res(lhs.getSystemValue()*rhs.getSystemValue());
91  return res;
92 }
93 
94 matrixEigen operator+(const matrixEigen &lhs,const matrixEigen &rhs){
95  matrixEigen res(lhs.getSystemValue() + rhs.getSystemValue());
96  return res;
97 };
98 
99 matrixEigen operator-(const matrixEigen &lhs,const matrixEigen &rhs){
100  matrixEigen res(lhs.getSystemValue() - rhs.getSystemValue());
101  return res;
102 };
103 
104 std::ostream& operator<<(std::ostream& stream, const matrixEigen & mat) {
105  Eigen::MatrixXd v = mat.getSystemValue();
106  stream<<v;
107  return stream;
108 }
109 
110 
111 
112 
113 vectorEigen operator*(const matrixEigen &lhs, const vectorEigen &rhs){
114  vectorEigen res(lhs.getSystemValue()*rhs.getSystemValue());
115  return res;
116 }
117 
118 vectorEigen operator*(const vectorEigen &lhs, const matrixEigen &rhs){
119  vectorEigen res(lhs.getSystemValue()*rhs.getSystemValue());
120  return res;
121 }
122 #endif
Definition: eigen.h:59
Definition: eigen.h:7