root/bdm/stat/libBM.h @ 18

Revision 18, 4.1 kB (checked in by smidl, 16 years ago)

update

  • Property svn:eol-style set to native
Line 
1/*!
2  \file
3  \brief Bayesian Models (bm) that use Bayes rule to learn from observations
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 BM_H
14#define BM_H
15
16#include <itpp/itbase.h>
17//#include <std>
18
19using namespace itpp;
20
21/*!
22* \brief Class representing variables, most often random variables
23
24* More?...
25*/
26class RV {
27        int size,len;
28        ivec ids;
29        ivec sizes;
30        ivec times;
31        ivec obs;
32        Array<std::string> names;
33
34private:
35        void init ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times, ivec in_obs );
36public:
37        //! Full constructor which is called by the others
38        RV ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times, ivec in_obs );
39        //! default constructor
40        RV ( ivec ids );
41        //! Empty constructor will be set later
42        RV ();
43       
44        //! Printing output e.g. for debugging.
45        friend std::ostream &operator<< ( std::ostream &os, const RV &rv );
46
47        //! Return length (number of scalars) of the RV.
48        int count() {return size;}
49        //TODO why not inline and later??
50       
51        //! Find indexes of another rv in self
52        ivec find(RV rv2);
53        //! Add (concat) another variable to the current one
54        RV add(RV rv2);
55        //! Subtract  another variable from the current one
56        RV subt(RV rv2);
57        //! Select only variables at indeces ind
58        RV subselect(ivec ind);
59        //! Select only variables at indeces ind
60        RV operator()(ivec ind);
61        //! Generate new \c RV with \c time shifted by delta.
62        void t(int delta);
63};
64
65
66
67
68//! Class representing function of variables
69class fnc {
70        RV rv;
71};
72
73//! Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities.
74class BM {
75public:
76        //!Logarithm of marginalized data likelihood.
77        double ll;
78
79        /*! \brief Incremental Bayes rule
80        @param dt vector of input data
81        @param evall If true, the filter will compute likelihood of the data record and store it in \c ll
82        */
83        virtual void bayes ( const vec &dt, bool evall=true ) = 0;
84        //! Batch Bayes rule (columns of Dt are observations)
85        void bayes ( mat Dt );
86};
87
88//! Probability density function with numerical statistics, e.g. posterior density.
89class epdf {
90        RV rv;
91public:
92        //! Returns the required moment of the epdf
93//      virtual vec moment ( const int order = 1 );
94        //! Returns a sample from the density, $x \sim epdf(rv)$
95        virtual vec sample (){};
96        virtual double eval(const vec &val){};
97};
98
99//! Conditional probability density, e.g. modeling some dependencies.
100class mpdf {
101        //! modeled random variable
102        RV rv;
103        //! random variable in condition
104        RV rvc;
105public:
106
107        //! Returns the required moment of the epdf
108//      virtual fnc moment ( const int order = 1 );
109        //! Returns a sample from the density conditioned on \c cond, $x \sim epdf(rv|cond)$
110        virtual vec samplecond (vec &cond, double lik){};
111        virtual void condition (vec &cond){};
112};
113
114/*! \brief Abstract class for discrete-time sources of data.
115
116The class abstracts operations of: (i) data aquisition, (ii) data-preprocessing, (iii) scaling of data, and (iv) data resampling from the task of estimation and control.
117Moreover, for controlled systems, it is able to receive the desired control action and perform it in the next step. (Or as soon as possible).
118
119*/
120class DS {
121        //!Observed variables, returned by \c getdata().
122        RV Drv; 
123        //!Action variables, accepted by \c write().
124        RV Urv; //
125public:
126        //! Returns full vector of observed data
127        void getdata(vec &dt);
128        //! Returns data records at indeces.
129        void getdata(vec &dt, ivec &indeces);
130        //! Accepts action variable and schedule it for application.
131        void write(vec &ut);
132        //! Accepts action variables at specific indeces       
133        void write(vec &ut, ivec &indeces);
134        /*! \brief Method that assigns random variables to the datasource.
135        Typically, the datasource will be constructed without knowledge of random variables. This method will associate existing variables with RVs.
136       
137        (Inherited from m3k, may be deprecated soon).
138        */
139        void linkrvs(RV &drv, RV &urv);
140       
141        //! Moves from $t$ to $t+1$, i.e. perfroms the actions and reads response of the system.
142        void step();
143};
144
145
146#endif // BM_H
Note: See TracBrowser for help on using the browser.