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

astyle

Location:
applications/bdmtoolbox
Files:
6 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(); 
  • applications/bdmtoolbox/mex/merger.cpp

    r569 r622  
    2929 
    3030#ifdef MEX 
    31 void mexFunction (int n_output, mxArray *output[], int n_input, const mxArray *input[]) 
    32 { 
     31void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 
    3332        // Check the number of inputs and output arguments 
    34         if (n_input != 3) mexErrMsgTxt ("Usage:\n" 
    35                                             "result=merger(sources, support, merger)\n" 
    36                                             "  sources= { struct('class','epdf'),... };  % cell of pdfs (epdfs or mpdfs) to be merged,\n" 
    37                                             "  support= struct(\n" 
    38                                             "           grid    = {[dim1_start,dim1_end], [dim2_start, dim2_end]...}  %support boundary \n" 
    39                                             "           nbins   = [bins_in_dim1, bins_in_dim2,...]                    %fixed \n" 
    40                                             "         === OR ==\n" 
    41                                             "           pdf     = struct('class','epdf'); % pdf to draw samples from\n" 
    42                                             "           nsamples= 100;                    % number of samples\n" 
    43                                             "           );\n" 
    44                                             "        If all elements are present,  (grid,nbins) is used;\n" 
    45                                             "  merger = struct('class','merger_*');       % object to be used for merging,\n\n" 
    46                                             "see documentation of classes epdf, mpdf, merger_base and their offsprings in BDM."); 
     33        if ( n_input != 3 ) mexErrMsgTxt ( "Usage:\n" 
     34                                                   "result=merger(sources, support, merger)\n" 
     35                                                   "  sources= { struct('class','epdf'),... };  % cell of pdfs (epdfs or mpdfs) to be merged,\n" 
     36                                                   "  support= struct(\n" 
     37                                                   "           grid    = {[dim1_start,dim1_end], [dim2_start, dim2_end]...}  %support boundary \n" 
     38                                                   "           nbins   = [bins_in_dim1, bins_in_dim2,...]                    %fixed \n" 
     39                                                   "         === OR ==\n" 
     40                                                   "           pdf     = struct('class','epdf'); % pdf to draw samples from\n" 
     41                                                   "           nsamples= 100;                    % number of samples\n" 
     42                                                   "           );\n" 
     43                                                   "        If all elements are present,  (grid,nbins) is used;\n" 
     44                                                   "  merger = struct('class','merger_*');       % object to be used for merging,\n\n" 
     45                                                   "see documentation of classes epdf, mpdf, merger_base and their offsprings in BDM." ); 
    4746        RV::clear_all(); 
    4847        // LOAD CONFIG 
    4948        UImxArray Cfg; 
    50         Cfg.addList (input[0], "Sources"); 
    51         Cfg.addGroup (input[1], "Support"); 
    52         Cfg.addGroup (input[2], "Merger"); 
     49        Cfg.addList ( input[0], "Sources" ); 
     50        Cfg.addGroup ( input[1], "Support" ); 
     51        Cfg.addGroup ( input[2], "Merger" ); 
    5352 
    5453        //DBG 
    55         Cfg.writeFile ("merger.cfg"); 
     54        Cfg.writeFile ( "merger.cfg" ); 
    5655#else 
    5756int main() { 
    58         UIFile Cfg ("merger.cfg"); 
     57        UIFile Cfg ( "merger.cfg" ); 
    5958#endif 
    6059        // Sources 
    6160        Array<shared_ptr<mpdf> > Sources; 
    6261        //abuse Mer to store sources 
    63         Setting& _Sources = Cfg.lookup ("Sources"); 
     62        Setting& _Sources = Cfg.lookup ( "Sources" ); 
    6463        int Slen = _Sources.getLength(); 
    65         Sources.set_size (Slen); 
    66         for (int i = 0; i < Slen; i++) { 
     64        Sources.set_size ( Slen ); 
     65        for ( int i = 0; i < Slen; i++ ) { 
    6766                try { 
    68                         shared_ptr<mpdf> mtmp = UI::build<mpdf> (_Sources, i); 
    69                         Sources (i) = mtmp; 
    70                 } catch (UIException) { 
     67                        shared_ptr<mpdf> mtmp = UI::build<mpdf> ( _Sources, i ); 
     68                        Sources ( i ) = mtmp; 
     69                } catch ( UIException ) { 
    7170                        // it is not mpdf - see if it is epdf 
    7271                        try { 
    73                                 shared_ptr<epdf> etmp = UI::build<epdf> (_Sources, i); 
    74                                 if (etmp) { 
    75                                         Sources (i) = new mepdf (etmp); // hopefully OK 
     72                                shared_ptr<epdf> etmp = UI::build<epdf> ( _Sources, i ); 
     73                                if ( etmp ) { 
     74                                        Sources ( i ) = new mepdf ( etmp ); // hopefully OK 
    7675                                } 
    77                         } catch (UIException &e) { 
    78                                 it_error ("No mpdfs or epdfs found! " + string (e.what())); 
    79                         } catch (std::exception e) { 
    80                                 it_error ("Error in UI at " + _Sources[i].getPath()); 
     76                        } catch ( UIException &e ) { 
     77                                it_error ( "No mpdfs or epdfs found! " + string ( e.what() ) ); 
     78                        } catch ( std::exception e ) { 
     79                                it_error ( "Error in UI at " + _Sources[i].getPath() ); 
    8180                        } 
    82                 } catch (std::exception &e) { 
    83                         it_error ("Error in UI at " + _Sources[i].getPath()); 
     81                } catch ( std::exception &e ) { 
     82                        it_error ( "Error in UI at " + _Sources[i].getPath() ); 
    8483                } 
    8584        } 
    8685 
    87         shared_ptr<merger_base> Merger = UI::build<merger_base> (Cfg, "Merger"); 
     86        shared_ptr<merger_base> Merger = UI::build<merger_base> ( Cfg, "Merger" ); 
    8887 
    8988        // Support 
    9089        try { 
    91                 shared_ptr<rectangular_support> RecSup = UI::build<rectangular_support> (Cfg, "Support"); 
    92                 Merger->set_support(*RecSup); 
    93         } 
    94         catch (UIException &e) { 
    95                 shared_ptr<discrete_support> DisSup = UI::build<discrete_support> (Cfg, "Support"); 
    96                 Merger->set_support (*DisSup); 
     90                shared_ptr<rectangular_support> RecSup = UI::build<rectangular_support> ( Cfg, "Support" ); 
     91                Merger->set_support ( *RecSup ); 
     92        } catch ( UIException &e ) { 
     93                shared_ptr<discrete_support> DisSup = UI::build<discrete_support> ( Cfg, "Support" ); 
     94                Merger->set_support ( *DisSup ); 
    9795        } 
    9896// COMPUTE RESULTS 
    99         Merger->set_sources (Sources);  
     97        Merger->set_sources ( Sources ); 
    10098        Merger->merge(); 
    10199 
    102100// save results 
    103         Array<vec> source_vals (Sources.length()); 
    104         for (int i = 0;i < Sources.length();i++) { 
     101        Array<vec> source_vals ( Sources.length() ); 
     102        for ( int i = 0;i < Sources.length();i++ ) { 
    105103                datalink_m2e dl; 
    106                 dl.set_connection (Sources (i)->_rv(), Sources (i)->_rvc(), Merger->_rv()); 
     104                dl.set_connection ( Sources ( i )->_rv(), Sources ( i )->_rvc(), Merger->_rv() ); 
    107105 
    108                 vec ll (Merger->_Smp()._samples().length()); 
    109                 for (int j = 0; j < Merger->_Smp()._samples().length(); j++) { 
    110                         vec dt = dl.pushdown (Merger->_Smp()._samples() (j)); 
    111                         vec dtc = dl.get_cond (Merger->_Smp()._samples() (j)); 
    112                         ll (j) = Sources (i)->evallogcond (dt, dtc); 
     106                vec ll ( Merger->_Smp()._samples().length() ); 
     107                for ( int j = 0; j < Merger->_Smp()._samples().length(); j++ ) { 
     108                        vec dt = dl.pushdown ( Merger->_Smp()._samples() ( j ) ); 
     109                        vec dtc = dl.get_cond ( Merger->_Smp()._samples() ( j ) ); 
     110                        ll ( j ) = Sources ( i )->evallogcond ( dt, dtc ); 
    113111                } 
    114112 
    115                 vec sll = exp (ll); 
     113                vec sll = exp ( ll ); 
    116114 
    117                 source_vals (i) = sll / sum (sll); 
     115                source_vals ( i ) = sll / sum ( sll ); 
    118116        } 
    119117 
    120         merger_mix* MerMix=dynamic_cast<merger_mix*>(Merger.get()); 
     118        merger_mix* MerMix=dynamic_cast<merger_mix*> ( Merger.get() ); 
    121119        vec mix_val; 
    122                          
    123         if (MerMix){ 
    124                 vec ll (Merger->_Smp()._samples().length()); 
    125                 for (int j = 0; j < Merger->_Smp()._samples().length(); j++) { 
    126                         ll (j) = Merger->evallog (Merger->_Smp()._samples() (j)); 
     120 
     121        if ( MerMix ) { 
     122                vec ll ( Merger->_Smp()._samples().length() ); 
     123                for ( int j = 0; j < Merger->_Smp()._samples().length(); j++ ) { 
     124                        ll ( j ) = Merger->evallog ( Merger->_Smp()._samples() ( j ) ); 
    127125                } 
    128          
    129                 vec sll = exp (ll); 
    130          
    131                 mix_val = sll / sum (sll); 
     126 
     127                vec sll = exp ( ll ); 
     128 
     129                mix_val = sll / sum ( sll ); 
    132130        } 
    133131 
     
    135133        mxArray* tmp ; 
    136134        // Save results 
    137         if (n_output > 0) { 
    138                 tmp = mxCreateStructMatrix (1, 1, 0, NULL); 
     135        if ( n_output > 0 ) { 
     136                tmp = mxCreateStructMatrix ( 1, 1, 0, NULL ); 
    139137                //support 
    140138                Array<vec> &samples = Merger->_Smp()._samples(); 
    141                 if (samples.size() > 0) { 
    142                         mxArray* fld = mxCreateDoubleMatrix (samples (0).length(), samples.size(), mxREAL); 
    143                         Arrayvec2mxArray (samples, fld); 
    144                         mxReplaceFieldNM (tmp, "support", fld); 
     139                if ( samples.size() > 0 ) { 
     140                        mxArray* fld = mxCreateDoubleMatrix ( samples ( 0 ).length(), samples.size(), mxREAL ); 
     141                        Arrayvec2mxArray ( samples, fld ); 
     142                        mxReplaceFieldNM ( tmp, "support", fld ); 
    145143                } 
    146144 
    147145                //weights 
    148146                vec &w = Merger->_Smp()._w(); 
    149                 mxArray* fldw = mxCreateDoubleMatrix (1, w.length(), mxREAL); 
    150                 vec2mxArray (w, fldw); 
    151                 mxReplaceFieldNM (tmp, "weights", fldw); 
     147                mxArray* fldw = mxCreateDoubleMatrix ( 1, w.length(), mxREAL ); 
     148                vec2mxArray ( w, fldw ); 
     149                mxReplaceFieldNM ( tmp, "weights", fldw ); 
    152150 
    153151                //mixture values 
    154                 if (mix_val.length()>0){ 
    155                         mxArray* fldm = mxCreateDoubleMatrix (1, w.length(), mxREAL); 
    156                         vec2mxArray (mix_val, fldm); 
    157                         mxReplaceFieldNM (tmp, "mix", fldm); 
     152                if ( mix_val.length() >0 ) { 
     153                        mxArray* fldm = mxCreateDoubleMatrix ( 1, w.length(), mxREAL ); 
     154                        vec2mxArray ( mix_val, fldm ); 
     155                        mxReplaceFieldNM ( tmp, "mix", fldm ); 
    158156                } 
    159157                // sources 
    160158                char srcstr[20]; 
    161                 for (int i = 0;i < Sources.length();i++) { 
    162                         sprintf (srcstr, "source%d", i + 1); 
    163                         mxArray* fldw = mxCreateDoubleMatrix (1, source_vals (i).length(), mxREAL); 
    164                         vec2mxArray (source_vals (i), fldw); 
    165                         mxReplaceFieldNM (tmp, srcstr, fldw); 
     159                for ( int i = 0;i < Sources.length();i++ ) { 
     160                        sprintf ( srcstr, "source%d", i + 1 ); 
     161                        mxArray* fldw = mxCreateDoubleMatrix ( 1, source_vals ( i ).length(), mxREAL ); 
     162                        vec2mxArray ( source_vals ( i ), fldw ); 
     163                        mxReplaceFieldNM ( tmp, srcstr, fldw ); 
    166164                } 
    167165 
  • applications/bdmtoolbox/mex/mxstruct2config.cpp

    r391 r622  
    22 
    33void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 
    4         UImxArray F (input[0]); 
    5         string filename = mxArray2string(input[1]); 
    6         F.writeFile(filename.c_str()); 
     4        UImxArray F ( input[0] ); 
     5        string filename = mxArray2string ( input[1] ); 
     6        F.writeFile ( filename.c_str() ); 
    77} 
  • applications/bdmtoolbox/mex/simulator.cpp

    r617 r622  
    1212\enddot 
    1313 
    14 Here,  
     14Here, 
    1515\li Data Source is an object (class DS) providing sequential data, \f$ [d_1, d_2, \ldots d_t] \f$. 
    1616\li Result Logger is an object (class logger) dedicated to storing important data from the experiment. 
     
    5656void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { 
    5757        // Check the number of inputs and output arguments 
    58         if(n_input<1) mexErrMsgTxt("Usage:\n"   
    59                 "result=simulator(system,  experiment, logger)\n" 
    60                 "  system     = struct('class','datasource',...);  % Estimated system\n" 
    61                 "  === optional ===" 
    62                 "  experiment = struct('ndat',10);                 % number of data in experiment, full length of finite datasources, 10 otherwise \n" 
    63                 "  logger     = struct('class','mexlogger');       % How to store results, default=mexlog, i.e. matlab structure\n\n" 
    64                 "see documentation of classes datasource and mexlogger and their offsprings in BDM."); 
    65          
     58        if ( n_input<1 ) mexErrMsgTxt ( "Usage:\n" 
     59                                                "result=simulator(system,  experiment, logger)\n" 
     60                                                "  system     = struct('class','datasource',...);  % Estimated system\n" 
     61                                                "  === optional ===" 
     62                                                "  experiment = struct('ndat',10);                 % number of data in experiment, full length of finite datasources, 10 otherwise \n" 
     63                                                "  logger     = struct('class','mexlogger');       % How to store results, default=mexlog, i.e. matlab structure\n\n" 
     64                                                "see documentation of classes datasource and mexlogger and their offsprings in BDM." ); 
     65 
    6666        RV::clear_all(); 
    67         //CONFIG  
     67        //CONFIG 
    6868        UImxArray Cfg; 
    69         try{ 
    70         Cfg.addGroup(input[0],"system"); 
    71         if (n_input>2){ 
    72                 Cfg.addGroup(input[1],"experiment"); 
    73         } 
    74         if (n_input>3){ 
    75                 Cfg.addGroup(input[2],"logger"); 
    76         }/*else{ 
     69        try { 
     70                Cfg.addGroup ( input[0],"system" ); 
     71                if ( n_input>2 ) { 
     72                        Cfg.addGroup ( input[1],"experiment" ); 
     73                } 
     74                if ( n_input>3 ) { 
     75                        Cfg.addGroup ( input[2],"logger" ); 
     76                }/*else{ 
    7777                // define logger as mexlog 
    7878                Setting &S=Cfg.getRoot(); 
     
    8585                S["logger"]["maxlen"]=maxlen; 
    8686        }*/ 
    87         } catch(SettingException e){it_error("error: "+string(e.getPath()));} 
     87        } catch ( SettingException e ) { 
     88                it_error ( "error: "+string ( e.getPath() ) ); 
     89        } 
    8890 
    8991        //DBG 
    90         Cfg.writeFile("simulator.cfg"); 
     92        Cfg.writeFile ( "simulator.cfg" ); 
    9193 
    9294#else 
     
    100102        UIFile Cfg ( fname ); 
    101103#endif 
    102          
    103         shared_ptr<DS> Ds = UI::build<DS>( Cfg, "system" ); 
     104 
     105        shared_ptr<DS> Ds = UI::build<DS> ( Cfg, "system" ); 
    104106        long Ndat=10; 
    105         if (Cfg.exists("experiment")) { 
    106                 if (Cfg.lookupValue ( "experiment.ndat",Ndat )) { 
    107                         bdm_assert(Ndat<=Ds->max_length(), "Data source has less data then required"); 
     107        if ( Cfg.exists ( "experiment" ) ) { 
     108                if ( Cfg.lookupValue ( "experiment.ndat",Ndat ) ) { 
     109                        bdm_assert ( Ndat<=Ds->max_length(), "Data source has less data then required" ); 
    108110                }; 
    109111        } else { 
    110                 if (Ds->max_length() < std::numeric_limits< int >::max()) { 
     112                if ( Ds->max_length() < std::numeric_limits< int >::max() ) { 
    111113                        Ndat=Ds->max_length(); 
    112                 };// else Ndat=10; 
     114                } 
     115                ;// else Ndat=10; 
    113116        } 
    114         shared_ptr<logger> L = UI::build<logger>( Cfg, "logger",UI::optional); 
    115         if (!L) { 
    116                 #ifdef MEX 
     117        shared_ptr<logger> L = UI::build<logger> ( Cfg, "logger",UI::optional ); 
     118        if ( !L ) { 
     119#ifdef MEX 
    117120                //mex logger has only from_setting constructor - we  have to fill it... 
    118                 L=new mexlog(Ndat); 
    119                 #else 
     121                L=new mexlog ( Ndat ); 
     122#else 
    120123                L=new stdlog(); 
    121                 #endif 
     124#endif 
    122125        } 
    123          
     126 
    124127        Ds->log_add ( *L ); 
    125128        L->init(); 
     
    130133                Ds->getdata ( dt );                                     // read data 
    131134                Ds->logit ( *L ); 
    132                  
     135 
    133136                L->step(); 
    134137                Ds->step();                                                     // simulator step 
     
    139142 
    140143#ifdef MEX 
    141         mexlog* mL=dynamic_cast<mexlog*>(L.get()); 
     144        mexlog* mL=dynamic_cast<mexlog*> ( L.get() ); 
    142145 
    143         if (mL) { // user wants output!! 
     146        if ( mL ) { // user wants output!! 
    144147                if ( n_output<1 ) mexErrMsgTxt ( "Wrong number of output variables!" ); 
    145148                output[0] = mL->toCell(); 
  • applications/bdmtoolbox/tutorial/arx_mex_test.cfg

    r568 r622  
    11//Data generating system 
    2 system = { type="external"; filename="arx_test.cfg"; path="system";}; 
     2system = { type="external"; 
     3           filename="arx_test.cfg"; 
     4           path="system"; 
     5         }; 
    36 
    47//store results 
     
    69        type= "mexlog"; 
    710        maxlen = 90; // 
    8     //dirname = "exp/ax"; 
     11        //dirname = "exp/ax"; 
    912}; 
    1013 
    1114//estimation 
    1215estimator = { 
    13    type = "ARX"; 
    14         y = {type="RV"; names=("y"); }; 
     16        type = "ARX"; 
     17        y = {type="RV"; 
     18             names= ( "y" ); 
     19            }; 
    1520        rgr = {type="RV"; 
    16                 names = ("y","y","y","u"); 
    17                 times = [-1, -2, -3, -1]; 
    18         }; 
     21               names = ( "y","y","y","u" ); 
     22               times = [-1, -2, -3, -1]; 
     23              }; 
    1924 
    2025        //optional fields 
    21         dV0 = matrix(5,1,[1e-3, 1e-5, 1e-5, 1e-5, 1e-5]); //default: 1e-3 for y, 1e-5 for rgr 
     26        dV0 = matrix ( 5,1,[1e-3, 1e-5, 1e-5, 1e-5, 1e-5] ); //default: 1e-3 for y, 1e-5 for rgr 
    2227        //nu0 = 8.;      //default: rgrlen + 2 
    2328        frg = .9991;    // forgetting, default frg=1.0 
     
    2530 
    2631//experiment description 
    27 experiment:{ 
     32experiment: { 
    2833        ndat = 90; 
    2934}; 
  • applications/bdmtoolbox/tutorial/arx_test.cfg

    r357 r622  
    22system = { 
    33        class = "ArxDS"; 
    4         y = {class="RV"; names=("y", "u");}; 
    5         u = {class="RV"; names=(); }; 
     4        y = {class="RV"; 
     5             names= ( "y", "u" ); 
     6            }; 
     7        u = {class="RV"; 
     8             names=(); 
     9            }; 
    610        rgr = {class="RV"; 
    7                 names = ("y","y","y","u"); 
    8                 times = [-1, -2, -3, -1]; 
    9         }; 
     11               names = ( "y","y","y","u" ); 
     12               times = [-1, -2, -3, -1]; 
     13              }; 
    1014        //AR parameters 
    11         theta = (2,4,[0.8, -0.3, 0.4, 1.0, 
    12                       0.0, 0.0, 0.0, 0.0]); 
     15        theta = ( 2,4,[0.8, -0.3, 0.4, 1.0, 
     16                       0.0, 0.0, 0.0, 0.0] ); 
    1317        // offset 
    1418        offset = [0.0, 0.0]; 
    1519        //variance 
    16         r = (2,2,[0.1, 0.0, 
    17                  0.0, 1.0] ); 
     20        r = ( 2,2,[0.1, 0.0, 
     21                   0.0, 1.0] ); 
    1822        // log also theta 
    1923        opt="L_theta"; 
     
    3034estimator = { 
    3135        class = "ARX"; 
    32         y = {class="RV"; names=("y"); }; 
     36        y = {class="RV"; 
     37             names= ( "y" ); 
     38            }; 
    3339        rgr = {class="RV"; 
    34                 names = ("y","y","y","u"); 
    35                 times = [-1, -2, -3, -1]; 
    36         }; 
     40               names = ( "y","y","y","u" ); 
     41               times = [-1, -2, -3, -1]; 
     42              }; 
    3743 
    3844        //optional fields 
     
    4349 
    4450//experiment description 
    45 experiment:{ 
     51experiment: { 
    4652        ndat = 9000; 
    4753};