| 1 | /*! |
|---|
| 2 | \file |
|---|
| 3 | \brief Models for synchronous electric drive using IT++ and BDM |
|---|
| 4 | \author Vaclav Smidl. |
|---|
| 5 | |
|---|
| 6 | ----------------------------------- |
|---|
| 7 | BDM++ - C++ library for Bayesian Decision Making under Uncertainty |
|---|
| 8 | |
|---|
| 9 | Using IT++ for numerical operations |
|---|
| 10 | ----------------------------------- |
|---|
| 11 | */ |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | #include <estim/ekf_template.h> |
|---|
| 15 | |
|---|
| 16 | //include dopravni model |
|---|
| 17 | #include "model.h" |
|---|
| 18 | #include "stat\datasources.h" |
|---|
| 19 | #include "stat\loggers.h" |
|---|
| 20 | |
|---|
| 21 | using namespace bdm; |
|---|
| 22 | |
|---|
| 23 | int main( int argc, char* argv[] ) { |
|---|
| 24 | /* const char *fname; |
|---|
| 25 | if ( argc>1 ) {fname = argv[1]; } |
|---|
| 26 | else { fname = "k1.cfg"; } |
|---|
| 27 | UIFile F ( fname ); //protected by exceptions, should complain if not found*/ |
|---|
| 28 | |
|---|
| 29 | ITppFileDS DS("data.it","Data"); // Data Source |
|---|
| 30 | int ndat = DS.ndat(); // number of data |
|---|
| 31 | memlog L(ndat); // Logger |
|---|
| 32 | string resfile="k1_results.it"; // name of output file |
|---|
| 33 | vec dQ="0.1 0.1"; |
|---|
| 34 | vec dR="0.2 0.2"; // TODO: read from config file <== broken on windows |
|---|
| 35 | |
|---|
| 36 | //model vyvoje stavu |
|---|
| 37 | IMk1 fxu; |
|---|
| 38 | fxu.set_parameters (0.5, 0.5); // pokud nejake budou |
|---|
| 39 | |
|---|
| 40 | //model pozorovani |
|---|
| 41 | OMk1 hxu; |
|---|
| 42 | //hxu.set_parameters (); // odkomentovat pokud budou |
|---|
| 43 | |
|---|
| 44 | // ESTIMATOR --- EKF |
|---|
| 45 | // Priprava covariancnich matic pro EKF |
|---|
| 46 | EKFCh Efix; //Extended KF s fix. variancemi |
|---|
| 47 | Efix.set_parameters ( &fxu,&hxu,diag(dQ),diag(dR)); |
|---|
| 48 | Efix.set_statistics ( zeros(fxu.dimension()), 100*eye ( fxu.dimension() ) ); // nulova |
|---|
| 49 | |
|---|
| 50 | // Definovat co se bude logovat |
|---|
| 51 | Efix.log_add(L,"E"); |
|---|
| 52 | L.init(); // <<==== allocate memory for results |
|---|
| 53 | |
|---|
| 54 | vec dt; |
|---|
| 55 | for ( int t=1;t<ndat;t++ ) { |
|---|
| 56 | DS.getdata(dt); // dt is allocated |
|---|
| 57 | Efix.bayes(dt); //ESTIMATE |
|---|
| 58 | |
|---|
| 59 | //LOG results |
|---|
| 60 | Efix.logit(L); |
|---|
| 61 | |
|---|
| 62 | L.step(); |
|---|
| 63 | DS.step(); |
|---|
| 64 | } |
|---|
| 65 | L.finalize(); |
|---|
| 66 | L.itsave(resfile.c_str()); |
|---|
| 67 | return 0; |
|---|
| 68 | } |
|---|