1 | /*! |
---|
2 | \file |
---|
3 | \brief Probability distributions for Exponential Family models. |
---|
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 EF_H |
---|
14 | #define EF_H |
---|
15 | |
---|
16 | #include <itpp/itbase.h> |
---|
17 | //#include <std> |
---|
18 | |
---|
19 | using namespace itpp; |
---|
20 | |
---|
21 | /*! |
---|
22 | * \brief General conjugate exponential family posterior density. |
---|
23 | |
---|
24 | * More?... |
---|
25 | */ |
---|
26 | class eEF :public epdf { |
---|
27 | |
---|
28 | public: |
---|
29 | virtual void tupdate( double phi, mat &vbar, double nubar ){}; |
---|
30 | virtual void dupdate( mat &v,double nu=1.0 ){}; |
---|
31 | }; |
---|
32 | |
---|
33 | class mEF :public mpdf { |
---|
34 | |
---|
35 | public: |
---|
36 | |
---|
37 | }; |
---|
38 | |
---|
39 | /*! |
---|
40 | * \brief General exponential family density |
---|
41 | |
---|
42 | * More?... |
---|
43 | */ |
---|
44 | template<class sq_T> |
---|
45 | class enorm : public eEF { |
---|
46 | vec mu; |
---|
47 | sq_T R; |
---|
48 | public: |
---|
49 | enorm( RV &rv, vec &mu, sq_T &R ); |
---|
50 | enorm(); |
---|
51 | void tupdate( double phi, mat &vbar, double nubar ); |
---|
52 | void dupdate( mat &v,double nu=1.0 ); |
---|
53 | vec sample(); |
---|
54 | double eval( const vec &val ); |
---|
55 | |
---|
56 | }; |
---|
57 | |
---|
58 | /*! |
---|
59 | \brief |
---|
60 | */ |
---|
61 | template<class sq_T> |
---|
62 | class mlnorm : public mEF { |
---|
63 | enorm<sq_T> epdf; |
---|
64 | mat A; |
---|
65 | public: |
---|
66 | //! Constructor |
---|
67 | mlnorm( RV &rv,RV &rvc, mat &A, sq_T &R ); |
---|
68 | //!Generate one sample of the posterior |
---|
69 | vec samplecond( vec &cond, double &lik ); |
---|
70 | mat samplecond( vec &cond, vec &lik, int n ); |
---|
71 | void condition( vec &cond ); |
---|
72 | }; |
---|
73 | |
---|
74 | //////////////////////// |
---|
75 | |
---|
76 | template<class sq_T> |
---|
77 | enorm<sq_T>::enorm( RV &rv, vec &mu0, sq_T &R0 ) { |
---|
78 | mu = mu0; |
---|
79 | R = R0; |
---|
80 | }; |
---|
81 | |
---|
82 | template<class sq_T> |
---|
83 | void enorm<sq_T>::dupdate( mat &v, double nu ) { |
---|
84 | // |
---|
85 | }; |
---|
86 | |
---|
87 | template<class sq_T> |
---|
88 | void enorm<sq_T>::tupdate( double phi, mat &vbar, double nubar ) { |
---|
89 | // |
---|
90 | }; |
---|
91 | |
---|
92 | template<class sq_T> |
---|
93 | vec enorm<sq_T>::sample() { |
---|
94 | // |
---|
95 | }; |
---|
96 | |
---|
97 | template<class sq_T> |
---|
98 | double enorm<sq_T>::eval( const vec &val ) { |
---|
99 | // |
---|
100 | }; |
---|
101 | |
---|
102 | |
---|
103 | template<class sq_T> |
---|
104 | enorm<sq_T>::enorm() {}; |
---|
105 | |
---|
106 | template<class sq_T> |
---|
107 | mlnorm<sq_T>::mlnorm( RV &rv,RV &rvc, mat &A, sq_T &R ) { |
---|
108 | int dim = rv.length(); |
---|
109 | vec mu( dim ); |
---|
110 | |
---|
111 | epdf = enorm<sq_T>( rv,mu,R ); |
---|
112 | } |
---|
113 | |
---|
114 | template<class sq_T> |
---|
115 | vec mlnorm<sq_T>::samplecond( vec &cond, double &lik ) { |
---|
116 | this->condition( cond ); |
---|
117 | vec smp = epdf.sample(); |
---|
118 | lik = epdf.eval(smp); |
---|
119 | return smp; |
---|
120 | } |
---|
121 | |
---|
122 | template<class sq_T> |
---|
123 | mat mlnorm<sq_T>::samplecond( vec &cond, vec &lik, int n ) { |
---|
124 | int i; |
---|
125 | int dim = rv.length(); |
---|
126 | mat Smp( dim,n ); |
---|
127 | vec smp( dim); |
---|
128 | this->condition( cond ); |
---|
129 | for ( i=0; i<dim; i++ ) { |
---|
130 | smp = epdf.sample(); |
---|
131 | lik(i) = epdf.eval(smp); |
---|
132 | Smp.set_col( i ,smp); |
---|
133 | } |
---|
134 | return Smp; |
---|
135 | } |
---|
136 | |
---|
137 | template<class sq_T> |
---|
138 | void mlnorm<sq_T>::condition( vec &cond) { |
---|
139 | } |
---|
140 | |
---|
141 | #endif //EF_H |
---|