Show
Ignore:
Timestamp:
09/16/09 22:52:57 (15 years ago)
Author:
smidl
Message:

astyle

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • applications/bdmtoolbox/mex/estimator.cpp

    r611 r622  
    99        {rank="same"; "Data Source"; "Bayesian Model"} 
    1010        "Data Source" -> "Bayesian Model" [label="data"]; 
    11         "Bayesian Model" -> "Result Logger" [label="estimated\n statistics"];  
     11        "Bayesian Model" -> "Result Logger" [label="estimated\n statistics"]; 
    1212        "Data Source" -> "Result Logger" [label="Simulated\n data"]; 
    1313} 
    1414\enddot 
    1515 
    16 Here,  
     16Here, 
    1717\li Data Source is an object (class DS) providing sequential data, \f$ [d_1, d_2, \ldots d_t] \f$. 
    1818\li Bayesian Model is an object (class BM) performing Bayesian filtering, 
     
    6565void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 
    6666        // Check the number of inputs and output arguments 
    67         if(n_input<2) mexErrMsgTxt("Usage:\n"   
    68                 "result=estimator(system, estimators, experiment, logger)\n" 
    69                 "  system     = struct('class','datasource',...);  % Estimated system\n" 
    70                 "  estimators = {struct('class','estimator',...),  % Estimators\n" 
    71                 "                struct('class','estimator',...),...} \n" 
    72                 "  === optional ===" 
    73                 "  experiment = struct('ndat',10);                 % number of data in experiment, full length of finite datasources, 10 otherwise \n" 
    74                 "  logger     = struct('class','mexlogger');       % How to store results, default=mexlog, i.e. matlab structure\n\n" 
    75                 "see documentation of classes datasource, BM, and mexlogger and their offsprings in BDM."); 
    76          
     67        if ( n_input<2 ) mexErrMsgTxt ( "Usage:\n" 
     68                                                "result=estimator(system, estimators, experiment, logger)\n" 
     69                                                "  system     = struct('class','datasource',...);  % Estimated system\n" 
     70                                                "  estimators = {struct('class','estimator',...),  % Estimators\n" 
     71                                                "                struct('class','estimator',...),...} \n" 
     72                                                "  === optional ===" 
     73                                                "  experiment = struct('ndat',10);                 % number of data in experiment, full length of finite datasources, 10 otherwise \n" 
     74                                                "  logger     = struct('class','mexlogger');       % How to store results, default=mexlog, i.e. matlab structure\n\n" 
     75                                                "see documentation of classes datasource, BM, and mexlogger and their offsprings in BDM." ); 
     76 
    7777        RV::clear_all(); 
    78         //CONFIG  
     78        //CONFIG 
    7979        UImxArray Cfg; 
    80         try{ 
    81         Cfg.addGroup(input[0],"system"); 
    82         Cfg.addList(input[1],"estimators"); 
    83         if (n_input>2){ 
    84                 Cfg.addGroup(input[2],"experiment"); 
    85         } 
    86         if (n_input>3){ 
    87                 Cfg.addGroup(input[3],"logger"); 
    88         }/*else{ 
     80        try { 
     81                Cfg.addGroup ( input[0],"system" ); 
     82                Cfg.addList ( input[1],"estimators" ); 
     83                if ( n_input>2 ) { 
     84                        Cfg.addGroup ( input[2],"experiment" ); 
     85                } 
     86                if ( n_input>3 ) { 
     87                        Cfg.addGroup ( input[3],"logger" ); 
     88                }/*else{ 
    8989                // define logger as mexlog 
    9090                Setting &S=Cfg.getRoot(); 
     
    9797                S["logger"]["maxlen"]=maxlen; 
    9898        }*/ 
    99         } catch(SettingException e){it_error("error: "+string(e.getPath()));} 
     99        } catch ( SettingException e ) { 
     100                it_error ( "error: "+string ( e.getPath() ) ); 
     101        } 
    100102 
    101103        //DBG 
    102         Cfg.writeFile("estimator.cfg"); 
     104        Cfg.writeFile ( "estimator.cfg" ); 
    103105 
    104106#else 
     
    112114        UIFile Cfg ( fname ); 
    113115#endif 
    114          
    115         shared_ptr<DS> Ds = UI::build<DS>( Cfg, "system" ); 
    116         Array<shared_ptr<BM> > Es;      UI::get(Es,Cfg, "estimators" ); 
     116 
     117        shared_ptr<DS> Ds = UI::build<DS> ( Cfg, "system" ); 
     118        Array<shared_ptr<BM> > Es; 
     119        UI::get ( Es,Cfg, "estimators" ); 
    117120        long Ndat=10; 
    118         if (Cfg.exists("experiment")) { 
    119                 if (Cfg.lookupValue ( "experiment.ndat",Ndat )) { 
    120                         bdm_assert(Ndat<=Ds->max_length(), "Data source has less data then required"); 
     121        if ( Cfg.exists ( "experiment" ) ) { 
     122                if ( Cfg.lookupValue ( "experiment.ndat",Ndat ) ) { 
     123                        bdm_assert ( Ndat<=Ds->max_length(), "Data source has less data then required" ); 
    121124                }; 
    122125        } else { 
    123                 if (Ds->max_length() < inf) { 
     126                if ( Ds->max_length() < inf ) { 
    124127                        Ndat=Ds->max_length(); 
    125                 };// else Ndat=10; 
     128                } 
     129                ;// else Ndat=10; 
    126130        } 
    127         shared_ptr<logger> L = UI::build<logger>( Cfg, "logger",UI::optional); 
    128         if (!L) { 
    129                 #ifdef MEX 
     131        shared_ptr<logger> L = UI::build<logger> ( Cfg, "logger",UI::optional ); 
     132        if ( !L ) { 
     133#ifdef MEX 
    130134                //mex logger has only from_setting constructor - we  have to fill it... 
    131                 L=new mexlog(Ndat); 
    132                 #else 
     135                L=new mexlog ( Ndat ); 
     136#else 
    133137                L=new stdlog(); 
    134                 #endif 
     138#endif 
    135139        } 
    136          
     140 
    137141        Ds->log_add ( *L ); 
    138142        string Ename; 
    139143        Setting &S=Cfg; 
    140         for (int i=0; i<Es.length(); i++){ 
    141                 try{ 
    142                         UI::get(Ename, S["estimators"][i], "name"); 
    143                 } catch (UIException e){ 
    144                         Ename="Est"+num2str(i); 
     144        for ( int i=0; i<Es.length(); i++ ) { 
     145                try { 
     146                        UI::get ( Ename, S["estimators"][i], "name" ); 
     147                } catch ( UIException e ) { 
     148                        Ename="Est"+num2str ( i ); 
    145149                } 
    146                  
    147                 Es(i)->log_add(*L,Ename); // estimate 
     150 
     151                Es ( i )->log_add ( *L,Ename ); // estimate 
    148152        } 
    149                 L->init(); 
     153        L->init(); 
    150154 
    151155        vec dt=zeros ( Ds->_drv()._dsize() );   //data variable 
    152         Array<datalink*> Dls(Es.length());  
    153         for (int i=0; i<Es.length(); i++){ 
    154                 Dls(i)=new datalink( Es(i)->_drv(),Ds->_drv() ); //datalink between a datasource and estimator 
     156        Array<datalink*> Dls ( Es.length() ); 
     157        for ( int i=0; i<Es.length(); i++ ) { 
     158                Dls ( i ) =new datalink ( Es ( i )->_drv(),Ds->_drv() ); //datalink between a datasource and estimator 
    155159        } 
    156          
     160 
    157161        for ( int tK=0;tK<Ndat;tK++ ) { 
    158162                Ds->getdata ( dt );                                     // read data 
    159163                Ds->logit ( *L ); 
    160                  
    161                 for (int i=0; i<Es.length(); i++){ 
    162                         Es(i)->bayes ( Dls(i)->pushdown ( dt ) );               // update estimates 
    163                         Es(i)->logit (*L); 
     164 
     165                for ( int i=0; i<Es.length(); i++ ) { 
     166                        Es ( i )->bayes ( Dls ( i )->pushdown ( dt ) );         // update estimates 
     167                        Es ( i )->logit ( *L ); 
    164168                } 
    165169                L->step(); 
     
    171175 
    172176#ifdef MEX 
    173         mexlog* mL=dynamic_cast<mexlog*>(L.get()); 
     177        mexlog* mL=dynamic_cast<mexlog*> ( L.get() ); 
    174178 
    175         if (mL) { // user wants output!! 
     179        if ( mL ) { // user wants output!! 
    176180                if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); 
    177181                output[0] = mL->toCell();