1 | /*! |
---|
2 | \file |
---|
3 | \brief Bayesian Filtering for generalized autoregressive (ARX) model |
---|
4 | \author Vaclav Smidl. |
---|
5 | |
---|
6 | ----------------------------------- |
---|
7 | BDM++ - C++ library for Bayesian Decision Making under Uncertainty |
---|
8 | |
---|
9 | Using IT++ for numerical operations |
---|
10 | ----------------------------------- |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef AR_H |
---|
14 | #define AR_H |
---|
15 | |
---|
16 | #include <itpp/itbase.h> |
---|
17 | #include "../stat/libFN.h" |
---|
18 | #include "../stat/libEF.h" |
---|
19 | |
---|
20 | namespace bdm{ |
---|
21 | |
---|
22 | /*! |
---|
23 | * \brief Linear Autoregressive model with Gaussian noise |
---|
24 | |
---|
25 | Regression of the following kind: |
---|
26 | \f[ |
---|
27 | y_t = \theta_1 \psi_1 + \theta_2 + \psi_2 +\ldots + \theta_n \psi_n + r e_t |
---|
28 | \f] |
---|
29 | where unknown parameters \c rv are \f$[\theta r]\f$, regression vector \f$\psi=\psi(y_{1:t},u_{1:t})\f$ is a known function of past outputs and exogeneous variables \f$u_t\f$. Distrubances \f$e_t\f$ are supposed to be normally distributed: |
---|
30 | \f[ |
---|
31 | e_t \sim \mathcal{N}(0,1). |
---|
32 | \f] |
---|
33 | |
---|
34 | Extension for time-variant parameters \f$\theta_t,r_t\f$ may be achived using exponential forgetting (Kulhavy and Zarrop, 1993). In such a case, the forgetting factor \c frg \f$\in <0,1>\f$ should be given in the constructor. Time-invariant parameters are estimated for \c frg = 1. |
---|
35 | */ |
---|
36 | class ARX: public BMEF { |
---|
37 | protected: |
---|
38 | //! Posterior estimate of \f$\theta,r\f$ in the form of Normal-inverse Wishart density |
---|
39 | egiw est; |
---|
40 | //! cached value of est.V |
---|
41 | ldmat &V; |
---|
42 | //! cached value of est.nu |
---|
43 | double ν |
---|
44 | public: |
---|
45 | //! Full constructor |
---|
46 | ARX ( const RV &rv, const mat &V0, const double &nu0, const double frg0=1.0 ) : BMEF ( rv,frg0 ),est ( rv,V0,nu0 ), V ( est._V() ), nu ( est._nu() ) |
---|
47 | {last_lognc=est.lognc();}; |
---|
48 | |
---|
49 | //!Copy constructor |
---|
50 | ARX ( const ARX &A0 ) : BMEF ( A0),est ( rv,A0.V,A0.nu ), V ( est._V() ), nu ( est._nu() ) {}; |
---|
51 | |
---|
52 | //!Auxiliary function |
---|
53 | ARX* _copy_(bool changerv=false); |
---|
54 | |
---|
55 | // //! Set parameters given by moments, \c mu (mean of theta), \c R (mean of R) and \c C (variance of theta) |
---|
56 | // void set_parameters ( const vec &mu, const mat &R, const mat &C, double dfm){}; |
---|
57 | //! Set sufficient statistics |
---|
58 | void set_parameters ( const ldmat &V0, const double &nu0 ) |
---|
59 | {est._V() =V0;est._nu() =nu0;last_lognc=est.lognc();} |
---|
60 | void set_statistics ( const BMEF* BM0 ); |
---|
61 | //! Returns sufficient statistics |
---|
62 | void get_parameters ( mat &V0, double &nu0 ) {V0=est._V().to_mat(); nu0=est._nu();} |
---|
63 | //! Here \f$dt = [y_t psi_t] \f$. |
---|
64 | void bayes ( const vec &dt, const double w ); |
---|
65 | void bayes ( const vec &dt ) {bayes ( dt,1.0 );}; |
---|
66 | const epdf& _epdf() const {return est;} |
---|
67 | double logpred ( const vec &dt ) const; |
---|
68 | void flatten (const BMEF* B ) { |
---|
69 | const ARX* A=dynamic_cast<const ARX*>(B); |
---|
70 | // nu should be equal to B.nu |
---|
71 | est.pow ( A->nu/nu); |
---|
72 | if(evalll){last_lognc=est.lognc();} |
---|
73 | } |
---|
74 | //! Conditional version of the predictor |
---|
75 | enorm<ldmat>* predictor(const RV &rv0, const vec &rgr) const; |
---|
76 | enorm<ldmat>* predictor(const RV &rv0) const {it_assert_debug(rv0.count()==V.rows()-1,"Regressor is not only 1");return predictor(rv0,vec_1(1.0));} |
---|
77 | mlnorm<ldmat>* predictor(const RV &rv0, const RV &rvc0) const; |
---|
78 | mlstudent* predictor_student(const RV &rv0, const RV &rvc0) const; |
---|
79 | //! Brute force structure estimation.\return indeces of accepted regressors. |
---|
80 | ivec structure_est ( egiw Eg0 ); |
---|
81 | const egiw* _e() const {return &est ;}; |
---|
82 | }; |
---|
83 | |
---|
84 | } |
---|
85 | |
---|
86 | #endif // AR_H |
---|
87 | |
---|