root/libEF.h @ 12

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

opravy v libDC (stale nefunkcni)

  • Property svn:eol-style set to native
RevLine 
[8]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>
[12]17#include "libDC.h"
18#include "libBM.h"
[8]19//#include <std>
20
21using namespace itpp;
22
23/*!
24* \brief General conjugate exponential family posterior density.
25
26* More?...
27*/
[12]28class eEF : public epdf {
[8]29
30public:
[12]31        virtual void tupdate( double phi, mat &vbar, double nubar ) {};
32        virtual void dupdate( mat &v,double nu=1.0 ) {};
[8]33};
34
[12]35class mEF : public mpdf {
[8]36
37public:
38
39};
40
41/*!
42* \brief General exponential family density
43
44* More?...
45*/
46template<class sq_T>
47class enorm : public eEF {
[12]48        int dim;
[8]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();
[12]57        mat sample(int N);
[8]58        double eval( const vec &val );
[12]59        Normal_RNG RNG;
[8]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 ) {
[12]82        dim = rv.count();
[8]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() {
[12]99        vec x( dim );
100        RNG.sample_vector( dim,x );
101        vec smp = R.sqrt_mult( x );
102
103        smp += mu;
104        return smp;
[8]105};
106
107template<class sq_T>
[12]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>
[8]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 ) {
[12]133        int dim = rv.count();
[8]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();
[12]143        lik = epdf.eval( smp );
[8]144        return smp;
145}
146
147template<class sq_T>
148mat mlnorm<sq_T>::samplecond( vec &cond, vec &lik, int n ) {
149        int i;
[12]150        int dim = rv.count();
[8]151        mat Smp( dim,n );
[12]152        vec smp( dim );
[8]153        this->condition( cond );
154        for ( i=0; i<dim; i++ ) {
155                smp = epdf.sample();
[12]156                lik( i ) = epdf.eval( smp );
157                Smp.set_col( i ,smp );
[8]158        }
159        return Smp;
160}
161
162template<class sq_T>
[12]163void mlnorm<sq_T>::condition( vec &cond ) {
164        epdf.mu = A*cond;
165//R is already assigned;
[8]166}
167
168#endif //EF_H
Note: See TracBrowser for help on using the browser.