work/mixpp/bdm/stat/libEF.h

Go to the documentation of this file.
00001 
00013 #ifndef EF_H
00014 #define EF_H
00015 
00016 #include <itpp/itbase.h>
00017 #include "../math/libDC.h"
00018 #include "libBM.h"
00019 //#include <std>
00020 
00021 using namespace itpp;
00022 
00028 class eEF : public epdf {
00029 
00030 public:
00031         virtual void tupdate( double phi, mat &vbar, double nubar ) {};
00032         virtual void dupdate( mat &v,double nu=1.0 ) {};
00033 };
00034 
00035 class mEF : public mpdf {
00036 
00037 public:
00038 
00039 };
00040 
00046 template<class sq_T>
00047 class enorm : public eEF {
00048         int dim;
00049         vec mu;
00050         sq_T R;
00051 public:
00052         enorm( RV &rv, vec &mu, sq_T &R );
00053         enorm();
00054         void tupdate( double phi, mat &vbar, double nubar );
00055         void dupdate( mat &v,double nu=1.0 );
00056         vec sample();
00057         mat sample(int N);
00058         double eval( const vec &val );
00059         Normal_RNG RNG;
00060 };
00061 
00065 template<class sq_T>
00066 class mlnorm : public mEF {
00067         enorm<sq_T> epdf;
00068         mat A;
00069 public:
00071         mlnorm( RV &rv,RV &rvc, mat &A, sq_T &R );
00073         vec samplecond( vec &cond, double &lik );
00074         mat samplecond( vec &cond, vec &lik, int n );
00075         void condition( vec &cond );
00076 };
00077 
00079 
00080 template<class sq_T>
00081 enorm<sq_T>::enorm( RV &rv, vec &mu0, sq_T &R0 ) {
00082         dim = rv.count();
00083         mu = mu0;
00084         R = R0;
00085 };
00086 
00087 template<class sq_T>
00088 void enorm<sq_T>::dupdate( mat &v, double nu ) {
00089         //
00090 };
00091 
00092 template<class sq_T>
00093 void enorm<sq_T>::tupdate( double phi, mat &vbar, double nubar ) {
00094         //
00095 };
00096 
00097 template<class sq_T>
00098 vec enorm<sq_T>::sample() {
00099         vec x( dim );
00100         RNG.sample_vector( dim,x );
00101         vec smp = R.sqrt_mult( x );
00102 
00103         smp += mu;
00104         return smp;
00105 };
00106 
00107 template<class sq_T>
00108 mat enorm<sq_T>::sample( int N ) {
00109         mat X( dim,N );
00110         vec x( dim );
00111         vec pom;
00112         int i;
00113         for ( i=0;i<N;i++ ) {
00114                 RNG.sample_vector( dim,x );
00115                 pom = R.sqrt_mult( x );
00116                 pom +=mu;
00117                 X.set_col( i, pom);
00118         }
00119         return X;
00120 };
00121 
00122 template<class sq_T>
00123 double enorm<sq_T>::eval( const vec &val ) {
00124         //
00125 };
00126 
00127 
00128 template<class sq_T>
00129 enorm<sq_T>::enorm() {};
00130 
00131 template<class sq_T>
00132 mlnorm<sq_T>::mlnorm( RV &rv,RV &rvc, mat &A, sq_T &R ) {
00133         int dim = rv.count();
00134         vec mu( dim );
00135 
00136         epdf = enorm<sq_T>( rv,mu,R );
00137 }
00138 
00139 template<class sq_T>
00140 vec mlnorm<sq_T>::samplecond( vec &cond, double &lik ) {
00141         this->condition( cond );
00142         vec smp = epdf.sample();
00143         lik = epdf.eval( smp );
00144         return smp;
00145 }
00146 
00147 template<class sq_T>
00148 mat mlnorm<sq_T>::samplecond( vec &cond, vec &lik, int n ) {
00149         int i;
00150         int dim = rv.count();
00151         mat Smp( dim,n );
00152         vec smp( dim );
00153         this->condition( cond );
00154         for ( i=0; i<dim; i++ ) {
00155                 smp = epdf.sample();
00156                 lik( i ) = epdf.eval( smp );
00157                 Smp.set_col( i ,smp );
00158         }
00159         return Smp;
00160 }
00161 
00162 template<class sq_T>
00163 void mlnorm<sq_T>::condition( vec &cond ) {
00164         epdf.mu = A*cond;
00165 //R is already assigned;
00166 }
00167 
00168 #endif //EF_H

Generated on Fri Feb 15 18:57:37 2008 for mixpp by  doxygen 1.5.3