Changeset 700
- Timestamp:
- 11/04/09 22:54:58 (15 years ago)
- Files:
-
- 2 removed
- 20 modified
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
applications/bdmtoolbox/mex/estimator.cpp
r685 r700 48 48 */ 49 49 50 #include "estim/arx.h"51 #include "stat/emix.h"52 #include "base/datasources.h"53 #include "base/loggers.h"54 #include "estim/particles.h"55 #include "estim/kalman.h"50 #include <estim/arx.h> 51 #include <stat/emix.h> 52 #include <base/datasources.h> 53 #include <base/loggers.h> 54 #include <estim/particles.h> 55 #include <estim/kalman.h> 56 56 57 57 //#include "mex_datasource.h" … … 61 61 #ifdef MEX 62 62 #include <itpp/itmex.h> 63 #include "mex/mex_BM.h"64 #include "mex/mex_logger.h"65 #include "mex/mex_datasource.h"63 #include <mex/mex_BM.h> 64 #include <mex/mex_logger.h> 65 #include <mex/mex_datasource.h> 66 66 67 67 void mexFunction ( int n_output, mxArray *output[], int n_input, const mxArray *input[] ) { … … 120 120 Array<shared_ptr<BM> > Es; 121 121 UI::get ( Es,Cfg, "estimators" ); 122 longNdat=10;122 int Ndat=10; 123 123 if ( Cfg.exists ( "experiment" ) ) { 124 if ( Cfg. lookupValue ( "experiment.ndat",Ndat ) ) {124 if ( Cfg.getRoot().lookupValue ( "experiment.ndat",Ndat ) ) { 125 125 bdm_assert ( Ndat<=Ds->max_length(), "Data source has less data then required" ); 126 126 }; -
applications/bdmtoolbox/mex/merger.cpp
r685 r700 58 58 #endif 59 59 // Sources 60 Array<shared_ptr< mpdf> > Sources;60 Array<shared_ptr<pdf> > Sources; 61 61 UI::get(Sources, Cfg, "Sources", UI::compulsory); 62 62 shared_ptr<merger_base> Merger = UI::build<merger_base> ( Cfg, "Merger" ); -
applications/bdmtoolbox/mex/simulator.cpp
r676 r700 39 39 */ 40 40 41 #include "estim/arx.h"42 #include "stat/emix.h"43 #include "base/datasources.h"44 #include "base/loggers.h"41 #include <estim/arx.h> 42 #include <stat/emix.h> 43 #include <base/datasources.h> 44 #include <base/loggers.h> 45 45 46 46 //#include "mex_datasource.h" … … 104 104 105 105 shared_ptr<DS> Ds = UI::build<DS> ( Cfg, "system" ); 106 longNdat=10;106 int Ndat=10; 107 107 if ( Cfg.exists ( "experiment" ) ) { 108 108 if ( Cfg.lookupValue ( "experiment.ndat",Ndat ) ) { -
applications/bdmtoolbox/tutorial/merging/pdfs.m
r568 r700 38 38 'rv', ab); 39 39 Gb_a=struct('class','mgamma', 'beta',2, 'k',1, 'rv',b, 'rvc',a); % f(b|a) 40 Ga_ =struct('class','mepdf','epdf',Ga); % convert f(a) to f(a|) 41 Gba = struct('class','mprod', 'mpdfs',{{Gb_a,Ga_}}); 40 Gba = struct('class','mprod', 'pdfs',{{Gb_a,Ga}}); 42 41 43 42 pd.Ga=Ga; -
applications/bdmtoolbox/tutorial/userguide/arx_basic_example.m
r631 r700 1 1 % load data created by the MpdfDS_example 2 load mpdfds_results2 load pdfds_results 3 3 4 4 DS.class = 'MemDS'; … … 17 17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 18 18 % plot results 19 ndat = size(M. u,1);19 ndat = size(M.DS_u,1); 20 20 21 21 subplot(1,2,1); 22 22 hold off 23 plot((true_theta' *ones(1,ndat))','-.'); 24 title(' Regression parameters \theta') 25 hold on 26 plot(M.mean_theta(1:ndat,:)); 27 co = get(gca,'ColorOrder'); 28 for i=1:size(M.mean_theta,2) 29 ind =1:10:ndat; 30 h=errorbar(ind,M.mean_theta(ind,i),... 31 M.mean_theta(ind,i)-M.lb_theta(ind,i),M.mean_theta(ind,i)-M.ub_theta(ind,i),'.'); 32 set(h,'color',co(i,:)); 33 end 34 23 plotestimates(true_theta, ... 24 M.Est0_apost_mean_theta, ... 25 M.Est0_apost_lb_theta, ... 26 M.Est0_apost_ub_theta); 35 27 set(gca,'YLim',[-1.5,1]); 36 28 37 29 subplot(1,2,2); 38 30 hold off 39 plot(true_R*ones(1,ndat),'-.'); 31 plotestimates(true_R, ... 32 M.Est0_apost_mean_r, ... 33 M.Est0_apost_lb_r, ... 34 M.Est0_apost_ub_r); 35 40 36 title('Variance parameters r') 41 hold on42 plot(M.mean_r(1:ndat,:));43 co = get(gca,'ColorOrder');44 ind =1:10:ndat;45 for i=1:size(M.mean_r, 2)46 h=errorbar(ind,M.mean_r(ind,i),...47 M.mean_r(ind,i)-M.lb_r(ind,i),M.mean_r(ind,i)-M.ub_r(ind,i),'.');48 set(h,'color',co(i,:));49 end -
applications/bdmtoolbox/tutorial/userguide/arx_selection_example.m
r631 r700 1 1 % load data created by the MpdfDS_example 2 load mpdfds_results2 load pdfds_results 3 3 4 4 DS.class = 'MemDS'; … … 30 30 31 31 %%%% Process results 32 lls = [sum(M.A1 ll) sum(M.A2ll) sum(M.A3ll)]32 lls = [sum(M.A1_ll_ll) sum(M.A2_ll_ll) sum(M.A3_ll_ll)] 33 33 34 34 ells=exp(lls-max(lls)); -
applications/bdmtoolbox/tutorial/userguide/epdfds_example.m
r618 r700 12 12 M=simulator(DS,experiment); 13 13 14 M. a14 M.DS_a -
applications/bdmtoolbox/tutorial/userguide/frg_estim.m
r661 r700 17 17 %%%%%% Random walk on frg - Dirichlet 18 18 phi_pdf.class = 'mDirich'; % random walk on coefficient phi 19 phi_pdf.rv = RV( 'phi',2); % 2D random walk - frg is the first element19 phi_pdf.rv = RV({'phi','1_phi'}); % 2D random walk - frg is the first element 20 20 phi_pdf.k = 0.01; % width of the random walk 21 21 phi_pdf.betac = [0.01 0.01]; % stabilizing elememnt of random walk … … 26 26 E.parameter_pdf = phi_pdf; % Random walk is the parameter evolution model 27 27 E.res_threshold = 1.0; % resampling parameter 28 E.n = 20; % number of particles28 E.n = 10; % number of particles 29 29 E.prior.class = 'eDirich'; % prior on non-linear part 30 30 E.prior.beta = [2 1]; % … … 36 36 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 37 37 % plot results 38 ndat = size(M. u,1);38 ndat = size(M.DS_u,1); 39 39 40 40 figure(1); 41 41 subplot(2,2,1); 42 plotestimates(true_theta, M.MPF mean_theta, M.MPFlb_theta, M.MPFub_theta);42 plotestimates(true_theta, M.MPF_apost_mean_theta, M.MPF_apost_lb_theta, M.MPF_apost_ub_theta); 43 43 title(' Regression parameters \theta') 44 44 set(gca,'YLim',[-1.5,1]); 45 45 46 46 subplot(2,2,2); 47 plotestimates(true_R, M.MPF mean_r,M.MPFlb_r,M.MPFub_r);47 plotestimates(true_R, M.MPF_apost_mean_r,M.MPF_apost_lb_r,M.MPF_apost_ub_r); 48 48 title('Variance parameters r') 49 49 50 50 subplot(2,2,3); 51 plotestimates(1, M.MPF mean_phi(:,1),M.MPFlb_phi(:,1),M.MPFub_phi(:,1));51 plotestimates(1, M.MPF_apost_mean_phi(:,1),M.MPF_apost_lb_phi(:,1),M.MPF_apost_ub_phi(:,1)); 52 52 title('Forgetting factor') 53 53 -
applications/bdmtoolbox/tutorial/userguide/pdfds_example.m
r631 r700 20 20 DS.class = 'MpdfDS'; 21 21 DS.mpdf.class = 'mprod'; 22 DS.mpdf.mpdfs = {fy, epdf2mpdf(fu)};22 DS.mpdf.mpdfs = {fy, fu}; 23 23 DS.init_rv = RVtimes([y,y,y], [-1,-2,-3]); 24 24 DS.init_values = [0.1, 0.2, 0.3]; … … 30 30 31 31 %%% store results 32 Data=[M. y'; M.u'];32 Data=[M.DS_y'; M.DS_u']; 33 33 drv = RVjoin([y,u]); 34 34 true_theta=[fy.A fy.const]; -
applications/pmsm/filters.h
r686 r700 19 19 20 20 //! modelling theta as normal random walk with 2pi correction 21 class rwtheta: public mpdf_internal<enorm<fsqmat> > {21 class rwtheta: public pdf_internal<enorm<fsqmat> > { 22 22 double om_hat_dt; 23 23 double om_var; … … 120 120 pf->prior_from_set ( set ); 121 121 pf->resmethod_from_set ( set ); 122 pf->set_model ( rwt,new mpdf() );122 pf->set_model ( rwt,new pdf() ); 123 123 124 124 shared_ptr<RV> rv = UI::build<RV> ( set, "rv", UI::optional ); -
library/bdm/base/bdmbase.cpp
r693 r700 53 53 id = iter->second; 54 54 if (size>0){ 55 bdm_assert ( SIZES ( id ) == size, "RV " + name + " of different size already exists" );55 bdm_assert ( SIZES ( id ) == size, "RV " + name + " of size " + num2str(SIZES(id)) + " exists, requested size " + num2str(size) + "can not be assigned" ); 56 56 } 57 57 } -
library/bdm/base/bdmbase.h
r693 r700 266 266 //! Minimum time-offset 267 267 int mint() const { 268 return times.length()>0 ? min (times) : 0; 268 return times.length()>0 ? min (times) : 0; 269 } 270 //! Minimum time-offset of ids of given RVs 271 int mint(const RV &rv) const { 272 bvec belong=zeros_b(len); 273 for (int r=0; r<rv.length(); r++){ 274 belong = belong | (ids == rv.id(r)); 275 } 276 return times.length()>0 ? min (times(belong)) : 0; 269 277 } 270 278 //!@} … … 598 606 logrec->L.logit( logrec->ids(0), mean() ); 599 607 } 600 if (log_level> 2) {608 if (log_level>1) { 601 609 vec lb; vec ub; 602 610 qbounds(lb,ub); … … 913 921 //establish c2c connection 914 922 rvc.dataind ( rvc_up, c2c_lo, c2c_up ); 915 bdm_assert_debug ( c2c_lo.length() + v2c_lo.length() == condsize, "cond is not fully given" );923 // bdm_assert_debug ( c2c_lo.length() + v2c_lo.length() == condsize, "cond is not fully given" ); 916 924 } 917 925 … … 919 927 vec get_cond ( const vec &val_up, const vec &cond_up ) { 920 928 vec tmp ( condsize ); 921 set_subvector ( tmp, v2c_lo, val_up ( v2c_up ) ); 922 set_subvector ( tmp, c2c_lo, cond_up ( c2c_up ) ); 929 fill_cond (val_up, cond_up, tmp ); 923 930 return tmp; 931 } 932 //! fill condition 933 void fill_cond ( const vec &val_up, const vec &cond_up, vec& cond_out){ 934 bdm_assert_debug(cond_out.length()>=condsize,"dl.fill_cond: cond_out is too small"); 935 set_subvector ( cond_out, v2c_lo, val_up ( v2c_up ) ); 936 set_subvector ( cond_out, c2c_lo, cond_up ( c2c_up ) ); 924 937 } 925 938 //! Fill … … 1077 1090 1078 1091 BM() : yrv(),dimy(0),rvc(),dimc(0), ll ( 0 ), evalll ( true ) { }; 1079 BM ( const BM &B ) : yrv ( B.yrv ), dimy(B.dimy), rvc ( B.rvc), ll ( B.ll ), evalll ( B.evalll ) {}1092 // BM ( const BM &B ) : yrv ( B.yrv ), dimy(B.dimy), rvc ( B.rvc ),dimc(B.dimc), ll ( B.ll ), evalll ( B.evalll ) {} 1080 1093 //! \brief Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually! 1081 1094 //! Prototype: \code BM* _copy_() const {return new BM(*this);} \endcode -
library/bdm/base/datasources.h
r697 r700 132 132 dt = zeros(iepdf->dimension()); 133 133 dtsize=dt.length(); 134 ytsize=dt.length(); 134 135 set_drv(iepdf->_rv(),RV()); 135 136 utsize =0; … … 365 366 class = "stateDS"; 366 367 //Internal model 367 IM = { type = " mpdf-offspring"; };368 IM = { type = "pdf-offspring"; }; 368 369 //Observation model 369 OM = { type = " mpdf-offspring"; }370 OM = { type = "pdf-offspring"; } 370 371 //initial state 371 372 x0 = [...]; //vector of data -
library/bdm/estim/arx.cpp
r679 r700 2 2 namespace bdm { 3 3 4 void ARX::bayes_weighted ( const vec &yt, const vec &cond, const double w ) { 4 void ARX::bayes_weighted ( const vec &yt, const vec &cond, const double w ) { 5 6 bdm_assert_debug(yt.length()>=dimy,"ARX::bayes yt is smaller then dimc"); 7 bdm_assert_debug(cond.length()>=dimc,"ARX::bayes cond is smaller then dimc"); 5 8 double lnc; 6 9 //cache -
library/bdm/estim/arx.h
r679 r700 54 54 //! \name Constructors 55 55 //!@{ 56 ARX ( const double frg0 = 1.0 ) : BMEF ( frg0 ), have_constant(true), dyad(), est() {};57 ARX ( const ARX &A0 ) : BMEF (A0 .frg), have_constant(A0.have_constant), dyad(A0.dyad),est(est) { };56 ARX ( const double frg0 = 1.0 ) : BMEF ( frg0 ), have_constant(true), dyad(), est(), alter_est() {}; 57 ARX ( const ARX &A0 ) : BMEF (A0), have_constant(A0.have_constant), dyad(A0.dyad),est(A0.est),alter_est(A0.alter_est) { }; 58 58 ARX* _copy_() const; 59 59 void set_parameters ( double frg0 ) { … … 167 167 /*! ARX model conditined by knowledge of the forgetting factor 168 168 \f[ f(\theta| d_1 \ldots d_t , \phi_t) \f] 169 170 The symbol \f$ \phi \f$ is assumed to be the last of the conditioning variables. 169 171 */ 170 172 class ARXfrg : public ARX{ … … 174 176 ARXfrg(const ARXfrg &A0):ARX(A0){}; 175 177 ARXfrg* _copy_() const {ARXfrg *A = new ARXfrg(*this); return A;} 176 void condition(const vec &val){ 177 frg = val(0); 178 179 void bayes(const vec &val, const vec &cond){ 180 frg = cond(dimc-1); // last in cond is phi 181 ARX::bayes(val,cond); 182 } 183 void validate() { 184 ARX::validate(); 185 rvc.add(RV("{phi }",vec_1(1))); 186 dimc +=1; 178 187 } 179 188 }; -
library/bdm/estim/particles.cpp
r679 r700 78 78 int n=pf->__w().length(); 79 79 vec &lls = pf->_lls(); 80 Array<vec> &samples=pf->__samples(); 80 81 81 82 // generate samples - time step … … 84 85 #pragma parallel for 85 86 for ( i = 0; i < n; i++ ) { 86 BMs(i) -> bayes(this2bm.pushdown(yt), this2bm.get_cond(yt,cond)); 87 vec bm_cond(BMs(i)->dimensionc()); 88 this2bm.fill_cond(yt,cond, bm_cond); 89 pf2bm.filldown(samples(i), bm_cond); 90 BMs(i) -> bayes(this2bm.pushdown(yt), bm_cond); 87 91 lls ( i ) += BMs(i)->_ll(); 88 92 } -
library/bdm/estim/particles.h
r693 r700 157 157 res_threshold=0.5; 158 158 } 159 validate();159 //validate(); 160 160 } 161 161 //! load prior information from set and set internal structures accordingly … … 177 177 178 178 void validate(){ 179 bdm_assert(par,"PF::parameter_pdf not specified."); 179 180 n=_w.length(); 180 181 lls=zeros(n); 182 181 183 if (par->_rv()._dsize()>0) { 182 184 bdm_assert(par->_rv()._dsize()==est.dimension(),"Mismatch of RV and dimension of posterior" ); … … 301 303 //! datalink from global yt and cond (Up) to PFs yt and cond (Down) 302 304 datalink_m2m this2pf; 305 //!datalink from PF part to BM 306 datalink_part pf2bm; 303 307 304 308 public: … … 367 371 } 368 372 //set drv 373 //??set_yrv(concat(BM0->_yrv(),u) ); 374 set_yrv(BM0->_yrv() ); 375 rvc = BM0->_rvc().subt(par->_rv()); 369 376 //find potential input - what remains in rvc when we subtract rv 370 RV u = par->_rvc().remove_time().subt( par->_rv() ); 371 set_yrv(concat(BM0->_yrv(),u) ); 377 RV u = par->_rvc().subt( par->_rv().copy_t(-1) ); 378 rvc.add(u); 379 dimc = rvc._dsize(); 372 380 validate(); 373 381 } 374 382 void validate(){ 375 383 try{ 376 pf->validate();384 pf->validate(); 377 385 } catch (std::exception &e){ 378 386 throw UIException("Error in PF part of MPF:"); … … 380 388 jest.read_parameters(); 381 389 this2bm.set_connection(BMs(0)->_yrv(), BMs(0)->_rvc(), yrv, rvc); 382 this2bm.set_connection(pf->_yrv(), pf->_rvc(), yrv, rvc); 390 this2pf.set_connection(pf->_yrv(), pf->_rvc(), yrv, rvc); 391 pf2bm.set_connection(BMs(0)->_rvc(), pf->posterior()._rv()); 383 392 } 384 393 -
library/bdm/math/square_mat.h
r619 r700 221 221 //! print full matrix 222 222 friend std::ostream &operator<< ( std::ostream &os, const fsqmat &sq ); 223 //!access function 224 mat & _M ( ) {return M;}; 223 225 224 226 }; -
library/bdm/mex/config2mxstruct.h
r665 r700 2 2 #define CFGSTR_H 3 3 4 #include "../base/libconfig/lib config.h++"4 #include "../base/libconfig/lib/libconfig.h++" 5 5 #include <itpp/itbase.h> 6 6 #include <itpp/itmex.h> -
library/bdm/mex/mex_parser.h
r691 r700 3 3 4 4 5 #include " ../base/libconfig/lib/lib/libconfig.h++"5 #include "base/libconfig/lib/libconfig.h++" 6 6 #include <itpp/itbase.h> 7 7 #include <itpp/itmex.h> -
library/tests/CMakeLists.txt
r693 r700 41 41 # using UnitTest++ 42 42 43 SET(unit_test_configurations mepdf.cfgegiw.cfg mlnorm.cfg edirich.cfg mprod.cfg generator.cfg epdfds.cfg pdfds.cfg test_user_info_input.cfg merger.cfg erroneous.cfg egamma.cfg test_user_info_external.cfg merger_error.cfg mgamma.cfg enorm.cfg)43 SET(unit_test_configurations egiw.cfg mlnorm.cfg edirich.cfg mprod.cfg generator.cfg epdfds.cfg pdfds.cfg test_user_info_input.cfg merger.cfg erroneous.cfg egamma.cfg test_user_info_external.cfg merger_error.cfg mgamma.cfg enorm.cfg) 44 44 45 45 add_executable(testsuite arx_straux_test.cpp datalink_test.cpp datasource_test.cpp egiw_test.cpp emix_test.cpp epdf_test.cpp logger_test.cpp LQG_test.cpp merger_test.cpp