Show
Ignore:
Timestamp:
09/13/09 23:14:23 (15 years ago)
Author:
smidl
Message:

remove "delays" from memory DS, check length of datasource

Files:
1 modified

Legend:

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

    r602 r609  
    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<3) mexErrMsgTxt("Usage:\n"   
     67        if(n_input<2) mexErrMsgTxt("Usage:\n"   
    6868                "result=estimator(system, estimators, experiment, logger)\n" 
    6969                "  system     = struct('class','datasource',...);  % Estimated system\n" 
    7070                "  estimators = {struct('class','estimator',...),  % Estimators\n" 
    7171                "                struct('class','estimator',...),...} \n" 
    72                 "  experiment = struct('ndat',100);                % number of data in experiment \n" 
    7372                "  === optional ===" 
     73                "  experiment = struct('ndat',10);                 % number of data in experiment, full length of finite datasources, 10 otherwise \n" 
    7474                "  logger     = struct('class','mexlogger');       % How to store results, default=mexlog, i.e. matlab structure\n\n" 
    7575                "see documentation of classes datasource, BM, and mexlogger and their offsprings in BDM."); 
     
    8181        Cfg.addGroup(input[0],"system"); 
    8282        Cfg.addList(input[1],"estimators"); 
    83         Cfg.addGroup(input[2],"experiment"); 
     83        if (n_input>2){ 
     84                Cfg.addGroup(input[2],"experiment"); 
     85        } 
    8486        if (n_input>3){ 
    8587                Cfg.addGroup(input[3],"logger"); 
    86         }else{ 
     88        }/*else{ 
    8789                // define logger as mexlog 
    8890                Setting &S=Cfg.getRoot(); 
     
    9496                S["experiment"].lookupValue("ndat",maxlen); 
    9597                S["logger"]["maxlen"]=maxlen; 
    96         } 
     98        }*/ 
    9799        } catch(SettingException e){it_error("error: "+string(e.getPath()));} 
    98100 
     
    111113#endif 
    112114         
    113         shared_ptr<logger> L = UI::build<logger>( Cfg, "logger"); 
    114115        shared_ptr<DS> Ds = UI::build<DS>( Cfg, "system" ); 
    115116        Array<shared_ptr<BM> > Es;      UI::get(Es,Cfg, "estimators" ); 
    116         int Ndat; 
    117         Cfg.lookupValue ( "experiment.ndat",Ndat ); 
    118  
     117        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                }; 
     122        } else { 
     123                if (Ds->max_length() < inf) { 
     124                        Ndat=Ds->max_length(); 
     125                };// else Ndat=10; 
     126        } 
     127        shared_ptr<logger> L = UI::build<logger>( Cfg, "logger",UI::optional); 
     128        if (!L) { 
     129                #ifdef MEX 
     130                //mex logger has only from_setting constructor - we  have to fill it... 
     131                L=new mexlog(Ndat); 
     132                #else 
     133                L=new memlog(Ndat, "estimator_logger.it"); 
     134                #endif 
     135        } 
     136         
    119137        Ds->log_add ( *L ); 
    120138        string Ename; 
     
    137155        } 
    138156         
    139         for ( int tK=1;tK<Ndat;tK++ ) { 
    140                 Ds->step();                                                     // simulator step 
     157        for ( int tK=0;tK<Ndat;tK++ ) { 
    141158                Ds->getdata ( dt );                                     // read data 
    142159                Ds->logit ( *L ); 
     
    147164                } 
    148165                L->step(); 
     166                Ds->step();                                                     // simulator step 
    149167        } 
    150168