- Main Page
- Related Pages
- Classes
- Files

# work/git/mixpp/bdm/stat/merger.h

Go to the documentation of this file.

    00001
    00013 #ifndef MER_H
    00014 #define MER_H
    00015
    00016 #include <itpp/itbase.h>
    00017 #include "libBM.h"
    00018 #include "libEF.h"
    00019 #include "emix.h"
    00020
    00021 using namespace itpp;
    00022 using std::string;
    00023
    00030 class merger : public mprod{
    00031 protected:
    00033         enorm<fsqmat> condpdf;
    00035         Array<ivec> overlaps;
    00036 public:
    00038         merger (const Array<mpdf*> &in_sources) : mprod(in_sources,true), condpdf(rvc), overlaps(rv.count()) {
    00039                 if (rvc.count()>0) {
    00040                         vec mu = zeros(rvc.count());
    00041                         mat R = 100*eye(rvc.count());
    00042                         condpdf.set_parameters(mu,R);
    00043                 }
    00044                 for (int i=0;i<rv.count();i++){ // cycle over rv
    00045                         ivec tmp(0);
    00046                         for (int j=0;j<n;j++){//cycle over rvinds
    00047                                 ivec id=itpp::find(rvinds(j)==i);
    00048                                 tmp=concat(tmp,id); // add i to tmp if found
    00049                         }
    00050                         overlaps(i)=tmp;
    00051                 }
    00052         }
    00055 /*      vec sample(double &w, const vec &smp0){
    00056                 // result
    00057                 vec smp=smp0;
    00058                 vec cond=condpdf.sample(); // Just like in samplecond, here it is not given!
    00059                 // temporary
    00060                 mat smpi=zeros(rv.count()+rvc.count(), n);
    00061                 vec condi;
    00062                 vec ll(n);
    00063
    00064                 // Consider arithmetic mean as a proposal density
    00065                 ll = 0;
    00066                 for ( int i = ( n - 1 );i >= 0;i-- ) {
    00067                         if ( rvcinds ( i ).length() > 0 ) {
    00068                                 condi = zeros ( rvcinrv.length() + rvcinds.length() );
    00069                                 // copy data in condition
    00070                                 set_subvector ( condi,rvcinds ( i ), cond );
    00071                                 // copy data in already generated sample
    00072                                 set_subvector ( condi,rvcinrv ( i ), smp );
    00073
    00074                                 mpdfs ( i )->condition ( condi );
    00075                         }
    00076                         smpi.set_col(i, epdfs ( i )->sample());
    00077                         // add ith likelihood contribution
    00078                         ll+=epdfs(i)->evalpdflog(smpi);
    00079                 }
    00080                 // Now lets analyze samples smpi
    00081                 for (int i=0;i<rv.count();i++){
    00082                         // number of components
    00083                         int noc = overlaps(i).length();
    00084                         if (noc<2) { // only one sample in this dimension, take it
    00085                                 smp(i) = smpi(i,overlaps(i)(0));
    00086                         }
    00087                         else {
    00088                                 //pick dimension
    00089                                 double unis = UniRNG.sample();
    00090                                 dim = 0;
    00091                                 while(unis<(dim+1)/noc) {dim++;} //
    00092                                 //in dim we now have randomly picked dimension
    00093                                 smp(i) = smpi(i,overlaps(i)(dim));
    00094                         }
    00095                 }
    00096
    00097                 // now we have sample how to evaluate weight?
    00098                 return smp;
    00099
    00100                 // copied from mprod.sample
    00101         };*/
    00102 //      project
    00104         virtual ~merger() {};
    00105 };
    00106
    00107
    00108 #endif // MER_H