Changeset 176

Show
Ignore:
Timestamp:
10/09/08 11:32:12 (16 years ago)
Author:
smidl
Message:

Corrections to mixtures & merger

Files:
5 added
2 removed
7 modified

Legend:

Unmodified
Added
Removed
  • bdm/CMakeLists.txt

    r168 r176  
    22 
    33SET(BdmMath math/libDC.cpp math/libDC.h math/chmat.cpp math/chmat.h) 
    4 SET(BdmStat stat/libDS.cpp stat/libDS.h stat/libFN.cpp stat/libFN.h stat/libBM.cpp stat/libBM.h stat/libEF.cpp stat/libEF.h stat/loggers.cpp stat/loggers.h stat/emix.cpp stat/emix.h stat/merger.cpp) 
    5 SET(BdmEstim estim/libKF.cpp estim/libKF.h estim/libPF.cpp estim/libPF.h estim/arx.cpp estim/arx.h estim/mixef.cpp estim/mixef.h) 
     4SET(BdmStat stat/libDS.cpp stat/libDS.h stat/libFN.cpp stat/libFN.h stat/libBM.cpp stat/libBM.h stat/libEF.cpp stat/libEF.h stat/loggers.cpp stat/loggers.h stat/emix.cpp stat/emix.h) 
     5SET(BdmEstim estim/libKF.cpp estim/libKF.h estim/libPF.cpp estim/libPF.h estim/arx.cpp estim/arx.h estim/mixef.cpp estim/mixef.h estim/merger.cpp) 
    66SET(BdmUI userinfo.cpp userinfo.h) 
    77 
  • bdm/stat/emix.h

    r175 r176  
    7878        Additional parameter overlap is left for future use. Do not set to true for mprod. 
    7979        */ 
    80         mprod ( Array<mpdf*> mFacs): compositepdf(mFacs), mpdf(getrv(true),RV()), rvcinds(n), epdfs(n) 
     80        mprod ( Array<mpdf*> mFacs): compositepdf(mFacs), mpdf(getrv(true),RV()), epdfs(n), rvcinds(n) 
    8181        {       setrvc(rv,rvc); 
    8282                setrvcinrv(rvc,rvcinds); 
  • bdm/stat/libBM.cpp

    r175 r176  
    9191// } 
    9292 
    93 RV RV::subselect ( ivec ind ) const { 
     93RV RV::subselect (const ivec &ind ) const { 
    9494        RV ret; 
    9595        ret.init ( ids ( ind ), names ( to_Arr ( ind ) ), sizes ( ind ), times ( ind ) ); 
     
    9999void RV::t ( int delta ) { times += delta;} 
    100100 
    101 RV RV::operator() ( ivec ind ) const { 
     101RV RV::operator() (const ivec &ind ) const { 
    102102        RV ret; 
    103103        if ( ind.length() >0 ) { 
     
    140140} 
    141141 
    142 ivec RV::dataind ( RV rv2 ) const { 
     142ivec RV::dataind (const RV &rv2 ) const { 
    143143        ivec res ( 0 ); 
    144144        if ( rv2.count()>0 ) { 
     
    155155} 
    156156 
    157 RV RV::subt ( const RV rv2 ) const { 
     157RV RV::subt ( const RV &rv2 ) const { 
    158158        ivec res = this->findself ( rv2 ); // nonzeros 
    159159        ivec valid = itpp::find ( res == -1 ); //-1 => value not found => it remains 
  • bdm/stat/libBM.h

    r175 r176  
    8080        bool add ( const RV &rv2 ); 
    8181        //! Subtract  another variable from the current one 
    82         RV subt ( const RV rv2 ) const; 
     82        RV subt ( const RV &rv2 ) const; 
    8383        //! Select only variables at indeces ind 
    84         RV subselect ( ivec ind ) const; 
     84        RV subselect ( const ivec &ind ) const; 
    8585        //! Select only variables at indeces ind 
    86         RV operator() ( ivec ind ) const; 
     86        RV operator() ( const ivec &ind ) const; 
    8787        //! Shift \c time shifted by delta. 
    8888        void t ( int delta ); 
     
    9090        str tostr() const; 
    9191        //! generate indeces into \param crv data vector that form data vector of self. 
    92         ivec dataind(RV crv) const; 
     92        ivec dataind(const RV &crv) const; 
    9393 
    9494        //!access function 
     
    103103        //!access function 
    104104        std::string name ( int at ) {return names ( at );}; 
     105         
     106        //!access function 
     107        void set_id ( int at, int id0 ) {ids ( at )=id0;}; 
     108        //!access function 
     109        void set_size ( int at, int size0 ) {sizes ( at )=size0; tsize=sum(sizes);}; 
     110        //!access function 
     111        void set_time ( int at, int time0 ) {times ( at )=time0;}; 
     112 
    105113        //!Assign unused ids to this rv  
    106114        void newids(); 
     
    160168 
    161169        //! Compute log-probability of multiple values argument \c val 
    162         virtual vec evalpdflog ( const mat &Val ) const { 
     170        virtual vec evalpdflog_m ( const mat &Val ) const { 
    163171                vec x ( Val.cols() ); 
    164172                for ( int i=0;i<Val.cols();i++ ) {x ( i ) =evalpdflog( Val.get_col(i) ) ;} 
     
    318326        //! I.e. marginal likelihood of the data with the posterior integrated out. 
    319327        virtual double logpred(const vec &dt)const{it_error("Not implemented");return 0.0;} 
     328        //! Matrix version of logpred 
     329        vec logpred_m(const mat &dt)const{vec tmp(dt.cols());for(int i=0;i<dt.cols();i++){tmp(i)=logpred(dt.get_col(i));}return tmp;} 
    320330         
    321331        //! Destructor for future use; 
  • bdm/stat/libEF.h

    r173 r176  
    9191        void bayes ( const vec &dt ); 
    9292        //!Flatten the posterior 
    93         virtual void flatten ( BMEF * B) {it_error ( "Not implemented" );} 
     93        virtual void flatten ( BMEF * B ) {it_error ( "Not implemented" );} 
    9494}; 
    9595 
     
    206206        vec sample() const {it_error ( "Not implemented" );return vec_1 ( 0.0 );}; 
    207207        vec mean() const {return beta/sum ( beta );}; 
    208         //! In this instance, val= [theta, r]. For multivariate instances, it is stored columnwise val = [theta_1 theta_2 ... r_1 r_2 ] 
     208        //! In this instance, val is ... 
    209209        double evalpdflog_nn ( const vec &val ) const {return ( beta-1 ) *log ( val );}; 
    210210        double lognc () const { 
     
    216216        //!access function 
    217217        vec& _beta() {return beta;} 
     218        //!Set internal parameters 
     219        void set_parameters(const vec &beta0){ 
     220                if(beta0.length()!=beta.length()){ 
     221                        it_assert_debug(rv.length()==1,"Undefined"); 
     222                        rv.set_size(0,beta0.length()); 
     223                } 
     224                beta= beta0; 
     225        } 
    218226}; 
    219227 
     
    239247                eDirich pred ( est ); 
    240248                vec &beta = pred._beta(); 
    241                  
     249 
    242250                double lll; 
    243251                if ( frg<1.0 ) 
     
    250258                return pred.lognc()-lll; 
    251259        } 
    252         void flatten (BMEF* B ) { 
    253                 eDirich* E=dynamic_cast<eDirich*>(B); 
     260        void flatten ( BMEF* B ) { 
     261                eDirich* E=dynamic_cast<eDirich*> ( B ); 
    254262                // sum(beta) should be equal to sum(B.beta) 
    255263                const vec &Eb=E->_beta(); 
    256                 est.pow ( sum(beta)/sum(Eb) ); 
     264                est.pow ( sum ( beta ) /sum ( Eb ) ); 
     265                if ( evalll ) {last_lognc=est.lognc();} 
     266        } 
     267        const epdf& _epdf() const {return est;}; 
     268        void set_parameters ( const vec &beta0 ) { 
     269                est.set_parameters(beta0); 
     270                rv = est._rv(); 
    257271                if(evalll){last_lognc=est.lognc();} 
    258272        } 
    259         const epdf& _epdf() const {return est;}; 
    260         //!access funct 
    261273}; 
    262274 
  • mpdm/merg_pred.cpp

    r162 r176  
    22#include <stat/libEF.h> 
    33#include <stat/loggers.h> 
    4 #include <stat/merger.h> 
     4//#include <stat/merger.h> 
    55using namespace itpp; 
    66 
  • tests/merger_test.cpp

    r168 r176  
    11#include <itpp/itbase.h> 
    22#include <stat/libEF.h> 
    3 #include <stat/merger.h> 
     3#include <estim/merger.h> 
    44 
    55using namespace itpp; 
     
    1111int main() { 
    1212 
    13         RV x("{x }","1"); 
    14         RV y("{y }","1"); 
    15         RV z("{z }","1"); 
     13        RV x ( "{x }","1" ); 
    1614 
    17         mlnorm<fsqmat> fx(x,y); 
    18         mlnorm<fsqmat> fy(x,z); 
     15        enorm<fsqmat> f1 ( x ); 
     16        enorm<fsqmat> f2 ( x ); 
    1917 
    20         fx.set_parameters("1.5",mat("1")); 
    21         fy.set_parameters("1.3",mat("1")); 
    22          
    23         Array<mpdf* > A(2);  
    24         A(0)=&fx; 
    25         A(1)=&fy; 
     18        f1.set_parameters ( "-5",mat ( "2" ) ); 
     19        f2.set_parameters ( "5",mat ( "10" ) ); 
    2620 
    27         merger M(A); 
     21        Array<mpdf* > A ( 2 ); 
     22        A ( 0 ) =&mepdf(f1); 
     23        A ( 1 ) =&mepdf(f2); 
     24 
     25        int Npoints=100; 
     26        mat x_grid ( 1,Npoints ); 
     27        x_grid.set_row ( 0,linspace ( -10.0, 10.0 ) ); 
     28 
     29        vec l_f1=f1.evalpdflog_m ( x_grid ); 
     30 
     31        vec l_f2=f2.evalpdflog_m ( x_grid ); 
     32        mat lW(2,Npoints); 
     33        lW.set_row(0, l_f1); 
     34        lW.set_row(1, l_f2 ); 
     35 
     36        merger M ( A ); 
     37        cout << M.lognorm_merge(lW)<<endl; 
    2838//      eEmp res=M.merge(100); 
    29          
    30 //      cout << res.mean() << endl; 
    31         //Exit program: 
    32         return 0; 
     39 
    3340 
    3441}