Index: library/bdm/mex/mex_parser.h
===================================================================
--- library/bdm/mex/mex_parser.h (revision 599)
+++ library/bdm/mex/mex_parser.h (revision 613)
@@ -51,5 +51,9 @@
 			mexErrMsgTxt ( "Given mxArray is not numeric." );
 		};
-		mat val = mxArray2mat ( value );
+		//treat empty matrices independently
+		mat val;
+		if (mxGetM(value)>0) {
+			val = mxArray2mat ( value );
+		}
 		if ( ( val.rows() == 1 ) && ( val.cols() == 1 ) ) {
 			Setting &child = ( key == "" ) ? setting.add ( Setting::TypeFloat )
Index: library/bdm/base/bdmbase.h
===================================================================
--- library/bdm/base/bdmbase.h (revision 610)
+++ library/bdm/base/bdmbase.h (revision 613)
@@ -710,7 +710,7 @@
 	//! push current data to history
 	void step ( const vec &val_up ) {
-		if ( Hrv._dsize() > 0 ) {
-			history.shift_right ( 0, Hrv._dsize() );
-		  history.set_subvector ( 0, val_up(v2h_up) ); // write U after Drv
+		if ( v2h_up.length() > 0 ) {
+			history.shift_right ( 0, v2h_up.length() );
+		  history.set_subvector ( 0, val_up(v2h_up) ); 
 		}
 	}
@@ -748,4 +748,12 @@
 		downsize = v2v_down.length() + h2v_down.length();
 		upsize = v2v_up.length();
+	}
+	//! set history of variable given by \c rv1 to values of \c hist.
+	void set_history(const RV& rv1, const vec &hist0){
+		bdm_assert(rv1._dsize()==hist0.length(),"hist is not compatible with given rv1");
+		ivec ind_H;
+		ivec ind_h0;
+		Hrv.dataind(rv1, ind_H, ind_h0); // find indeces of rv in 
+		set_subvector(history, ind_H, hist0(ind_h0)); // copy given hist to appropriate places
 	}
 };
@@ -964,5 +972,4 @@
 		bdm_error ( "abstract class" );
 	}
-
 	//! Returns data records at indeces.
 	virtual void getdata ( vec &dt, const ivec &indeces ) {
Index: library/bdm/base/datasources.h
===================================================================
--- library/bdm/base/datasources.h (revision 611)
+++ library/bdm/base/datasources.h (revision 613)
@@ -128,8 +128,11 @@
 			iepdf=UI::build<epdf> ( set,"epdf",UI::compulsory );
 			bdm_assert(iepdf->isnamed(), "Input epdf must be named, check if RV is given correctly");
-			dt =  iepdf->sample();
+			dt =  zeros(iepdf->dimension());
 			dtsize=dt.length();
 			set_drv(iepdf->_rv(),RV());
 			utsize =0;
+		}
+		void validate() {
+			dt = iepdf->sample();
 		}
 };
@@ -172,7 +175,11 @@
 		\code
 		class = "MpdfDS";
-		mpdf = {class="mpdf_offspring", ...}// mpdf to simulate
+		mpdf = {class="mpdf_offspring", ...};  // mpdf to simulate
+		--- optional ---
+		init_rv = {class="RV",names=...};      // define what rv to initialize - typically delayed values!
+		init_values = [...];                   // vector of initial values corresponding to init_rv
 		\endcode
 
+		If init_rv is not given, init_values are set to zero.
 		*/
 		void from_setting ( const Setting &set ) {
@@ -188,4 +195,17 @@
 			ut2rgr.set_connection(impdf->_rvc(), Urv); 
 			yt2rgr.set_connection(impdf->_rvc(), Yrv); 
+			
+			//set history - if given
+			shared_ptr<RV> rv_ini=UI::build<RV>(set,"init_rv",UI::optional);
+			if(rv_ini){ // check if 
+				vec val;
+				UI::get(val, set, "init_values", UI::optional);
+				if (val.length()!=rv_ini->_dsize()){
+					bdm_error("init_rv and init_values fields have incompatible sizes");
+				} else {
+					ut2rgr.set_history(*rv_ini, val);
+					yt2rgr.set_history(*rv_ini, val);
+				}
+			}
 
 			yt = zeros ( impdf->dimension() );
@@ -196,4 +216,11 @@
 			utsize=ut.length();
 			dtsize = ytsize+utsize;
+			validate();
+		}
+		void validate() {
+			//taken from sample() - shift of history is not done here
+			ut2rgr.filldown ( ut,rgr );
+			yt2rgr.filldown ( yt,rgr );
+			yt=impdf->samplecond ( rgr );
 		}
 };
Index: library/bdm/stat/exp_family.h
===================================================================
--- library/bdm/stat/exp_family.h (revision 612)
+++ library/bdm/stat/exp_family.h (revision 613)
@@ -561,5 +561,5 @@
 			bdm_assert_debug (A0.rows() == mu0.length(), "mlnorm: A vs. mu mismatch");
 			bdm_assert_debug (A0.rows() == R0.rows(), "mlnorm: A vs. R mismatch");
-
+			
 			this->iepdf.set_parameters (zeros (A0.rows()), R0);
 			A = A0;
@@ -684,7 +684,4 @@
 		//! constructor function
 		void set_parameters (const mat &A0, const vec &mu0, const ldmat &R0, const ldmat& Lambda0) {
-			bdm_assert_debug (A0.rows() == mu0.length(), "mlstudent: A vs. mu mismatch");
-			bdm_assert_debug (R0.rows() == A0.rows(), "mlstudent: A vs. R mismatch");
-
 			iepdf.set_parameters (mu0, R0);// was Lambda, why?
 			A = A0;
@@ -706,4 +703,9 @@
 		};
 
+		void validate() {
+			bdm_assert_debug (A.rows() == mu_const.length(), "mlstudent: A vs. mu mismatch");
+			bdm_assert_debug (_R.rows() == A.rows(), "mlstudent: A vs. R mismatch");
+			
+		}
 };
 /*!
