| 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 | |
|---|
| 19 | using namespace itpp; |
|---|
| 20 | |
|---|
| 21 | /*! |
|---|
| 22 | * \brief Class representing variables, most often random variables |
|---|
| 23 | |
|---|
| 24 | * More?... |
|---|
| 25 | */ |
|---|
| 26 | class RV { |
|---|
| 27 | int len; |
|---|
| 28 | ivec ids; |
|---|
| 29 | ivec sizes; |
|---|
| 30 | ivec times; |
|---|
| 31 | ivec obs; |
|---|
| 32 | Array<std::string> names; |
|---|
| 33 | |
|---|
| 34 | private: |
|---|
| 35 | void init ( ivec in_ids, Array<std::string> in_names, ivec in_sizes, ivec in_times, ivec in_obs ); |
|---|
| 36 | public: |
|---|
| 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 | //! Printing output e.g. for debugging. |
|---|
| 42 | friend std::ostream &operator<< ( std::ostream &os, const RV &rv ); |
|---|
| 43 | |
|---|
| 44 | //! Find indexes of another rv in self |
|---|
| 45 | ivec rvfind(RV rv2); |
|---|
| 46 | //! Add (concat) another variable to the current one |
|---|
| 47 | RV rvadd(RV rv2); |
|---|
| 48 | //! Subtract another variable from the current one |
|---|
| 49 | RV rvsubt(RV rv2); |
|---|
| 50 | //! Select only variables at indeces ind |
|---|
| 51 | RV rvsubselect(ivec ind); |
|---|
| 52 | //! Select only variables at indeces ind |
|---|
| 53 | RV operator()(ivec ind); |
|---|
| 54 | }; |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | |
|---|
| 58 | |
|---|
| 59 | //! Class representing function of variables |
|---|
| 60 | class fnc { |
|---|
| 61 | RV rv; |
|---|
| 62 | }; |
|---|
| 63 | |
|---|
| 64 | //! Bayesian Model of the world, i.e. all uncertainty is modeled by probabilities. |
|---|
| 65 | class BM { |
|---|
| 66 | public: |
|---|
| 67 | //!Logarithm of marginalized data likelihood. |
|---|
| 68 | double ll; |
|---|
| 69 | |
|---|
| 70 | /*! \brief Incremental Bayes rule |
|---|
| 71 | @param dt vector of input data |
|---|
| 72 | @param evall If true, the filter will compute likelihood of the data record and store it in \c ll |
|---|
| 73 | */ |
|---|
| 74 | virtual void bayes ( const vec &dt, bool evall=true ) = 0; |
|---|
| 75 | //! Batch Bayes rule (columns of Dt are observations) |
|---|
| 76 | void bayes ( mat Dt ); |
|---|
| 77 | }; |
|---|
| 78 | |
|---|
| 79 | //! Probability density function with numerical statistics, e.g. posterior density. |
|---|
| 80 | class epdf { |
|---|
| 81 | RV rv; |
|---|
| 82 | public: |
|---|
| 83 | //! Returns the required moment of the epdf |
|---|
| 84 | virtual vec moment ( const int order = 1 ); |
|---|
| 85 | }; |
|---|
| 86 | |
|---|
| 87 | //! Conditional probability density, e.g. modeling some dependencies. |
|---|
| 88 | class mpdf { |
|---|
| 89 | //! modeled random variable |
|---|
| 90 | RV rv; |
|---|
| 91 | //! random variable in condition |
|---|
| 92 | RV rvc; |
|---|
| 93 | public: |
|---|
| 94 | |
|---|
| 95 | //! Returns the required moment of the epdf |
|---|
| 96 | virtual fnc moment ( const int order = 1 ); |
|---|
| 97 | }; |
|---|
| 98 | |
|---|
| 99 | #endif // BM_H |
|---|