Changeset 181 for bdm/stat

Show
Ignore:
Timestamp:
10/15/08 19:11:17 (16 years ago)
Author:
smidl
Message:

Regenerated doc

Location:
bdm/stat
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • bdm/stat/emix.cpp

    r178 r181  
    3131} 
    3232 
    33 // mprod::mprod ( Array<mpdf*> mFacs, bool overlap) : mpdf ( RV(), RV() ), n ( mFacs.length() ), epdfs ( n ), mpdfs ( mFacs ), rvinds ( n ), rvcinrv ( n ), rvcinds ( n ) { 
     33// mprod::mprod ( Array<mpdf*> mFacs, bool overlap) : mpdf ( RV(), RV() ), n ( mFacs.length() ), epdfs ( n ), mpdfs ( mFacs ), rvinds ( n ), rvcinrv ( n ), rvcsinrvc ( n ) { 
    3434//              int i; 
    3535//              bool rvaddok; 
     
    5454//                      rvcinrv ( i ) = mpdfs ( i )->_rvc().dataind ( rv ); 
    5555//                      // find ith rvc in common rv 
    56 //                      rvcinds ( i ) = mpdfs ( i )->_rvc().dataind ( rvc ); 
     56//                      rvcsinrvc ( i ) = mpdfs ( i )->_rvc().dataind ( rvc ); 
    5757//                      // 
    5858// /*                   if ( rvcinrv ( i ).length() >0 ) {independent = false;} 
    59 //                      if ( rvcinds ( i ).length() >0 ) {independent = false;}*/ 
     59//                      if ( rvcsinrvc ( i ).length() >0 ) {independent = false;}*/ 
    6060//              } 
    6161//      }; 
  • bdm/stat/emix.h

    r178 r181  
    4040public: 
    4141        //!Default constructor 
    42         emix (const RV &rv ) : epdf ( rv ) {}; 
     42        emix ( const RV &rv ) : epdf ( rv ) {}; 
    4343        //! Set weights \c w and components \c Coms , Coms are not copied! 
    4444        void set_parameters ( const vec &w, const Array<epdf*> &Coms, bool copy=true ); 
     
    6060        //! returns a pointer to the internal mean value. Use with Care! 
    6161        vec& _w() {return w;} 
    62         virtual ~emix(){if (destroyComs){for(int i=0;i<Coms.length();i++){delete Coms(i);}}} 
     62        virtual ~emix() {if ( destroyComs ) {for ( int i=0;i<Coms.length();i++ ) {delete Coms ( i );}}} 
    6363        //! Auxiliary function for taking ownership of the Coms() 
    64         void ownComs(){destroyComs=true;} 
     64        void ownComs() {destroyComs=true;} 
    6565}; 
    6666 
     
    7575class mprod: public compositepdf, public mpdf { 
    7676protected: 
    77         // pointers to epdfs 
     77        //! pointers to epdfs - shortcut to mpdfs()._epdf() 
    7878        Array<epdf*> epdfs; 
    7979        //! Indeces of rvc in common rvc 
    80         Array<ivec> rvcinds; 
     80        Array<ivec> rvcsinrvc; 
     81        //! Indeces of common rvc in rvcs 
     82        Array<ivec> rvcinrvcs; 
    8183public: 
    8284        /*!\brief Constructor from list of mFacs, 
    83         Additional parameter overlap is left for future use. Do not set to true for mprod. 
    8485        */ 
    85         mprod ( Array<mpdf*> mFacs): compositepdf(mFacs), mpdf(getrv(true),RV()), epdfs(n), rvcinds(n) 
    86         {       setrvc(rv,rvc); 
    87                 setrvcinrv(rvc,rvcinds); 
    88                 setindices(rv);  
    89         for(int i=0;i<n;i++){epdfs(i)=&(mpdfs(i)->_epdf());} 
    90         }; 
    91  
    92         double evalpdflog ( const vec &val ) const { 
     86        mprod ( Array<mpdf*> mFacs ) : compositepdf ( mFacs ), mpdf ( getrv ( true ),RV() ), epdfs ( n ), rvcsinrvc ( n ) { 
     87                setrvc ( rv,rvc ); 
     88                setindices ( rv ); 
     89                for ( int i = 0;i < n;i++ ) { 
     90                        // find ith rvc in common rv 
     91                        rvcsinrvc ( i ) = mpdfs ( i )->_rvc().dataind ( rvc ); 
     92                        //and vice-versa 
     93                        rvcinrvcs ( i ) = rvc.dataind ( mpdfs ( i )->_rvc() ); 
     94                } 
     95 
     96                for ( int i=0;i<n;i++ ) { 
     97                        epdfs ( i ) =& ( mpdfs ( i )->_epdf() ); 
     98                } 
     99        }; 
     100 
     101        double evalcond ( const vec &val, const vec &cond ) const { 
    93102                int i; 
    94103                double res = 0.0; 
     104                vec condi; 
    95105                for ( i = n - 1;i > 0;i++ ) { 
    96                         if ( rvcinds ( i ).length() > 0 ) 
    97                                 {mpdfs ( i )->condition ( val ( rvcinds ( i ) ) );} 
     106                        if ( ( rvcsinrvc ( i ).length() > 0 ) || ( rvcsinrv ( i ).length() > 0 ) ) { 
     107                                condi = zeros ( rvcsinrvc ( i ).length() +rvcsinrv ( i ).length() ); 
     108                                //copy part of the rvc into condi 
     109                                set_subvector ( condi, rvcinrvcs ( i ), get_vec ( cond,rvcsinrvc ( i ) ) ); 
     110                                //copy part of the rv into condi 
     111                                set_subvector ( condi, rvinrvcs ( i ), get_vec ( val,rvcsinrv ( i ) ) ); 
     112                                mpdfs ( i )->condition ( condi ); 
     113                        } 
    98114                        // add logarithms 
    99115                        res += epdfs ( i )->evalpdflog ( val ( rvsinrv ( i ) ) ); 
     
    107123                ll = 0; 
    108124                for ( int i = ( n - 1 );i >= 0;i-- ) { 
    109                         if (( rvcinds ( i ).length() > 0 )||( rvcsinrv ( i ).length() > 0 )) { 
    110                                 condi = zeros ( rvcsinrv(i).length() + rvcinds(i).length() ); 
     125                        if ( ( rvcsinrvc ( i ).length() > 0 ) || ( rvcsinrv ( i ).length() > 0 ) ) { 
     126                                condi = zeros ( rvcsinrv ( i ).length() + rvcsinrvc ( i ).length() ); 
    111127                                // copy data in condition 
    112                                 set_subvector ( condi,rvcinds ( i ), cond ); 
     128                                set_subvector ( condi,rvcsinrvc ( i ), cond ); 
    113129                                // copy data in already generated sample 
    114                                 set_subvector ( condi,rvinrvcs ( i ), get_vec(smp,rvcsinrv(i)) ); 
     130                                set_subvector ( condi,rvinrvcs ( i ), get_vec ( smp,rvcsinrv ( i ) ) ); 
    115131 
    116132                                mpdfs ( i )->condition ( condi ); 
     
    169185                double tmp=0; 
    170186                for ( int i=0;i<epdfs.length();i++ ) { 
    171                         tmp+=epdfs(i)->evalpdflog(val(rvinds(i))); 
     187                        tmp+=epdfs ( i )->evalpdflog ( val ( rvinds ( i ) ) ); 
    172188                } 
    173189                return tmp; 
    174190        } 
    175191        //!access function 
    176         const epdf* operator () (int i) const {it_assert_debug(i<epdfs.length(),"wrong index");return epdfs(i);} 
     192        const epdf* operator () ( int i ) const {it_assert_debug ( i<epdfs.length(),"wrong index" );return epdfs ( i );} 
    177193}; 
    178194 
  • bdm/stat/libBM.cpp

    r178 r181  
    213213} 
    214214 
    215 void compositepdf::setrvcinrv(const RV &rvc, Array<ivec> &rvinds){ 
    216         for (int i = 0;i < n;i++ ) { 
    217                         // find ith rv in common rv 
    218                 rvinds ( i ) = mpdfs ( i )->_rvc().dataind ( rvc ); 
    219         } 
    220 } 
    221  
    222  
    223215void BM::bayesB(const mat &Data){ 
    224216        for(int t=0;t<Data.cols();t++){bayes(Data.get_col(t));} 
  • bdm/stat/libBM.h

    r178 r181  
    1919using namespace itpp; 
    2020 
    21 //! Structure of RV (used internally) 
     21//! Structure of RV (used internally), i.e. expanded RVs 
    2222class str{ 
    2323public: 
     24        //! vector id ids (non-unique!) 
    2425        ivec ids; 
     26        //! vector of times 
    2527        ivec times; 
     28        //!Default constructor 
    2629        str(ivec ids0, ivec times0):ids(ids0),times(times0){ 
    2730                it_assert_debug(times0.length()==ids0.length(),"Incompatible input"); 
     
    262265        public: 
    263266                compositepdf(Array<mpdf*> A0): n(A0.length()), mpdfs(A0), rvsinrv(n), rvcsinrv(n),rvinrvcs(n){}; 
     267                //! find common rv, flag \param checkoverlap modifies whether overlaps are acceptable 
    264268                RV getrv(bool checkoverlap=false); 
     269                //! common rvc of all mpdfs is written to rvc 
    265270                void setrvc(const RV &rv, RV &rvc); 
     271                //! fill all rv*inrv* according to  
    266272                void setindices(const RV &rv); 
    267                 void setrvcinrv(const RV &rvc, Array<ivec> &rvcind); 
    268273}; 
    269274 
  • bdm/stat/libEF.h

    r178 r181  
    230230}; 
    231231 
    232 //! Estimator for Multinomial density 
     232//! \brief Estimator for Multinomial density 
    233233class multiBM : public BMEF { 
    234234protected: 
    235235        //! Conjugate prior and posterior 
    236236        eDirich est; 
     237        //! Pointer inside est to sufficient statistics  
    237238        vec &beta; 
    238239public: 
     
    241242        //!Copy constructor 
    242243        multiBM ( const multiBM &B ) : BMEF ( B ),est ( rv,B.beta ),beta ( est._beta() ) {} 
    243  
     244        //! Sets sufficient statistics to match that of givefrom mB0 
    244245        void set_statistics ( const BM* mB0 ) {const multiBM* mB=dynamic_cast<const multiBM*> ( mB0 ); beta=mB->beta;} 
    245246        void bayes ( const vec &dt ) {