0.4.1
Loading...
Searching...
No Matches
ARMA.hpp
Go to the documentation of this file.
1// This file is part of INSTINCT, the INS Toolkit for Integrated
2// Navigation Concepts and Training by the Institute of Navigation of
3// the University of Stuttgart, Germany.
4//
5// This Source Code Form is subject to the terms of the Mozilla Public
6// License, v. 2.0. If a copy of the MPL was not distributed with this
7// file, You can obtain one at https://mozilla.org/MPL/2.0/.
8
9/// @file ARMA.hpp
10/// @brief ARMA Node
11/// @author MSc. Janis Thürsam (janis.thuersam@yahoo.de)
12/// @date 2021-01-13
13
14#pragma once
15
17
18#include "util/Eigen.hpp"
19
21
22#include <deque>
23
25{
26/// @brief Node performing an ARMA filtering of incoming data
27class ARMA : public Node
28{
29 public:
30 /// @brief Default constructor
31 ARMA();
32 /// @brief Destructor
33 ~ARMA() override;
34 /// @brief Copy constructor
35 ARMA(const ARMA&) = delete;
36 /// @brief Move constructor
37 ARMA(ARMA&&) = delete;
38 /// @brief Copy assignment operator
39 ARMA& operator=(const ARMA&) = delete;
40 /// @brief Move assignment operator
41 ARMA& operator=(ARMA&&) = delete;
42
43 /// @brief String representation of the Class Type
44 [[nodiscard]] static std::string typeStatic();
45
46 /// @brief String representation of the Class Type
47 [[nodiscard]] std::string type() const override;
48
49 /// @brief String representation of the Class Category
50 [[nodiscard]] static std::string category();
51
52 /// @brief ImGui config window which is shown on double click
53 /// @attention Don't forget to set _hasConfig to true in the constructor of the node
54 void guiConfig() override;
55
56 /// @brief Saves the node into a json object
57 [[nodiscard]] json save() const override;
58
59 /// @brief Restores the node from a json object
60 /// @param[in] j Json object with the node state
61 void restore(const json& j) override;
62
63 private:
64 constexpr static size_t INPUT_PORT_INDEX_IMU_OBS = 0; ///< @brief Flow (ImuObs)
65 constexpr static size_t OUTPUT_PORT_INDEX_IMU_OBS = 0; ///< @brief Flow (ImuObs)
66
67 /// @brief Initialize the node
68 bool initialize() override;
69
70 /// @brief Deinitialize the node
71 void deinitialize() override;
72
73 /// @brief Receive Sensor Data
74 /// @param[in] queue Queue with all the received data messages
75 /// @param[in] pinIdx Index of the pin the data is received on
76 void receiveImuObs(InputPin::NodeDataQueue& queue, size_t pinIdx);
77
78 /// @brief calculate autocorrelation function (ACF)
79 /// @param[in] y vector of data
80 /// @param[in] p order of AR process
81 /// @param[out] acf vector of acf values
82 static void acf_function(Eigen::VectorXd& y, int p, Eigen::VectorXd& acf);
83
84 /// @brief calculate partial autocorrelation function (PACF) via Durbin-Levinson
85 /// @param[in] y vector of data
86 /// @param[in] acf vector of acf
87 /// @param[in] p order of AR process
88 /// @param[out] pacf vector of pacf values
89 /// @param[out] e_hat_initial vector of initial ê for Hannan-Rissanen
90 static void pacf_function(Eigen::VectorXd& y, Eigen::VectorXd& acf, int p, Eigen::VectorXd& pacf, Eigen::VectorXd& e_hat_initial);
91
92 /// @brief Calculate ARMA parameters through Hannan-Rissanen
93 /// @param[in] y vector of data
94 /// @param[in] p order of AR process
95 /// @param[in] q order of MA process
96 /// @param[in] m value of superior order (p or q)
97 /// @param[in] deque_size Size of the deque
98 /// @param[out] x ARMA slope parameters
99 /// @param[out] emp_sig Empirical significance (p-Value) of parameters
100 /// @param[out] y_hat Output measurement data
101 static void hannan_rissanen(Eigen::VectorXd& y, int p, int q, int m, int deque_size, Eigen::VectorXd& x, Eigen::VectorXd& emp_sig, Eigen::VectorXd& y_hat);
102
103 /// @brief fill A matrix for least squares
104 /// @param[in] y vector of data
105 /// @param[in] e_hat residuals
106 /// @param[in] p order of AR process
107 /// @param[in] q order of MA process
108 /// @param[in] m value of superior order (p or q)
109 /// @param[out] A Returns the matrix filled with least squares
110 static void matrix_function(Eigen::VectorXd& y, Eigen::VectorXd& e_hat, int p, int q, int m, Eigen::MatrixXd& A);
111
112 /// @brief Buffer used to store Imu observations
113 std::deque<std::shared_ptr<const ImuObs>> _buffer;
114
115 /// loop iterator
116 int _k = 0;
117
118 bool INITIALIZE = false; ///< parameter initialization indicator
119 // ARMA order
120 int _p = 2; ///< AR order
121 int _q = 2; ///< MA order
122
123 int _deque_size = 1000; ///< modelling size
124 int _num_obs = 6; ///< number of observations (3-axis accelerometer / 3-axis gyro)
125
126 Eigen::MatrixXd _y; ///< measurement data
127 Eigen::VectorXd _y_rbm; ///< y (reduced by mean)
128 Eigen::VectorXd _y_hat; ///< ARMA estimates for y_rbm
129 Eigen::VectorXd _emp_sig; ///< empirical significance (p-Value) of parameters
130 Eigen::VectorXd _x; ///< ARMA slope parameters
131 Eigen::VectorXd _y_hat_t; ///< output container
132
133 int _p_mem = 0; ///< p memory to reset for each observation
134 int _q_mem = 0; ///< q memory to reset for each observation
135
136 int _m = 0; ///< value of superior order (p or q)
137 double _y_mean = 0; ///< y-mean
138};
139
140} // namespace NAV::experimental
Vector space operations.
nlohmann::json json
json namespace
Parent Class for all IMU Observations.
Node Class.
TsDeque< std::shared_ptr< const NAV::NodeData > > NodeDataQueue
Node data queue type.
Definition Pin.hpp:707
Node(std::string name)
Constructor.
Definition Node.cpp:30
~ARMA() override
Destructor.
Definition ARMA.cpp:32
Eigen::MatrixXd _y
measurement data
Definition ARMA.hpp:126
void deinitialize() override
Deinitialize the node.
Definition ARMA.cpp:140
static std::string category()
String representation of the Class Category.
Definition ARMA.cpp:47
std::deque< std::shared_ptr< const ImuObs > > _buffer
Buffer used to store Imu observations.
Definition ARMA.hpp:113
int _m
value of superior order (p or q)
Definition ARMA.hpp:136
static void pacf_function(Eigen::VectorXd &y, Eigen::VectorXd &acf, int p, Eigen::VectorXd &pacf, Eigen::VectorXd &e_hat_initial)
calculate partial autocorrelation function (PACF) via Durbin-Levinson
Definition ARMA.cpp:174
static void hannan_rissanen(Eigen::VectorXd &y, int p, int q, int m, int deque_size, Eigen::VectorXd &x, Eigen::VectorXd &emp_sig, Eigen::VectorXd &y_hat)
Calculate ARMA parameters through Hannan-Rissanen.
Definition ARMA.cpp:265
Eigen::VectorXd _y_hat
ARMA estimates for y_rbm.
Definition ARMA.hpp:128
int _deque_size
modelling size
Definition ARMA.hpp:123
void guiConfig() override
ImGui config window which is shown on double click.
Definition ARMA.cpp:52
Eigen::VectorXd _x
ARMA slope parameters.
Definition ARMA.hpp:130
static constexpr size_t OUTPUT_PORT_INDEX_IMU_OBS
Flow (ImuObs)
Definition ARMA.hpp:65
int _k
loop iterator
Definition ARMA.hpp:116
double _y_mean
y-mean
Definition ARMA.hpp:137
bool initialize() override
Initialize the node.
Definition ARMA.cpp:118
Eigen::VectorXd _y_hat_t
output container
Definition ARMA.hpp:131
int _q_mem
q memory to reset for each observation
Definition ARMA.hpp:134
ARMA(const ARMA &)=delete
Copy constructor.
static void acf_function(Eigen::VectorXd &y, int p, Eigen::VectorXd &acf)
calculate autocorrelation function (ACF)
Definition ARMA.cpp:145
ARMA & operator=(ARMA &&)=delete
Move assignment operator.
static std::string typeStatic()
String representation of the Class Type.
Definition ARMA.cpp:37
Eigen::VectorXd _y_rbm
y (reduced by mean)
Definition ARMA.hpp:127
int _q
MA order.
Definition ARMA.hpp:121
std::string type() const override
String representation of the Class Type.
Definition ARMA.cpp:42
ARMA(ARMA &&)=delete
Move constructor.
static void matrix_function(Eigen::VectorXd &y, Eigen::VectorXd &e_hat, int p, int q, int m, Eigen::MatrixXd &A)
fill A matrix for least squares
Definition ARMA.cpp:250
int _num_obs
number of observations (3-axis accelerometer / 3-axis gyro)
Definition ARMA.hpp:124
void receiveImuObs(InputPin::NodeDataQueue &queue, size_t pinIdx)
Receive Sensor Data.
Definition ARMA.cpp:314
ARMA & operator=(const ARMA &)=delete
Copy assignment operator.
bool INITIALIZE
parameter initialization indicator
Definition ARMA.hpp:118
Eigen::VectorXd _emp_sig
empirical significance (p-Value) of parameters
Definition ARMA.hpp:129
int _p
AR order.
Definition ARMA.hpp:120
void restore(const json &j) override
Restores the node from a json object.
Definition ARMA.cpp:100
static constexpr size_t INPUT_PORT_INDEX_IMU_OBS
Flow (ImuObs)
Definition ARMA.hpp:64
ARMA()
Default constructor.
Definition ARMA.cpp:20
json save() const override
Saves the node into a json object.
Definition ARMA.cpp:87
int _p_mem
p memory to reset for each observation
Definition ARMA.hpp:133