root/bdm/stat/libEF.h @ 14

Revision 14, 2.9 kB (checked in by smidl, 16 years ago)

restructuring

  • Property svn:eol-style set to native
Line 
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 "libDC.h"
18#include "libBM.h"
19//#include <std>
20
21using namespace itpp;
22
23/*!
24* \brief General conjugate exponential family posterior density.
25
26* More?...
27*/
28class eEF : public epdf {
29
30public:
31        virtual void tupdate( double phi, mat &vbar, double nubar ) {};
32        virtual void dupdate( mat &v,double nu=1.0 ) {};
33};
34
35class mEF : public mpdf {
36
37public:
38
39};
40
41/*!
42* \brief General exponential family density
43
44* More?...
45*/
46template<class sq_T>
47class enorm : public eEF {
48        int dim;
49        vec mu;
50        sq_T R;
51public:
52        enorm( RV &rv, vec &mu, sq_T &R );
53        enorm();
54        void tupdate( double phi, mat &vbar, double nubar );
55        void dupdate( mat &v,double nu=1.0 );
56        vec sample();
57        mat sample(int N);
58        double eval( const vec &val );
59        Normal_RNG RNG;
60};
61
62/*!
63 \brief
64*/
65template<class sq_T>
66class mlnorm : public mEF {
67        enorm<sq_T> epdf;
68        mat A;
69public:
70        //! Constructor
71        mlnorm( RV &rv,RV &rvc, mat &A, sq_T &R );
72        //!Generate one sample of the posterior
73        vec samplecond( vec &cond, double &lik );
74        mat samplecond( vec &cond, vec &lik, int n );
75        void condition( vec &cond );
76};
77
78////////////////////////
79
80template<class sq_T>
81enorm<sq_T>::enorm( RV &rv, vec &mu0, sq_T &R0 ) {
82        dim = rv.count();
83        mu = mu0;
84        R = R0;
85};
86
87template<class sq_T>
88void enorm<sq_T>::dupdate( mat &v, double nu ) {
89        //
90};
91
92template<class sq_T>
93void enorm<sq_T>::tupdate( double phi, mat &vbar, double nubar ) {
94        //
95};
96
97template<class sq_T>
98vec enorm<sq_T>::sample() {
99        vec x( dim );
100        RNG.sample_vector( dim,x );
101        vec smp = R.sqrt_mult( x );
102
103        smp += mu;
104        return smp;
105};
106
107template<class sq_T>
108mat enorm<sq_T>::sample( int N ) {
109        mat X( dim,N );
110        vec x( dim );
111        vec pom;
112        int i;
113        for ( i=0;i<N;i++ ) {
114                RNG.sample_vector( dim,x );
115                pom = R.sqrt_mult( x );
116                pom +=mu;
117                X.set_col( i, pom);
118        }
119        return X;
120};
121
122template<class sq_T>
123double enorm<sq_T>::eval( const vec &val ) {
124        //
125};
126
127
128template<class sq_T>
129enorm<sq_T>::enorm() {};
130
131template<class sq_T>
132mlnorm<sq_T>::mlnorm( RV &rv,RV &rvc, mat &A, sq_T &R ) {
133        int dim = rv.count();
134        vec mu( dim );
135
136        epdf = enorm<sq_T>( rv,mu,R );
137}
138
139template<class sq_T>
140vec mlnorm<sq_T>::samplecond( vec &cond, double &lik ) {
141        this->condition( cond );
142        vec smp = epdf.sample();
143        lik = epdf.eval( smp );
144        return smp;
145}
146
147template<class sq_T>
148mat mlnorm<sq_T>::samplecond( vec &cond, vec &lik, int n ) {
149        int i;
150        int dim = rv.count();
151        mat Smp( dim,n );
152        vec smp( dim );
153        this->condition( cond );
154        for ( i=0; i<dim; i++ ) {
155                smp = epdf.sample();
156                lik( i ) = epdf.eval( smp );
157                Smp.set_col( i ,smp );
158        }
159        return Smp;
160}
161
162template<class sq_T>
163void mlnorm<sq_T>::condition( vec &cond ) {
164        epdf.mu = A*cond;
165//R is already assigned;
166}
167
168#endif //EF_H
Note: See TracBrowser for help on using the browser.