root/bdm/estim/arx.h @ 286

Revision 286, 3.6 kB (checked in by smidl, 15 years ago)

make mpdm work again

  • Property svn:eol-style set to native
Line 
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 "../stat/libFN.h"
17#include "../stat/libEF.h"
18
19namespace bdm {
20
21/*!
22* \brief Linear Autoregressive model with Gaussian noise
23
24Regression of the following kind:
25\f[
26y_t = \theta_1 \psi_1 + \theta_2 + \psi_2 +\ldots + \theta_n \psi_n + r e_t
27\f]
28where 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:
29\f[
30e_t \sim \mathcal{N}(0,1).
31\f]
32
33See \ref tut_arx for mathematical treatment.
34
35The easiest way how to use the class is:
36\include arx_simple.cpp
37
38*/
39class ARX: public BMEF {
40protected:
41        //!size of output variable (needed in regressors)
42        int dimx;
43        //!description of modelled data \f$ y_t \f$ in the likelihood function
44        //! Do NOT access directly, only via \c get_yrv().
45        RV _yrv;
46        //! Posterior estimate of \f$\theta,r\f$ in the form of Normal-inverse Wishart density
47        egiw est;
48        //! cached value of est.V
49        ldmat &V;
50        //! cached value of est.nu
51        double ν
52public:
53        //! \name Constructors
54        //!@{
55        ARX ( const double frg0=1.0 ) : BMEF ( frg0 ),est (), V ( est._V() ), nu ( est._nu() ) {};
56        ARX ( const ARX &A0 ) : BMEF (),est (), V ( est._V() ), nu ( est._nu() ) {
57                set_statistics ( A0.dimx,A0.V,A0.nu );
58                set_parameters(A0.frg);
59        };
60        ARX* _copy_() const;
61        void set_parameters ( double frg0 ) {frg=frg0;}
62        void set_statistics ( int dimx0, const ldmat V0, double nu0=-1.0 ) {est.set_parameters ( dimx0,V0,nu0 );last_lognc=est.lognc();dimx=dimx0;}
63        //!@}
64
65//      //! Set parameters given by moments, \c mu (mean of theta), \c R (mean of R) and \c C (variance of theta)
66//      void set_parameters ( const vec &mu, const mat &R, const mat &C, double dfm){};
67        //! Set sufficient statistics
68        void set_statistics ( const BMEF* BM0 );
69//      //! Returns sufficient statistics
70//      void get_parameters ( mat &V0, double &nu0 ) {V0=est._V().to_mat(); nu0=est._nu();}
71        //!\name Mathematical operations
72        //!@{
73
74        //! Weighted Bayes \f$ dt = [y_t psi_t] \f$.
75        void bayes ( const vec &dt, const double w );
76        void bayes ( const vec &dt ) {bayes ( dt,1.0 );};
77        double logpred ( const vec &dt ) const;
78        void flatten ( const BMEF* B ) {
79                const ARX* A=dynamic_cast<const ARX*> ( B );
80                // nu should be equal to B.nu
81                est.pow ( A->nu/nu );
82                if ( evalll ) {last_lognc=est.lognc();}
83        }
84        //! Conditioned version of the predictor
85        enorm<ldmat>* epredictor ( const vec &rgr ) const;
86        //! Predictor for empty regressor
87        enorm<ldmat>* epredictor() const {
88                it_assert_debug ( dimx==V.rows()-1,"Regressor is not only 1" );
89                return epredictor ( vec_1 ( 1.0 ) );
90        }
91        //! conditional version of the predictor
92        mlnorm<ldmat>* predictor() const;
93        mlstudent* predictor_student() const;
94        //! Brute force structure estimation.\return indeces of accepted regressors.
95        ivec structure_est ( egiw Eg0 );
96        //!@}
97
98        //!\name Access attributes
99        //!@{
100        const egiw* _e() const {return &est ;};
101        const egiw& posterior() const {return est;}
102        //!@}
103
104        //!\name Connection
105        //!@{
106        void set_drv ( const RV &drv0 ) {drv=drv0;}
107        RV& get_yrv() {
108                //if yrv is not ready create it
109                if ( _yrv._dsize() !=dimx ) {
110                        int i=0;
111                        while ( _yrv._dsize() <dimx ) {_yrv.add ( drv ( vec_1 ( i ) ) );i++;}
112                }
113                //yrv should be ready by now
114                it_assert_debug ( _yrv._dsize() ==dimx,"incompatible drv" );
115                return _yrv;
116        }
117        //!@}
118};
119
120}
121
122#endif // AR_H
123
Note: See TracBrowser for help on using the browser.