Changeset 723 for applications/dual/src
- Timestamp:
- 11/15/09 23:02:02 (15 years ago)
- Location:
- applications/dual/src
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
applications/dual/src/arx1_ctrl.h
r706 r723 21 21 void set_b (const double b0){b=b0;} 22 22 //! data in ctrlaction are only past outputs yt 23 vec ctrlaction(const vec &yt) {23 vec ctrlaction(const vec &yt)const{ 24 24 vec ut(1); 25 25 if (abs(b)<1e-2) { … … 63 63 public: 64 64 //! expected input is yt 65 virtual void adapt(const vec & yt){65 virtual void adapt(const vec &dt){ 66 66 //prepare data for ARX 67 Psi(0) = yt(0)-ytm;68 Psi(1) = utm;69 67 // do estimation 70 est.bayes(Psi); 68 est.bayes(vec_1(dt(0)-ytm),vec_1(dt(1))); 69 ytm = dt(0); 71 70 // save estimate b = E(b); 72 71 b = est.posterior().mean()(0); // first 73 72 } 74 73 //! same as exact control, but stores ut as utm 75 vec ctrlaction(const vec &yt){ 76 vec ut=exact_ctrl::ctrlaction(yt); 74 vec ctrlaction(const vec &dt)const{ 75 vec ut(1); 76 mat P = est.posterior().variance(); 77 ut(0) =(yr - dt(0))/(b + (b<0 ? P(0,0) : -P(0,0)));; 77 78 // remember last ut for estimation 78 utm=ut(0);79 ytm=yt(0);80 79 return ut; 81 80 } … … 92 91 V0(1,0) = b0; 93 92 V0(0,1) = b0; 94 V0(1,1) = P0 ;93 V0(1,1) = P0/6; 95 94 96 est.set_statistics(1,V0 );95 est.set_statistics(1,V0,6); 97 96 est.set_constant(false); 97 est.validate(); 98 98 validate(); 99 99 } 100 100 void validate(){ 101 101 Psi = zeros(2); 102 LIDs = zeros_i(1);103 102 } 104 virtual void log_add ( logger &L, const string &name = "" ) { 105 LIDs ( 0 ) = L.add ( RV("bhat",1) ); 103 void log_register( logger& L, const string& prefix ){ 104 est.set_log_level(1); 105 est.log_register(L,""); 106 }; 107 void log_write() const{ 108 est.log_write(); 106 109 } 107 virtual void logit ( logger &L ) {108 L.logit ( LIDs ( 0 ), b );109 }110 111 110 }; 112 111 UIREGISTER(ce_ctrl); -
applications/dual/src/iterativemc.cpp
r706 r723 47 47 double b; 48 48 double sigma; 49 double ytm ;49 double ytm=0.0; 50 50 double yr; 51 51 int Ndat; … … 91 91 RV y("y",1); // name random variable 92 92 RV u("u",1); // name random variable 93 int L_yt=L->add(y );94 int L_ut=L->add(u );95 C->log_ add(*L);93 int L_yt=L->add(y,"S"); 94 int L_ut=L->add(u,"S"); 95 C->log_register(*L,"C"); 96 96 L->init(); 97 97 98 98 vec psi(2); // regressor 99 double ut ; // input99 double ut=0.0; // input 100 100 vec yt; 101 101 … … 103 103 //yt has now meaning of yt-1 104 104 //design controller 105 C->adapt(vec_ 1(ytm));106 ut = C->ctrlaction(vec_ 1(ytm))(0); // the best controller there is105 C->adapt(vec_2(ytm,ut)); 106 ut = C->ctrlaction(vec_2(ytm,ut))(0); // the best controller there is 107 107 108 108 //prepare regressor … … 116 116 L->logit(L_yt, yt); 117 117 L->logit(L_ut, vec_1(ut)); 118 C->log it(*L);118 C->log_write(); 119 119 L->step(); 120 120 }