Index: applications/dual/experiment/itermc.m
===================================================================
--- applications/dual/experiment/itermc.m (revision 706)
+++ applications/dual/experiment/itermc.m (revision 723)
@@ -25,9 +25,11 @@
     c.controller = C1;
     Mmc=iterativemc(c);
-    losses(i) = sum((Mmc.y-yr*ones(size(Mmc.y))).^2);
+    losses(i) = sum((Mmc.S_y-yr*ones(size(Mmc.S_y))).^2);
     
     c.controller = C2;
     Mmc=iterativemc(c);
-    losses2(i) = sum((Mmc.y-yr*ones(size(Mmc.y))).^2);
+    looo= sum((Mmc.S_y-yr*ones(size(Mmc.S_y))).^2)
+%     keyboard
+    losses2(i) = looo;
 end
 [min(losses) median(losses) max(losses)]
Index: applications/dual/src/arx1_ctrl.h
===================================================================
--- applications/dual/src/arx1_ctrl.h (revision 706)
+++ applications/dual/src/arx1_ctrl.h (revision 723)
@@ -21,5 +21,5 @@
 		void set_b (const double b0){b=b0;}
 		//! data in ctrlaction are only past outputs yt
-		vec ctrlaction(const vec &yt){
+		vec ctrlaction(const vec &yt)const{
 			vec ut(1);
 			if (abs(b)<1e-2) {
@@ -63,19 +63,18 @@
 	public:
 		//! expected input is yt
-		virtual void adapt(const vec &yt){
+		virtual void adapt(const vec &dt){
 			//prepare data for ARX
-			Psi(0) = yt(0)-ytm;
-			Psi(1) = utm;
 			// do estimation
-			est.bayes(Psi);
+			est.bayes(vec_1(dt(0)-ytm),vec_1(dt(1)));
+			ytm = dt(0);
 			// save estimate b = E(b);
 			b = est.posterior().mean()(0); // first
 		}
 		//! same as exact control, but stores ut as utm
-		vec ctrlaction(const vec &yt){
-			vec ut=exact_ctrl::ctrlaction(yt);
+		vec ctrlaction(const vec &dt)const{
+			vec ut(1);
+			mat P = est.posterior().variance();
+			ut(0) =(yr - dt(0))/(b + (b<0 ? P(0,0) : -P(0,0)));;
 			// remember last ut for estimation
-			utm=ut(0);
-			ytm=yt(0);
 			return ut;
 		}
@@ -92,21 +91,21 @@
 			V0(1,0) = b0;
 			V0(0,1) = b0;
-			V0(1,1) = P0;
+			V0(1,1) = P0/6;
 			
-			est.set_statistics(1,V0);
+			est.set_statistics(1,V0,6);
 			est.set_constant(false);
+			est.validate();
 			validate();
 		}
 		void validate(){
 			Psi = zeros(2);
-			LIDs = zeros_i(1);
 		}
-		virtual void log_add ( logger &L, const string &name = "" ) {
-			LIDs ( 0 ) = L.add ( RV("bhat",1) );
+		void log_register( logger& L, const string& prefix ){
+			est.set_log_level(1);
+			est.log_register(L,"");
+		};
+		void log_write() const{
+			est.log_write();
 		}
-		virtual void logit ( logger &L ) {
-			L.logit ( LIDs ( 0 ), b );
-		}
-		
 };
 UIREGISTER(ce_ctrl);
Index: applications/dual/src/iterativemc.cpp
===================================================================
--- applications/dual/src/iterativemc.cpp (revision 706)
+++ applications/dual/src/iterativemc.cpp (revision 723)
@@ -47,5 +47,5 @@
 	double b;
 	double sigma;
-	double ytm;
+	double ytm=0.0;
 	double yr;
 	int Ndat;
@@ -91,11 +91,11 @@
 	RV y("y",1); // name random variable
 	RV u("u",1); // name random variable
-	int L_yt=L->add(y);
-	int L_ut=L->add(u);
-	C->log_add(*L);
+	int L_yt=L->add(y,"S");
+	int L_ut=L->add(u,"S");
+	C->log_register(*L,"C");
 	L->init();
 	
 	vec psi(2);       // regressor
-	double ut;        // input
+	double ut=0.0;        // input
 	vec yt;
 	
@@ -103,6 +103,6 @@
 		//yt has now meaning of yt-1
 		//design controller
-		C->adapt(vec_1(ytm));
-		ut = C->ctrlaction(vec_1(ytm))(0);   // the best controller there is
+		C->adapt(vec_2(ytm,ut));
+		ut = C->ctrlaction(vec_2(ytm,ut))(0);   // the best controller there is
 		
 		//prepare regressor
@@ -116,5 +116,5 @@
 		L->logit(L_yt, yt);
 		L->logit(L_ut, vec_1(ut));
-		C->logit(*L);
+		C->log_write();
 		L->step();
 	}
Index: applications/bdmtoolbox/mex/estimator.cpp
===================================================================
--- applications/bdmtoolbox/mex/estimator.cpp (revision 706)
+++ applications/bdmtoolbox/mex/estimator.cpp (revision 723)
@@ -195,5 +195,5 @@
 		//update buffered fdat links
 		for (int i=0; i<Dls_buf.length(); i++){
-			Dls_buf(i)->step(dt);
+			Dls_buf(i)->store_data(dt);
 		}
 			
Index: applications/bdmtoolbox/mex/controlloop.cpp
===================================================================
--- applications/bdmtoolbox/mex/controlloop.cpp (revision 706)
+++ applications/bdmtoolbox/mex/controlloop.cpp (revision 723)
@@ -103,5 +103,5 @@
 
 	//DBG
-	Cfg.writeFile ( "closedloop.cfg" );
+	Cfg.writeFile ( "controlloop.cfg" );
 
 #else
@@ -111,5 +111,5 @@
 		fname = argv[1];
 	} else {
-		fname="closedloop.cfg";
+		fname="controlloop.cfg";
 	}
 	UIFile Cfg ( fname );
@@ -119,5 +119,5 @@
 	Array<shared_ptr<Controller> > Cs;
 	UI::get ( Cs,Cfg, "controllers" );
-	int Ndat=10;
+	int Ndat=100;
 	if ( Cfg.exists ( "experiment" ) ) {
 		if ( Cfg.getRoot().lookupValue ( "experiment.ndat",Ndat ) ) {
@@ -187,6 +187,9 @@
 				Cs(i) -> adapt( Dlsc(i) ->pushdown(dt));
 				vec ut=Cs ( i )->ctrlaction ( Dlsc(i) ->pushdown(dt) );		// update estimates
-				Ds->write(ut, vec_1(1));
+				Ds->write(ut, vec_1(0));
+			} else {
+				Ds->write(0.001*randn(Ds->_urv()._dsize()));
 			}
+			
 			Cs ( i )->log_write ();
 		}
@@ -196,5 +199,5 @@
 		//update buffered fdat links
 		for (int i=0; i<Dls_buf.length(); i++){
-			Dls_buf(i)->step(dt);
+			Dls_buf(i)->store_data(dt);
 		}
 			
