| 428 | //! EKF using bierman and Thorton code |
| 429 | class EKF_UD : public BM { |
| 430 | protected: |
| 431 | //! Internal Model f(x,u) |
| 432 | shared_ptr<diffbifn> pfxu; |
| 433 | |
| 434 | //! Observation Model h(x,u) |
| 435 | shared_ptr<diffbifn> phxu; |
| 436 | |
| 437 | //! U part |
| 438 | mat U; |
| 439 | //! D part |
| 440 | vec D; |
| 441 | |
| 442 | mat A; |
| 443 | mat C; |
| 444 | mat Q; |
| 445 | vec R; |
| 446 | |
| 447 | enorm<ldmat> est; |
| 448 | public: |
| 449 | //! copy constructor duplicated |
| 450 | EKF_UD* _copy() const { |
| 451 | return new EKF_UD(*this); |
| 452 | } |
| 453 | |
| 454 | const enorm<ldmat>& posterior()const{return est;}; |
| 455 | |
| 456 | enorm<ldmat>& prior() { |
| 457 | return const_cast<enorm<ldmat>&>(posterior()); |
| 458 | } |
| 459 | |
| 460 | |
| 461 | EKF_UD(){} |
| 462 | |
| 463 | EKF_UD(const EKF_UD &E0): pfxu(E0.pfxu),phxu(E0.phxu), U(E0.U), D(E0.D){} |
| 464 | |
| 465 | //! Set nonlinear functions for mean values and covariance matrices. |
| 466 | void set_parameters ( const shared_ptr<diffbifn> &pfxu, const shared_ptr<diffbifn> &phxu, const mat Q0, const vec R0 ); |
| 467 | |
| 468 | //! Here dt = [yt;ut] of appropriate dimensions |
| 469 | void bayes ( const vec &yt, const vec &cond = empty_vec ); |
| 470 | |
| 471 | /*! Create object from the following structure |
| 472 | |
| 473 | \code |
| 474 | class = 'EKF_UD'; |
| 475 | OM = configuration of bdm::diffbifn; % any offspring of diffbifn, bdm::diffbifn::from_setting |
| 476 | IM = configuration of bdm::diffbifn; % any offspring of diffbifn, bdm::diffbifn::from_setting |
| 477 | dQ = [...]; % vector containing diagonal of Q |
| 478 | dR = [...]; % vector containing diagonal of R |
| 479 | --- optional fields --- |
| 480 | mu0 = [...]; % vector of statistics mu0 |
| 481 | dP0 = [...]; % vector containing diagonal of P0 |
| 482 | -- or -- |
| 483 | P0 = [...]; % full matrix P0 |
| 484 | --- inherited fields --- |
| 485 | bdm::BM::from_setting |
| 486 | \endcode |
| 487 | If the optional fields are not given, they will be filled as follows: |
| 488 | \code |
| 489 | mu0 = [0,0,0,....]; % empty statistics |
| 490 | P0 = eye( dim ); |
| 491 | \endcode |
| 492 | */ |
| 493 | void from_setting ( const Setting &set ); |
| 494 | |
| 495 | void validate() {}; |
| 496 | // TODO dodelat void to_setting( Setting &set ) const; |
| 497 | |
| 498 | }; |
| 499 | UIREGISTER(EKF_UD); |
| 500 | |
474 | | |
475 | | // NEW Sigma points |
476 | | mat tmp; |
477 | | qr(concat_vertical(Xpred_dif,Q._Ch()), tmp); |
478 | | mat Ppred=tmp.get_rows(0,dim-1); |
479 | | // New Xi(k+1) |
480 | | Xik.set_col(0,xp); |
481 | | for ( i=0;i<dim; i++){ |
482 | | vec tmp=sqrt(npk)*Ppred.get_col(i); |
483 | | Xik.set_col(i+1, _mu+tmp); |
484 | | Xik.set_col(i+1+dim, _mu-tmp); |
485 | | } |
486 | | for (i=0;i<dim2;i++){ |
487 | | Xpred_dif.set_row(i, sqrt(w(i)) * (Xik.get_col(i) - xp)); |
488 | | } |
489 | | |
490 | | |
491 | | |
| 549 | |