Changeset 723 for applications/dual

Show
Ignore:
Timestamp:
11/15/09 23:02:02 (15 years ago)
Author:
smidl
Message:

Big commit of LQG stuff

Location:
applications/dual
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • applications/dual/experiment/itermc.m

    r706 r723  
    2525    c.controller = C1; 
    2626    Mmc=iterativemc(c); 
    27     losses(i) = sum((Mmc.y-yr*ones(size(Mmc.y))).^2); 
     27    losses(i) = sum((Mmc.S_y-yr*ones(size(Mmc.S_y))).^2); 
    2828     
    2929    c.controller = C2; 
    3030    Mmc=iterativemc(c); 
    31     losses2(i) = sum((Mmc.y-yr*ones(size(Mmc.y))).^2); 
     31    looo= sum((Mmc.S_y-yr*ones(size(Mmc.S_y))).^2) 
     32%     keyboard 
     33    losses2(i) = looo; 
    3234end 
    3335[min(losses) median(losses) max(losses)] 
  • applications/dual/src/arx1_ctrl.h

    r706 r723  
    2121                void set_b (const double b0){b=b0;} 
    2222                //! data in ctrlaction are only past outputs yt 
    23                 vec ctrlaction(const vec &yt){ 
     23                vec ctrlaction(const vec &yt)const{ 
    2424                        vec ut(1); 
    2525                        if (abs(b)<1e-2) { 
     
    6363        public: 
    6464                //! expected input is yt 
    65                 virtual void adapt(const vec &yt){ 
     65                virtual void adapt(const vec &dt){ 
    6666                        //prepare data for ARX 
    67                         Psi(0) = yt(0)-ytm; 
    68                         Psi(1) = utm; 
    6967                        // do estimation 
    70                         est.bayes(Psi); 
     68                        est.bayes(vec_1(dt(0)-ytm),vec_1(dt(1))); 
     69                        ytm = dt(0); 
    7170                        // save estimate b = E(b); 
    7271                        b = est.posterior().mean()(0); // first 
    7372                } 
    7473                //! 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)));; 
    7778                        // remember last ut for estimation 
    78                         utm=ut(0); 
    79                         ytm=yt(0); 
    8079                        return ut; 
    8180                } 
     
    9291                        V0(1,0) = b0; 
    9392                        V0(0,1) = b0; 
    94                         V0(1,1) = P0; 
     93                        V0(1,1) = P0/6; 
    9594                         
    96                         est.set_statistics(1,V0); 
     95                        est.set_statistics(1,V0,6); 
    9796                        est.set_constant(false); 
     97                        est.validate(); 
    9898                        validate(); 
    9999                } 
    100100                void validate(){ 
    101101                        Psi = zeros(2); 
    102                         LIDs = zeros_i(1); 
    103102                } 
    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(); 
    106109                } 
    107                 virtual void logit ( logger &L ) { 
    108                         L.logit ( LIDs ( 0 ), b ); 
    109                 } 
    110                  
    111110}; 
    112111UIREGISTER(ce_ctrl); 
  • applications/dual/src/iterativemc.cpp

    r706 r723  
    4747        double b; 
    4848        double sigma; 
    49         double ytm; 
     49        double ytm=0.0; 
    5050        double yr; 
    5151        int Ndat; 
     
    9191        RV y("y",1); // name random variable 
    9292        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"); 
    9696        L->init(); 
    9797         
    9898        vec psi(2);       // regressor 
    99         double ut;        // input 
     99        double ut=0.0;        // input 
    100100        vec yt; 
    101101         
     
    103103                //yt has now meaning of yt-1 
    104104                //design controller 
    105                 C->adapt(vec_1(ytm)); 
    106                 ut = C->ctrlaction(vec_1(ytm))(0);   // the best controller there is 
     105                C->adapt(vec_2(ytm,ut)); 
     106                ut = C->ctrlaction(vec_2(ytm,ut))(0);   // the best controller there is 
    107107                 
    108108                //prepare regressor 
     
    116116                L->logit(L_yt, yt); 
    117117                L->logit(L_ut, vec_1(ut)); 
    118                 C->logit(*L); 
     118                C->log_write(); 
    119119                L->step(); 
    120120        }