root/library/bdm/estim/arx_ext.h @ 1164

Revision 1164, 2.6 kB (checked in by smidl, 14 years ago)

fix arxg

Line 
1/*!
2  \file
3  \brief Bayesian Filtering for extensions of autoregressive (ARX) model
4  \author Vaclav Smidl.
5
6*/
7
8#ifndef AREX_H
9#define AREX_H
10
11#include "../math/functions.h"
12#include "arx.h"
13
14namespace bdm {
15
16/*!
17* \brief Non-linear transformation + Gaussian noise
18
19Regression of the following kind:
20\f[
21y_t = g(\psi_t ) + r e_t
22\f]
23where unknown parameters \c rv are \f$[r]\f$, regression vector \f$\psi_t=\psi(y_{1:t},u_{1:t})\f$ is propagated through a known function \c g. Distrubances \f$e_t\f$ are supposed to be normally distributed:
24\f[
25e_t \sim \mathcal{N}(0,1).
26\f]
27
28*/
29class ARXg: public ARX {
30protected:
31    //! function g
32    shared_ptr<fnc> g;
33public:
34    //! \name Constructors
35    //!@{
36    ARXg (): ARX() {}
37    ARXg (const ARXg &A0): ARX(A0),g(A0.g) {}
38    ARXg* _copy() const {
39        return new ARXg(*this);
40    }
41    //!@}
42
43    //!\name Mathematical operations
44    //!@{
45
46    //! Weighted Bayes \f$ dt = [y_t psi_t] \f$.
47    void bayes_weighted ( const vec &yt, const vec &cond = empty_vec, const double w = 1.0 ) {
48        int dimc_store =dimc;
49        dimc =0;
50                int rgrlen_store = rgrlen;
51                rgrlen =0;
52        ARX::bayes_weighted(yt - g->eval(cond), empty_vec, w);
53        dimc = dimc_store;
54                rgrlen=rgrlen_store;
55    };
56    //!@}
57
58    /*! UI for ARXg estimator
59
60    \code
61    class = 'ARXg';
62    yrv   = RV({names_of_dt} )                 // description of output variables
63    rgr   = RV({names_of_regressors}, [-1,-2]} // description of regressor variables
64    constant = 1;                              // 0/1 switch if the constant term is modelled or not
65    g     = {class='my_function',...}          // function transforming regressor
66
67    --- optional ---
68    prior = {class='egiw',...};                // Prior density, when given default is used instead
69    alternative = {class='egiw',...};          // Alternative density in stabilized estimation, when not given prior is used
70
71    frg   = 1.0;                               // forgetting, default frg=1.0
72
73    rv    = RV({names_of_parameters}}          // description of parametetr names
74    \endcode
75    */
76    void from_setting ( const Setting &set ) {
77        ARX::from_setting(set);
78        g=UI::build<fnc>(set,"g",UI::compulsory);
79    }
80
81    void validate() {
82        ARX::validate();//if dimc not set set it from V
83        bdm_assert(g->dimension()==dimensiony(),"incompatible g");
84        bdm_assert(g->dimensionc()==dimensionc(),"incompatible g");
85    }
86
87    void to_setting ( Setting &set ) const
88    {
89        ARX::to_setting( set ); // takes care of rv, yrv, rvc
90        UI::save(g,set,"g");
91    }
92};
93UIREGISTER ( ARXg );
94SHAREDPTR ( ARXg );
95
96};
97#endif // AREX_H
98
Note: See TracBrowser for help on using the browser.