Index: library/bdm/base/user_info.h
===================================================================
--- library/bdm/base/user_info.h (revision 565)
+++ library/bdm/base/user_info.h (revision 600)
@@ -234,5 +234,5 @@
 user-infos.
 
-See static methods 'build', 'get' and 'save'. Writing user-infos with these methods is rather  simple. The
+See static methods 'build', 'get' and 'save'. Writing user-infos with these methods is rather simple. The
 rest of this class is intended for internal purposes only. Its meaning is to allow pointers to its templated
 descendant ParticularUI<T>.
Index: library/bdm/base/bdmbase.h
===================================================================
--- library/bdm/base/bdmbase.h (revision 598)
+++ library/bdm/base/bdmbase.h (revision 600)
@@ -25,25 +25,16 @@
 using namespace std;
 
-namespace bdm
-{
-
-typedef std::map<string, int> RVmap;
-//! Internal global variable storing sizes of RVs
-extern ivec RV_SIZES;
-//! Internal global variable storing names of RVs
-extern Array<string> RV_NAMES;
-
+namespace bdm {
 //! Structure of RV, i.e. RVs expanded into a flat list of IDs, used for debugging.
-class str
-{
-	public:
-		//! vector id ids (non-unique!)
-		ivec ids;
-		//! vector of times
-		ivec times;
-		//!Default constructor
-		str (ivec ids0, ivec times0) : ids (ids0), times (times0) {
-			bdm_assert_debug (times0.length() == ids0.length(), "Incompatible input");
-		};
+class str {
+public:
+	//! vector id ids (non-unique!)
+	ivec ids;
+	//! vector of times
+	ivec times;
+	//!Default constructor
+	str ( ivec ids0, ivec times0 ) : ids ( ids0 ), times ( times0 ) {
+		bdm_assert_debug ( times0.length() == ids0.length(), "Incompatible input" );
+	};
 };
 
@@ -61,5 +52,5 @@
 subgraph cluster0 {
 node [shape=record];
-label = "RV_MAP \n std::map<string,int>";
+label = "MAP \n std::map<string,int>";
 map [label="{{\"a\"| \"b\" | \"c\"} | {<3> 3 |<1> 1|<2> 2}}"];
 color = "white"
@@ -67,5 +58,5 @@
 subgraph cluster1{
 node [shape=record];
-label = "RV_NAMES";
+label = "NAMES";
 names [label="{<1> \"b\" | <2> \"c\" | <3>\"a\" }"];
 color = "white"
@@ -73,5 +64,5 @@
 subgraph cluster2{
 node [shape=record];
-label = "RV_SIZES";
+label = "SIZES";
 labelloc = b;
 sizes [label="{<1>1 |<2> 4 |<3> 1}"];
@@ -86,476 +77,495 @@
 */
 
-class RV : public root
-{
-	protected:
-		//! size of the data vector
-		int dsize;
-		//! number of individual rvs
-		int len;
-		//! Vector of unique IDs
-		ivec ids;
-		//! Vector of shifts from current time
-		ivec times;
-
-	private:
-	  enum enum_dummy {dummy};
-		//! auxiliary function used in constructor
-		void init (const Array<std::string> &in_names, const ivec &in_sizes, const ivec &in_times);
-		int init (const string &name, int size);
-		//! Private constructor from IDs, potentially dangerous since all ids must be valid!
-		//! dummy is there to prevent confusion with RV(" string");
-		explicit RV (const ivec &ids0, enum_dummy dum): dsize(0), len(ids0.length()), ids(ids0), times(zeros_i(ids0.length())) {
-		  dsize = countsize();
-		}
-	public:
-		//! \name Constructors
-		//!@{
-
-		//! Full constructor
-		RV (const Array<std::string> &in_names, const ivec &in_sizes, const ivec &in_times) {
-			init (in_names, in_sizes, in_times);
-		}
-
-		//! Constructor with times=0
-		RV (const Array<std::string> &in_names, const ivec &in_sizes) {
-			init (in_names, in_sizes, zeros_i (in_names.length()));
-		}
-
-		//! Constructor with sizes=1, times=0
-		RV (const Array<std::string> &in_names) {
-			init (in_names, ones_i (in_names.length()), zeros_i (in_names.length()));
-		}
-
-		//! Constructor of empty RV
-		RV() : dsize (0), len (0), ids (0), times (0) {}
-
-		//! Constructor of a single RV with given id
-		RV (string name, int sz, int tm = 0);
-
-		// compiler-generated copy constructor is used
-		//!@}
-
-		//! \name Access functions
-		//!@{
-
-		//! State output, e.g. for debugging.
-		friend std::ostream &operator<< (std::ostream &os, const RV &rv);
-
-		int _dsize() const {
-			return dsize;
-		}
-		
-		//! access function
-		const ivec& _ids() const { return ids;}
-
-		//! Recount size of the corresponding data vector
-		int countsize() const;
-		ivec cumsizes() const;
-		int length() const {
-			return len;
-		}
-		int id (int at) const {
-			return ids (at);
-		}
-		int size (int at) const {
-			return RV_SIZES (ids (at));
-		}
-		int time (int at) const {
-			return times (at);
-		}
-		std::string name (int at) const {
-			return RV_NAMES (ids (at));
-		}
-		void set_time (int at, int time0) {
-			times (at) = time0;
-		}
-		//!@}
-
-		//! \name Algebra on Random Variables
-		//!@{
-
-		//! Find indices of self in another rv, \return ivec of the same size as self.
-		ivec findself (const RV &rv2) const;
-		//! Find indices of self in another rv, ignore time, \return ivec of the same size as self.
-		ivec findself_ids (const RV &rv2) const;
-		//! Compare if \c rv2 is identical to this \c RV
-		bool equal (const RV &rv2) const;
-		//! Add (concat) another variable to the current one, \return true if all rv2 were added, false if rv2 is in conflict
-		bool add (const RV &rv2);
-		//! Subtract  another variable from the current one
-		RV subt (const RV &rv2) const;
-		//! Select only variables at indices ind
-		RV subselect (const ivec &ind) const;
-
-		//! Select only variables at indices ind
-		RV operator() (const ivec &ind) const {
-			return subselect (ind);
-		}
-
-		//! Select from data vector starting at di1 to di2
-		RV operator() (int di1, int di2) const;
-
-		//! Shift \c time by delta.
-		void t (int delta);
-		//!@}
-
-		//! @{ \name Auxiliary functions
-		//! returns rvs with time set to 0 and removed duplicates
-		RV remove_time() const {  return RV(unique(ids), dummy);	}
-		//! return rvs with expanded delayes and sorted in the order of: \f$ [ rv_{0}, rv_{-1}, rv_{
-		RV expand_delayes() const {
-		  RV rvt=this->remove_time(); //rv at t=0
-		  RV tmp = rvt;
-		  int td = mint();
-		  for ( int i = -1; i >= td; i-- ) {
+class RV : public root {
+private:
+	typedef std::map<string, int> str2int_map;
+
+	//! Internal global variable storing sizes of RVs
+	static ivec SIZES;
+	//! Internal global variable storing names of RVs
+	static Array<string> NAMES;
+
+	//! TODO
+	const static int BUFFER_STEP;
+
+	//! TODO
+	static str2int_map MAP;
+
+public:
+
+protected:
+	//! size of the data vector
+	int dsize;
+	//! number of individual rvs
+	int len;
+	//! Vector of unique IDs
+	ivec ids;
+	//! Vector of shifts from current time
+	ivec times;
+
+private:
+	enum enum_dummy {dummy};
+
+	//! auxiliary function used in constructor
+	void init ( const Array<std::string> &in_names, const ivec &in_sizes, const ivec &in_times );
+	int init ( const string &name, int size );
+	//! Private constructor from IDs, potentially dangerous since all ids must be valid!
+	//! dummy is there to prevent confusion with RV(" string");
+	explicit RV ( const ivec &ids0, enum_dummy dum ) : dsize ( 0 ), len ( ids0.length() ), ids ( ids0 ), times ( zeros_i ( ids0.length() ) ) {
+		dsize = countsize();
+	}
+public:
+	//! \name Constructors
+	//!@{
+
+	//! Full constructor
+	RV ( const Array<std::string> &in_names, const ivec &in_sizes, const ivec &in_times ) {
+		init ( in_names, in_sizes, in_times );
+	}
+
+	//! Constructor with times=0
+	RV ( const Array<std::string> &in_names, const ivec &in_sizes ) {
+		init ( in_names, in_sizes, zeros_i ( in_names.length() ) );
+	}
+
+	//! Constructor with sizes=1, times=0
+	RV ( const Array<std::string> &in_names ) {
+		init ( in_names, ones_i ( in_names.length() ), zeros_i ( in_names.length() ) );
+	}
+
+	//! Constructor of empty RV
+	RV() : dsize ( 0 ), len ( 0 ), ids ( 0 ), times ( 0 ) {}
+
+	//! Constructor of a single RV with given id
+	RV ( string name, int sz, int tm = 0 );
+
+	// compiler-generated copy constructor is used
+	//!@}
+
+	//! \name Access functions
+	//!@{
+
+	//! State output, e.g. for debugging.
+	friend std::ostream &operator<< ( std::ostream &os, const RV &rv );
+
+	int _dsize() const {
+		return dsize;
+	}
+
+	//! access function
+	const ivec& _ids() const {
+		return ids;
+	}
+
+	//! Recount size of the corresponding data vector
+	int countsize() const;
+	ivec cumsizes() const;
+	int length() const {
+		return len;
+	}
+	int id ( int at ) const {
+		return ids ( at );
+	}
+	int size ( int at ) const {
+		return SIZES ( ids ( at ) );
+	}
+	int time ( int at ) const {
+		return times ( at );
+	}
+	std::string name ( int at ) const {
+		return NAMES ( ids ( at ) );
+	}
+	void set_time ( int at, int time0 ) {
+		times ( at ) = time0;
+	}
+	//!@}
+
+	//! \name Algebra on Random Variables
+	//!@{
+
+	//! Find indices of self in another rv, \return ivec of the same size as self.
+	ivec findself ( const RV &rv2 ) const;
+	//! Find indices of self in another rv, ignore time, \return ivec of the same size as self.
+	ivec findself_ids ( const RV &rv2 ) const;
+	//! Compare if \c rv2 is identical to this \c RV
+	bool equal ( const RV &rv2 ) const;
+	//! Add (concat) another variable to the current one, \return true if all rv2 were added, false if rv2 is in conflict
+	bool add ( const RV &rv2 );
+	//! Subtract  another variable from the current one
+	RV subt ( const RV &rv2 ) const;
+	//! Select only variables at indices ind
+	RV subselect ( const ivec &ind ) const;
+
+	//! Select only variables at indices ind
+	RV operator() ( const ivec &ind ) const {
+		return subselect ( ind );
+	}
+
+	//! Select from data vector starting at di1 to di2
+	RV operator() ( int di1, int di2 ) const;
+
+	//! Shift \c time by delta.
+	void t ( int delta );
+	//!@}
+
+	//! @{ \name Auxiliary functions
+	//! returns rvs with time set to 0 and removed duplicates
+	RV remove_time() const {
+		return RV ( unique ( ids ), dummy );
+	}
+	//! return rvs with expanded delayes and sorted in the order of: \f$ [ rv_{0}, rv_{-1}, rv_{
+	RV expand_delayes() const {
+		RV rvt = this->remove_time(); //rv at t=0
+		RV tmp = rvt;
+		int td = mint();
+		for ( int i = -1; i >= td; i-- ) {
 			rvt.t ( -1 );
 			tmp.add ( rvt ); //shift u1
-		  }
-		  return tmp;
 		}
-		//!@}
-		
-		//!\name Relation to vectors
-		//!@{
-
-		//! generate \c str from rv, by expanding sizes 
-		str tostr() const;
-		//! when this rv is a part of bigger rv, this function returns indices of self in the data vector of the bigger crv.
-		//! Then, data can be copied via: data_of_this = cdata(ind);
-		ivec dataind (const RV &crv) const;
-		//! same as dataind but this time crv should not be complete supperset of rv.
-		ivec dataind_part (const RV &crv) const;
-		//! generate mutual indices when copying data between self and crv.
-		//! Data are copied via: data_of_this(selfi) = data_of_rv2(rv2i)
-		void dataind (const RV &rv2, ivec &selfi, ivec &rv2i) const;
-		//! Minimum time-offset
-		int mint() const {
-			return min (times);
+		return tmp;
+	}
+	//!@}
+
+	//!\name Relation to vectors
+	//!@{
+
+	//! generate \c str from rv, by expanding sizes
+	str tostr() const;
+	//! when this rv is a part of bigger rv, this function returns indices of self in the data vector of the bigger crv.
+	//! Then, data can be copied via: data_of_this = cdata(ind);
+	ivec dataind ( const RV &crv ) const;
+	//! same as dataind but this time crv should not be complete supperset of rv.
+	ivec dataind_part ( const RV &crv ) const;
+	//! generate mutual indices when copying data between self and crv.
+	//! Data are copied via: data_of_this(selfi) = data_of_rv2(rv2i)
+	void dataind ( const RV &rv2, ivec &selfi, ivec &rv2i ) const;
+	//! Minimum time-offset
+	int mint() const {
+		return min ( times );
+	}
+	//!@}
+
+	/*! \brief UI for class RV (description of data vectors)
+
+	\code
+	rv = {
+	    class = "RV"; // class name
+	  // UNIQUE IDENTIFIER same names = same variable
+	  names = ( "a", "b", "c", ...);   // which will be used e.g. in loggers
+
+	  //optional arguments
+	  sizes = [1, 2, 3, ...];         // (optional) default = ones()
+	  times = [-1, -2, 0, ...];       // time shifts with respect to current time (optional) default = zeros()
+	}
+	\endcode
+	*/
+	void from_setting ( const Setting &set );
+
+	// TODO dodelat void to_setting( Setting &set ) const;
+
+	//! Invalidate all named RVs. Use before initializing any RV instances, with care...
+	static void clear_all();
+};
+UIREGISTER ( RV );
+SHAREDPTR ( RV );
+
+//! Concat two random variables
+RV concat ( const RV &rv1, const RV &rv2 );
+
+//! Class representing function \f$f(x)\f$ of variable \f$x\f$ represented by \c rv
+class fnc : public root {
+protected:
+	//! Length of the output vector
+	int dimy;
+public:
+	//!default constructor
+	fnc() {};
+	//! function evaluates numerical value of \f$f(x)\f$ at \f$x=\f$ \c cond
+	virtual vec eval ( const vec &cond ) {
+		return vec ( 0 );
+	};
+
+	//! function substitutes given value into an appropriate position
+	virtual void condition ( const vec &val ) {};
+
+	//! access function
+	int dimension() const {
+		return dimy;
+	}
+};
+
+class mpdf;
+
+//! Probability density function with numerical statistics, e.g. posterior density.
+
+class epdf : public root {
+protected:
+	//! dimension of the random variable
+	int dim;
+	//! Description of the random variable
+	RV rv;
+
+public:
+	/*! \name Constructors
+	 Construction of each epdf should support two types of constructors:
+	\li empty constructor,
+	\li copy constructor,
+
+	The following constructors should be supported for convenience:
+	\li constructor followed by calling \c set_parameters()
+	\li constructor accepting random variables calling \c set_rv()
+
+	 All internal data structures are constructed as empty. Their values (including sizes) will be set by method \c set_parameters(). This way references can be initialized in constructors.
+	@{*/
+	epdf() : dim ( 0 ), rv() {};
+	epdf ( const epdf &e ) : dim ( e.dim ), rv ( e.rv ) {};
+	epdf ( const RV &rv0 ) : dim ( rv0._dsize() ) {
+		set_rv ( rv0 );
+	};
+	void set_parameters ( int dim0 ) {
+		dim = dim0;
+	}
+	//!@}
+
+	//! \name Matematical Operations
+	//!@{
+
+	//! Returns a sample, \f$ x \f$ from density \f$ f_x()\f$
+	virtual vec sample() const {
+		bdm_error ( "not implemented" );
+		return vec();
+	}
+
+	//! Returns N samples, \f$ [x_1 , x_2 , \ldots \ \f$  from density \f$ f_x(rv)\f$
+	virtual mat sample_m ( int N ) const;
+
+	//! Compute log-probability of argument \c val
+	//! In case the argument is out of suport return -Infinity
+	virtual double evallog ( const vec &val ) const {
+		bdm_error ( "not implemented" );
+		return 0.0;
+	}
+
+	//! Compute log-probability of multiple values argument \c val
+	virtual vec evallog_m ( const mat &Val ) const;
+
+	//! Compute log-probability of multiple values argument \c val
+	virtual vec evallog_m ( const Array<vec> &Avec ) const;
+
+	//! Return conditional density on the given RV, the remaining rvs will be in conditioning
+	virtual shared_ptr<mpdf> condition ( const RV &rv ) const;
+
+	//! Return marginal density on the given RV, the remainig rvs are intergrated out
+	virtual shared_ptr<epdf> marginal ( const RV &rv ) const;
+
+	//! return expected value
+	virtual vec mean() const {
+		bdm_error ( "not implemneted" );
+		return vec();
+	}
+
+	//! return expected variance (not covariance!)
+	virtual vec variance() const {
+		bdm_error ( "not implemneted" );
+		return vec();
+	}
+
+	//! Lower and upper bounds of \c percentage % quantile, returns mean-2*sigma as default
+	virtual void qbounds ( vec &lb, vec &ub, double percentage = 0.95 ) const {
+		vec mea = mean();
+		vec std = sqrt ( variance() );
+		lb = mea - 2 * std;
+		ub = mea + 2 * std;
+	};
+	//!@}
+
+	//! \name Connection to other classes
+	//! Description of the random quantity via attribute \c rv is optional.
+	//! For operations such as sampling \c rv does not need to be set. However, for \c marginalization
+	//! and \c conditioning \c rv has to be set. NB:
+	//! @{
+
+	//!Name its rv
+	void set_rv ( const RV &rv0 ) {
+		rv = rv0;
+	}
+
+	//! True if rv is assigned
+	bool isnamed() const {
+		bool b = ( dim == rv._dsize() );
+		return b;
+	}
+
+	//! Return name (fails when isnamed is false)
+	const RV& _rv() const {
+		bdm_assert_debug ( isnamed(), "" );
+		return rv;
+	}
+	//!@}
+
+	//! \name Access to attributes
+	//! @{
+
+	//! Size of the random variable
+	int dimension() const {
+		return dim;
+	}
+	//! Load from structure with elements:
+	//!  \code
+	//! { rv = {class="RV", names=(...),}; // RV describing meaning of random variable
+	//!   // elements of offsprings
+	//! }
+	//! \endcode
+	//!@}
+	void from_setting ( const Setting &set ) {
+		shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional );
+		if ( r ) {
+			set_rv ( *r );
 		}
-		//!@}
-
-		/*! \brief UI for class RV (description of data vectors)
-
-		\code
-		rv = {
-	  	  class = "RV"; // class name
-		  // UNIQUE IDENTIFIER same names = same variable
-		  names = ( "a", "b", "c", ...);   // which will be used e.g. in loggers
-
-		  //optional arguments
-		  sizes = [1, 2, 3, ...];         // (optional) default = ones()
-		  times = [-1, -2, 0, ...];       // time shifts with respect to current time (optional) default = zeros()
+	}
+
+};
+SHAREDPTR ( epdf );
+
+//! Conditional probability density, e.g. modeling \f$ f( x | y) \f$, where \f$ x \f$ is random variable, \c rv, and \f$ y \f$ is conditioning variable, \c rvc.
+class mpdf : public root {
+protected:
+	//!dimension of the condition
+	int dimc;
+	//! random variable in condition
+	RV rvc;
+private:
+	//! internal epdf, used only as cache to avoid virtual calls of \c _rv() and \c _dimension()
+	epdf* ep;
+
+protected:
+	//! set internal pointer \c ep to point to given \c iepdf
+	void set_ep ( epdf &iepdf ) {
+		ep = &iepdf;
+	}
+	//! set internal pointer \c ep to point to given \c iepdf
+	void set_ep ( epdf *iepdfp ) {
+		ep = iepdfp;
+	}
+
+public:
+	//! \name Constructors
+	//! @{
+
+	mpdf() : dimc ( 0 ), rvc(), ep ( NULL ) { }
+
+	mpdf ( const mpdf &m ) : dimc ( m.dimc ), rvc ( m.rvc ), ep ( m.ep ) { }
+	//!@}
+
+	//! \name Matematical operations
+	//!@{
+
+	//! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv
+	virtual vec samplecond ( const vec &cond ) {
+		bdm_error ( "Not implemented" );
+		return vec();
+	}
+
+	//! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv
+	virtual mat samplecond_m ( const vec &cond, int N );
+
+	//! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently.
+	virtual double evallogcond ( const vec &dt, const vec &cond ) {
+		bdm_error ( "Not implemented" );
+		return 0.0;
+	}
+
+	//! Matrix version of evallogcond
+	virtual vec evallogcond_m ( const mat &Dt, const vec &cond ) {
+		vec v ( Dt.cols() );
+		for ( int i = 0; i < Dt.cols(); i++ ) {
+			v ( i ) = evallogcond ( Dt.get_col ( i ), cond );
 		}
-		\endcode
-		*/
-		void from_setting (const Setting &set);
-
-		// TODO dodelat void to_setting( Setting &set ) const;
-		//! Invalidate all named RVs. Use before initializing any RV instances, with care...
-		static void clear_all();
-};
-UIREGISTER (RV);
-SHAREDPTR (RV);
-
-//! Concat two random variables
-RV concat (const RV &rv1, const RV &rv2);
-
-//!Default empty RV that can be used as default argument
-extern RV RV0;
-
-//! Class representing function \f$f(x)\f$ of variable \f$x\f$ represented by \c rv
-
-class fnc : public root
-{
-	protected:
-		//! Length of the output vector
-		int dimy;
-	public:
-		//!default constructor
-		fnc() {};
-		//! function evaluates numerical value of \f$f(x)\f$ at \f$x=\f$ \c cond
-		virtual vec eval (const vec &cond) {
-			return vec (0);
-		};
-
-		//! function substitutes given value into an appropriate position
-		virtual void condition (const vec &val) {};
-
-		//! access function
-		int dimension() const {
-			return dimy;
-		}
-};
-
-class mpdf;
-
-//! Probability density function with numerical statistics, e.g. posterior density.
-
-class epdf : public root
-{
-	protected:
-		//! dimension of the random variable
-		int dim;
-		//! Description of the random variable
-		RV rv;
-
-	public:
-		/*! \name Constructors
-		 Construction of each epdf should support two types of constructors:
-		\li empty constructor,
-		\li copy constructor,
-
-		The following constructors should be supported for convenience:
-		\li constructor followed by calling \c set_parameters()
-		\li constructor accepting random variables calling \c set_rv()
-
-		 All internal data structures are constructed as empty. Their values (including sizes) will be set by method \c set_parameters(). This way references can be initialized in constructors.
-		@{*/
-		epdf() : dim (0), rv() {};
-		epdf (const epdf &e) : dim (e.dim), rv (e.rv) {};
-		epdf (const RV &rv0) : dim (rv0._dsize()) {
-			set_rv (rv0);
-		};
-		void set_parameters (int dim0) {
-			dim = dim0;
-		}
-		//!@}
-
-		//! \name Matematical Operations
-		//!@{
-
-		//! Returns a sample, \f$ x \f$ from density \f$ f_x()\f$
-		virtual vec sample() const {
-			bdm_error ("not implemented");
-			return vec();
-		}
-
-		//! Returns N samples, \f$ [x_1 , x_2 , \ldots \ \f$  from density \f$ f_x(rv)\f$
-		virtual mat sample_m (int N) const;
-
-		//! Compute log-probability of argument \c val
-		//! In case the argument is out of suport return -Infinity
-		virtual double evallog (const vec &val) const {
-			bdm_error ("not implemented");
-			return 0.0;
-		}
-
-		//! Compute log-probability of multiple values argument \c val
-		virtual vec evallog_m (const mat &Val) const;
-
-		//! Compute log-probability of multiple values argument \c val
-		virtual vec evallog_m (const Array<vec> &Avec) const;
-
-		//! Return conditional density on the given RV, the remaining rvs will be in conditioning
-		virtual shared_ptr<mpdf> condition (const RV &rv) const;
-
-		//! Return marginal density on the given RV, the remainig rvs are intergrated out
-		virtual shared_ptr<epdf> marginal (const RV &rv) const;
-
-		//! return expected value
-		virtual vec mean() const {
-			bdm_error ("not implemneted");
-			return vec();
-		}
-
-		//! return expected variance (not covariance!)
-		virtual vec variance() const {
-			bdm_error ("not implemneted");
-			return vec();
-		}
-
-		//! Lower and upper bounds of \c percentage % quantile, returns mean-2*sigma as default
-		virtual void qbounds (vec &lb, vec &ub, double percentage = 0.95) const {
-			vec mea = mean();
-			vec std = sqrt (variance());
-			lb = mea - 2 * std;
-			ub = mea + 2 * std;
-		};
-		//!@}
-
-		//! \name Connection to other classes
-		//! Description of the random quantity via attribute \c rv is optional.
-		//! For operations such as sampling \c rv does not need to be set. However, for \c marginalization
-		//! and \c conditioning \c rv has to be set. NB:
-		//! @{
-
-		//!Name its rv
-		void set_rv (const RV &rv0) {
-			rv = rv0;
-		}
-
-		//! True if rv is assigned
-		bool isnamed() const {
-			bool b = (dim == rv._dsize());
-			return b;
-		}
-
-		//! Return name (fails when isnamed is false)
-		const RV& _rv() const {
-			bdm_assert_debug (isnamed(), "");
-			return rv;
-		}
-		//!@}
-
-		//! \name Access to attributes
-		//! @{
-
-		//! Size of the random variable
-		int dimension() const {
-			return dim;
-		}
-		//! Load from structure with elements:
-		//!  \code
-		//! { rv = {class="RV", names=(...),}; // RV describing meaning of random variable
-		//!   // elements of offsprings
-		//! }
-		//! \endcode
-		//!@}
-		void from_setting (const Setting &set) {
-			shared_ptr<RV> r = UI::build<RV> ( set, "rv", UI::optional );
-			if (r) {
-				set_rv (*r);
-			}
-		}
-
-};
-SHAREDPTR(epdf);
-
-//! Conditional probability density, e.g. modeling \f$ f( x | y) \f$, where \f$ x \f$ is random variable, \c rv, and \f$ y \f$ is conditioning variable, \c rvc.
-class mpdf : public root
-{
-	protected:
-		//!dimension of the condition
-		int dimc;
-		//! random variable in condition
-		RV rvc;
-	private:
-		//! internal epdf, used only as cache to avoid virtual calls of \c _rv() and \c _dimension()
-		epdf* ep;
-
-	protected:
-		//! set internal pointer \c ep to point to given \c iepdf
-		void set_ep (epdf &iepdf) {
-			ep = &iepdf;
-		}
-		//! set internal pointer \c ep to point to given \c iepdf
-		void set_ep (epdf *iepdfp) {
-			ep = iepdfp;
-		}
-
-	public:
-		//! \name Constructors
-		//! @{
-
-		mpdf() : dimc (0), rvc(), ep (NULL) { }
-
-		mpdf (const mpdf &m) : dimc (m.dimc), rvc (m.rvc), ep (m.ep) { }
-		//!@}
-
-		//! \name Matematical operations
-		//!@{
-
-		//! Returns a sample from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv
-		virtual vec samplecond (const vec &cond) {
-			bdm_error ("Not implemented");
-			return vec();
-		}
-
-		//! Returns \param N samples from the density conditioned on \c cond, \f$x \sim epdf(rv|cond)\f$. \param cond is numeric value of \c rv
-		virtual mat samplecond_m (const vec &cond, int N);
-
-		//! Shortcut for conditioning and evaluation of the internal epdf. In some cases,  this operation can be implemented efficiently.
-		virtual double evallogcond (const vec &dt, const vec &cond) {
-			bdm_error ("Not implemented");
-			return 0.0;
-		}
-
-		//! Matrix version of evallogcond
-		virtual vec evallogcond_m (const mat &Dt, const vec &cond) {
-			vec v(Dt.cols());
-			for(int i=0;i<Dt.cols();i++){v(i)= evallogcond(Dt.get_col(i),cond);}
-			return v;
-		}
-
-		//! Array<vec> version of evallogcond
-		virtual vec evallogcond_m (const Array<vec> &Dt, const vec &cond) {
-			bdm_error ("Not implemented");
-			return vec();
-		}
-
-		//! \name Access to attributes
-		//! @{
-
-		const RV& _rv() const {
-			return ep->_rv();
-		}
-		const RV& _rvc() {
-			return rvc;
-		}
-
-		int dimension() const {
-			return ep->dimension();
-		}
-		int dimensionc() {
-			return dimc;
-		}
-
-		//! Load from structure with elements:
-		//!  \code
-		//! { class = "mpdf_offspring",
-		//!   rv = {class="RV", names=(...),}; // RV describing meaning of random variable
-		//!   rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition
-		//!   // elements of offsprings
-		//! }
-		//! \endcode
-		//!@}
-		void from_setting (const Setting &set);
-		//!@}
-
-		//! \name Connection to other objects
-		//!@{
-		void set_rvc (const RV &rvc0) {
-			rvc = rvc0;
-		}
-		void set_rv (const RV &rv0) {
-			ep->set_rv (rv0);
-		}
-		bool isnamed() {
-			return (ep->isnamed()) && (dimc == rvc._dsize());
-		}
-		//!@}
-};
-SHAREDPTR(mpdf);
+		return v;
+	}
+
+	//! Array<vec> version of evallogcond
+	virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond ) {
+		bdm_error ( "Not implemented" );
+		return vec();
+	}
+
+	//! \name Access to attributes
+	//! @{
+
+	const RV& _rv() const {
+		return ep->_rv();
+	}
+	const RV& _rvc() {
+		return rvc;
+	}
+
+	int dimension() const {
+		return ep->dimension();
+	}
+	int dimensionc() {
+		return dimc;
+	}
+
+	//! Load from structure with elements:
+	//!  \code
+	//! { class = "mpdf_offspring",
+	//!   rv = {class="RV", names=(...),}; // RV describing meaning of random variable
+	//!   rvc= {class="RV", names=(...),}; // RV describing meaning of random variable in condition
+	//!   // elements of offsprings
+	//! }
+	//! \endcode
+	//!@}
+	void from_setting ( const Setting &set );
+	//!@}
+
+	//! \name Connection to other objects
+	//!@{
+	void set_rvc ( const RV &rvc0 ) {
+		rvc = rvc0;
+	}
+	void set_rv ( const RV &rv0 ) {
+		ep->set_rv ( rv0 );
+	}
+	bool isnamed() {
+		return ( ep->isnamed() ) && ( dimc == rvc._dsize() );
+	}
+	//!@}
+};
+SHAREDPTR ( mpdf );
 
 //! Mpdf with internal epdf that is modified by function \c condition
 template <class EPDF>
-class mpdf_internal: public mpdf
-{
-	protected :
-		//! Internal epdf used for sampling
-		EPDF iepdf;
-	public:
-		//! constructor
-		mpdf_internal() : mpdf(), iepdf() {set_ep (iepdf);}
-
-		//! Update \c iepdf so that it represents this mpdf conditioned on \c rvc = cond
-		//! This function provides convenient reimplementation in offsprings
-		virtual void condition (const vec &cond) {
-			bdm_error ("Not implemented");
-		}
-
-		//!access function to iepdf
-		EPDF& e() {return iepdf;}
-
-		//! Reimplements samplecond using \c condition()
-		vec samplecond (const vec &cond);
-		//! Reimplements evallogcond using \c condition()
-		double evallogcond (const vec &val, const vec &cond);
-		//! Efficient version of evallogcond for matrices
-		virtual vec evallogcond_m (const mat &Dt, const vec &cond);
-		//! Efficient version of evallogcond for Array<vec>
-		virtual vec evallogcond_m (const Array<vec> &Dt, const vec &cond);
-		//! Efficient version of samplecond
-		virtual mat samplecond_m (const vec &cond, int N);
+class mpdf_internal: public mpdf {
+protected :
+	//! Internal epdf used for sampling
+	EPDF iepdf;
+public:
+	//! constructor
+	mpdf_internal() : mpdf(), iepdf() {
+		set_ep ( iepdf );
+	}
+
+	//! Update \c iepdf so that it represents this mpdf conditioned on \c rvc = cond
+	//! This function provides convenient reimplementation in offsprings
+	virtual void condition ( const vec &cond ) {
+		bdm_error ( "Not implemented" );
+	}
+
+	//!access function to iepdf
+	EPDF& e() {
+		return iepdf;
+	}
+
+	//! Reimplements samplecond using \c condition()
+	vec samplecond ( const vec &cond );
+	//! Reimplements evallogcond using \c condition()
+	double evallogcond ( const vec &val, const vec &cond );
+	//! Efficient version of evallogcond for matrices
+	virtual vec evallogcond_m ( const mat &Dt, const vec &cond );
+	//! Efficient version of evallogcond for Array<vec>
+	virtual vec evallogcond_m ( const Array<vec> &Dt, const vec &cond );
+	//! Efficient version of samplecond
+	virtual mat samplecond_m ( const vec &cond, int N );
 };
 
@@ -585,67 +595,69 @@
 
 */
-class datalink
-{
-	protected:
-		//! Remember how long val should be
-		int downsize;
-
-		//! Remember how long val of "Up" should be
-		int upsize;
-
-		//! val-to-val link, indices of the upper val
-		ivec v2v_up;
-		
-	public:
-		//! Constructor
-		datalink() : downsize (0), upsize (0) { }
-
-		//! Convenience constructor
-		datalink (const RV &rv, const RV &rv_up) {
-			set_connection (rv, rv_up);
-		}
-
-		//! set connection, rv must be fully present in rv_up
-		void set_connection (const RV &rv, const RV &rv_up);
-
-		//! set connection using indices
-		void set_connection (int ds, int us, const ivec &upind);
-
-		//! Get val for myself from val of "Up"
-		vec pushdown (const vec &val_up) {
-		  vec tmp(downsize);
-		  filldown(val_up, tmp);
-			return tmp;
-		}
-		//! Get val for vector val_down from val of "Up"
-		void filldown (const vec &val_up, vec &val_down) {
-			bdm_assert_debug (upsize == val_up.length(), "Wrong val_up");
-			val_down=val_up(v2v_up);
-		}
-
-		//! Fill val of "Up" by my pieces
-		void pushup (vec &val_up, const vec &val) {
-			bdm_assert_debug (downsize == val.length(), "Wrong val");
-			bdm_assert_debug (upsize == val_up.length(), "Wrong val_up");
-			set_subvector (val_up, v2v_up, val);
-		}
-		//! access functions
-		int _upsize(){return upsize;}
-		//! access functions
-		int _downsize(){return downsize;}
+class datalink {
+protected:
+	//! Remember how long val should be
+	int downsize;
+
+	//! Remember how long val of "Up" should be
+	int upsize;
+
+	//! val-to-val link, indices of the upper val
+	ivec v2v_up;
+
+public:
+	//! Constructor
+	datalink() : downsize ( 0 ), upsize ( 0 ) { }
+
+	//! Convenience constructor
+	datalink ( const RV &rv, const RV &rv_up ) {
+		set_connection ( rv, rv_up );
+	}
+
+	//! set connection, rv must be fully present in rv_up
+	void set_connection ( const RV &rv, const RV &rv_up );
+
+	//! set connection using indices
+	void set_connection ( int ds, int us, const ivec &upind );
+
+	//! Get val for myself from val of "Up"
+	vec pushdown ( const vec &val_up ) {
+		vec tmp ( downsize );
+		filldown ( val_up, tmp );
+		return tmp;
+	}
+	//! Get val for vector val_down from val of "Up"
+	void filldown ( const vec &val_up, vec &val_down ) {
+		bdm_assert_debug ( upsize == val_up.length(), "Wrong val_up" );
+		val_down = val_up ( v2v_up );
+	}
+	//! Fill val of "Up" by my pieces
+	void pushup ( vec &val_up, const vec &val ) {
+		bdm_assert_debug ( downsize == val.length(), "Wrong val" );
+		bdm_assert_debug ( upsize == val_up.length(), "Wrong val_up" );
+		set_subvector ( val_up, v2v_up, val );
+	}
+	//! access functions
+	int _upsize() {
+		return upsize;
+	}
+	//! access functions
+	int _downsize() {
+		return downsize;
+	}
 };
 
 /*! Extension of datalink to fill only part of Down
 */
-class datalink_part : public datalink{
-  protected:
+class datalink_part : public datalink {
+protected:
 	//! indeces of values in vector downsize
 	ivec v2v_down;
-  public:
-	void set_connection(const RV &rv, const RV &rv_up);
-		//! Get val for vector val_down from val of "Up"
-		void filldown (const vec &val_up, vec &val_down) {
-			set_subvector(val_down, v2v_down, val_up(v2v_up));
-		}
+public:
+	void set_connection ( const RV &rv, const RV &rv_up );
+	//! Get val for vector val_down from val of "Up"
+	void filldown ( const vec &val_up, vec &val_down ) {
+		set_subvector ( val_down, v2v_down, val_up ( v2v_up ) );
+	}
 };
 
@@ -654,132 +666,135 @@
 Up is current data, Down is their subset with possibly delayed values
 */
-class datalink_buffered: public datalink_part{
-  protected:
+class datalink_buffered: public datalink_part {
+protected:
 	//! History, ordered as \f$[Up_{t-1},Up_{t-2}, \ldots]\f$
 	vec history;
 	//! rv of the history
 	RV Hrv;
-	//! h2v : indeces in down 
+	//! h2v : indeces in down
 	ivec h2v_down;
 	//! h2v : indeces in history
 	ivec h2v_hist;
-  public:
-	
-    datalink_buffered():datalink_part(),history(0), h2v_down(0), h2v_hist(0){};
+public:
+
+	datalink_buffered() : datalink_part(), history ( 0 ), h2v_down ( 0 ), h2v_hist ( 0 ) {};
 	//! 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 ); // write U after Drv
+	void step ( const vec &val_up ) {
+		if ( Hrv._dsize() > 0 ) {
+			history.shift_right ( 0, Hrv._dsize() );
+			history.set_subvector ( 0, val_up ); // write U after Drv
 		}
 	}
-		//! Get val for myself from val of "Up"
-		vec pushdown (const vec &val_up) {
-		  vec tmp(downsize);
-		  filldown(val_up, tmp);
-			return tmp;
-		}
-	
-	void filldown(const vec &val_up, vec &val_down){
-	  bdm_assert_debug(val_down.length()>=downsize, "short val_down");
-	
-	  set_subvector(val_down, v2v_down, val_up(v2v_up)); // copy direct values
-	  set_subvector(val_down, h2v_down, history(h2v_hist)); // copy delayed values
-	}
-	
-	void set_connection(const RV &rv, const RV &rv_up){
-	  // create link between up and down
-	  datalink_part::set_connection(rv, rv_up);
-	  
-	  // create rvs of history 
-	  // we can store only what we get in rv_up - everything else is removed
-	  ivec valid_ids=rv.findself_ids(rv_up);
-	  RV rv_hist = rv.subselect( find(valid_ids>=0) ); // select only rvs that are in rv_up
-	  rv_hist = rv_hist.expand_delayes(); // full regressor - including time 0
-	  Hrv=rv_hist.subt(rv.remove_time());   // remove time 0
-	  history = zeros(Hrv._dsize());
-	  
-	  Hrv.dataind(rv,h2v_hist,h2v_down);
-	  
-	  downsize = v2v_down.length()+h2v_down.length();
-	  upsize = v2v_up.length();
+	//! Get val for myself from val of "Up"
+	vec pushdown ( const vec &val_up ) {
+		vec tmp ( downsize );
+		filldown ( val_up, tmp );
+		return tmp;
+	}
+
+	void filldown ( const vec &val_up, vec &val_down ) {
+		bdm_assert_debug ( val_down.length() >= downsize, "short val_down" );
+
+		set_subvector ( val_down, v2v_down, val_up ( v2v_up ) ); // copy direct values
+		set_subvector ( val_down, h2v_down, history ( h2v_hist ) ); // copy delayed values
+	}
+
+	void set_connection ( const RV &rv, const RV &rv_up ) {
+		// create link between up and down
+		datalink_part::set_connection ( rv, rv_up );
+
+		// create rvs of history
+		// we can store only what we get in rv_up - everything else is removed
+		ivec valid_ids = rv.findself_ids ( rv_up );
+		RV rv_hist = rv.subselect ( find ( valid_ids >= 0 ) ); // select only rvs that are in rv_up
+		rv_hist = rv_hist.expand_delayes(); // full regressor - including time 0
+		Hrv = rv_hist.subt ( rv.remove_time() );   // remove time 0
+		history = zeros ( Hrv._dsize() );
+
+		Hrv.dataind ( rv, h2v_hist, h2v_down );
+
+		downsize = v2v_down.length() + h2v_down.length();
+		upsize = v2v_up.length();
 	}
 };
 
 //! buffered datalink from 2 vectors to 1
-class datalink_2to1_buffered{
-  protected:
+class datalink_2to1_buffered {
+protected:
 	datalink_buffered dl1;
 	datalink_buffered dl2;
-  public:
+public:
 	//! set connection between RVs
-	void set_connection(const RV &rv, const RV &rv_up1, const RV &rv_up2){
-	  dl1.set_connection(rv,rv_up1);
-	  dl2.set_connection(rv,rv_up2);
-	}
-	void filldown(const vec &val1, const vec &val2, vec &val_down){
-	  bdm_assert_debug(val_down.length()>=dl1._downsize()+dl2._downsize(), "short val_down");
-	  dl1.filldown(val1, val_down);
-	  dl2.filldown(val2, val_down);
-	}
-	void step(const vec &dt, const vec &ut) {dl1.step(dt); dl2.step(ut);}
-};
+	void set_connection ( const RV &rv, const RV &rv_up1, const RV &rv_up2 ) {
+		dl1.set_connection ( rv, rv_up1 );
+		dl2.set_connection ( rv, rv_up2 );
+	}
+	void filldown ( const vec &val1, const vec &val2, vec &val_down ) {
+		bdm_assert_debug ( val_down.length() >= dl1._downsize() + dl2._downsize(), "short val_down" );
+		dl1.filldown ( val1, val_down );
+		dl2.filldown ( val2, val_down );
+	}
+	void step ( const vec &dt, const vec &ut ) {
+		dl1.step ( dt );
+		dl2.step ( ut );
+	}
+};
+
+
 
 //! Data link with a condition.
-class datalink_m2e: public datalink
-{
-	protected:
-		//! Remember how long cond should be
-		int condsize;
-
-		//!upper_val-to-local_cond link, indices of the upper val
-		ivec v2c_up;
-
-		//!upper_val-to-local_cond link, indices of the local cond
-		ivec v2c_lo;
-
-	public:
-		//! Constructor
-		datalink_m2e() : condsize (0) { }
-
-		//! Set connection between vectors
-		void set_connection (const RV &rv, const RV &rvc, const RV &rv_up);
-
-		//!Construct condition
-		vec get_cond (const vec &val_up);
-
-		//! Copy corresponding values to Up.condition
-		void pushup_cond (vec &val_up, const vec &val, const vec &cond);
+class datalink_m2e: public datalink {
+protected:
+	//! Remember how long cond should be
+	int condsize;
+
+	//!upper_val-to-local_cond link, indices of the upper val
+	ivec v2c_up;
+
+	//!upper_val-to-local_cond link, indices of the local cond
+	ivec v2c_lo;
+
+public:
+	//! Constructor
+	datalink_m2e() : condsize ( 0 ) { }
+
+	//! Set connection between vectors
+	void set_connection ( const RV &rv, const RV &rvc, const RV &rv_up );
+
+	//!Construct condition
+	vec get_cond ( const vec &val_up );
+
+	//! Copy corresponding values to Up.condition
+	void pushup_cond ( vec &val_up, const vec &val, const vec &cond );
 };
 
 //!DataLink is a connection between mpdf and its superordinate (Up)
 //! This class links
-class datalink_m2m: public datalink_m2e
-{
-	protected:
-		//!cond-to-cond link, indices of the upper cond
-		ivec c2c_up;
-		//!cond-to-cond link, indices of the local cond
-		ivec c2c_lo;
-
-	public:
-		//! Constructor
-		datalink_m2m() {};
-		//! Set connection between the vectors
-		void set_connection (const RV &rv, const RV &rvc, const RV &rv_up, const RV &rvc_up) {
-			datalink_m2e::set_connection (rv, rvc, rv_up);
-			//establish c2c connection
-			rvc.dataind (rvc_up, c2c_lo, c2c_up);
-			bdm_assert_debug (c2c_lo.length() + v2c_lo.length() == condsize, "cond is not fully given");
-		}
-
-		//! Get cond for myself from val and cond of "Up"
-		vec get_cond (const vec &val_up, const vec &cond_up) {
-			vec tmp (condsize);
-			set_subvector (tmp, v2c_lo, val_up (v2c_up));
-			set_subvector (tmp, c2c_lo, cond_up (c2c_up));
-			return tmp;
-		}
-		//! Fill
+class datalink_m2m: public datalink_m2e {
+protected:
+	//!cond-to-cond link, indices of the upper cond
+	ivec c2c_up;
+	//!cond-to-cond link, indices of the local cond
+	ivec c2c_lo;
+
+public:
+	//! Constructor
+	datalink_m2m() {};
+	//! Set connection between the vectors
+	void set_connection ( const RV &rv, const RV &rvc, const RV &rv_up, const RV &rvc_up ) {
+		datalink_m2e::set_connection ( rv, rvc, rv_up );
+		//establish c2c connection
+		rvc.dataind ( rvc_up, c2c_lo, c2c_up );
+		bdm_assert_debug ( c2c_lo.length() + v2c_lo.length() == condsize, "cond is not fully given" );
+	}
+
+	//! Get cond for myself from val and cond of "Up"
+	vec get_cond ( const vec &val_up, const vec &cond_up ) {
+		vec tmp ( condsize );
+		set_subvector ( tmp, v2c_lo, val_up ( v2c_up ) );
+		set_subvector ( tmp, c2c_lo, cond_up ( c2c_up ) );
+		return tmp;
+	}
+	//! Fill
 
 };
@@ -790,43 +805,48 @@
 This class abstracts logging of results from implementation. This class replaces direct logging of results (e.g. to files or to global variables) by calling methods of a logger. Specializations of this abstract class for specific storage method are designed.
  */
-class logger : public root
-{
-	protected:
-		//! RVs of all logged variables.
-		Array<RV> entries;
-		//! Names of logged quantities, e.g. names of algorithm variants
-		Array<string> names;
-	public:
-		//!Default constructor
-		logger() : entries (0), names (0) {}
-
-		//! returns an identifier which will be later needed for calling the \c logit() function
-		//! For empty RV it returns -1, this entry will be ignored by \c logit().
-		virtual int add (const RV &rv, string prefix = "") {
-			int id;
-			if (rv._dsize() > 0) {
-				id = entries.length();
-				names = concat (names, prefix);   // diff
-				entries.set_length (id + 1, true);
-				entries (id) = rv;
-			} else {
-				id = -1;
-			}
-			return id; // identifier of the last entry
+class logger : public root {
+protected:
+	//! RVs of all logged variables.
+	Array<RV> entries;
+	//! Names of logged quantities, e.g. names of algorithm variants
+	Array<string> names;
+public:
+	//!Default constructor
+	logger() : entries ( 0 ), names ( 0 ) {}
+
+	//! returns an identifier which will be later needed for calling the \c logit() function
+	//! For empty RV it returns -1, this entry will be ignored by \c logit().
+	virtual int add ( const RV &rv, string prefix = "" ) {
+		int id;
+		if ( rv._dsize() > 0 ) {
+			id = entries.length();
+			names = concat ( names, prefix ); // diff
+			entries.set_length ( id + 1, true );
+			entries ( id ) = rv;
+		} else {
+			id = -1;
 		}
-
-		//! log this vector
-		virtual void logit (int id, const vec &v) {bdm_error("Not implemented");};
-		//! log this double
-		virtual void logit (int id, const double &d) {bdm_error("Not implemented");};
-
-		//! Shifts storage position for another time step.
-		virtual void step() {bdm_error("Not implemneted");};
-
-		//! Finalize storing information
-		virtual void finalize() {};
-
-		//! Initialize the storage
-		virtual void init() {};
+		return id; // identifier of the last entry
+	}
+
+	//! log this vector
+	virtual void logit ( int id, const vec &v ) {
+		bdm_error ( "Not implemented" );
+	};
+	//! log this double
+	virtual void logit ( int id, const double &d ) {
+		bdm_error ( "Not implemented" );
+	};
+
+	//! Shifts storage position for another time step.
+	virtual void step() {
+		bdm_error ( "Not implemneted" );
+	};
+
+	//! Finalize storing information
+	virtual void finalize() {};
+
+	//! Initialize the storage
+	virtual void init() {};
 
 };
@@ -835,33 +855,36 @@
 
 */
-class mepdf : public mpdf
-{
-		//! Internal shared pointer to epdf
-		shared_ptr<epdf> iepdf;
-	public:
-		//!Default constructor
-		mepdf() { }
-		//! Set internal shared pointer
-		mepdf (shared_ptr<epdf> em) {
-			iepdf = em;
-			set_ep (*iepdf.get());
-			dimc = 0;
-		}
-
-		//! empty
-		vec samplecond(const vec &cond){return iepdf->sample();}
-		double evallogcond(const vec &val, const vec &cond){return iepdf->evallog(val);}
-
-		//! Load from structure with elements:
-		//!  \code
-		//! { class = "mepdf",
-		//!   epdf = {class="epdf_offspring",...}
-		//! }
-		//! \endcode
-		//!@}
-		void from_setting (const Setting &set);
-};
-UIREGISTER (mepdf);
-SHAREDPTR (mepdf);
+class mepdf : public mpdf {
+	//! Internal shared pointer to epdf
+	shared_ptr<epdf> iepdf;
+public:
+	//!Default constructor
+	mepdf() { }
+	//! Set internal shared pointer
+	mepdf ( shared_ptr<epdf> em ) {
+		iepdf = em;
+		set_ep ( *iepdf.get() );
+		dimc = 0;
+	}
+
+	//! empty
+	vec samplecond ( const vec &cond ) {
+		return iepdf->sample();
+	}
+	double evallogcond ( const vec &val, const vec &cond ) {
+		return iepdf->evallog ( val );
+	}
+
+	//! Load from structure with elements:
+	//!  \code
+	//! { class = "mepdf",
+	//!   epdf = {class="epdf_offspring",...}
+	//! }
+	//! \endcode
+	//!@}
+	void from_setting ( const Setting &set );
+};
+UIREGISTER ( mepdf );
+SHAREDPTR ( mepdf );
 
 //! \brief Combines RVs from a list of mpdfs to a single one.
@@ -875,73 +898,72 @@
 */
 
-class DS : public root
-{
-	protected:
-		int dtsize;
-		int utsize;
-		//!Description of data returned by \c getdata().
-		RV Drv;
-		//!Description of data witten by by \c write().
-		RV Urv; //
-		//! Remember its own index in Logger L
-		int L_dt, L_ut;
-	public:
-		//! default constructors
-		DS() : Drv(), Urv() {};
-
-		//! Returns full vector of observed data=[output, input]
-		virtual void getdata (vec &dt) {
-			bdm_error ("abstract class");
-		}
-
-		//! Returns data records at indeces.
-		virtual void getdata (vec &dt, const ivec &indeces) {
-			bdm_error ("abstract class");
-		}
-
-		//! Accepts action variable and schedule it for application.
-		virtual void write (vec &ut) {
-			bdm_error ("abstract class");
-		}
-
-		//! Accepts action variables at specific indeces
-		virtual void write (vec &ut, const ivec &indeces) {
-			bdm_error ("abstract class");
-		}
-
-		//! Moves from \f$ t \f$ to \f$ t+1 \f$, i.e. perfroms the actions and reads response of the system.
-		virtual void step() = 0;
-
-		//! Register DS for logging into logger L
-		virtual void log_add (logger &L) {
-			bdm_assert_debug (dtsize == Drv._dsize(), "invalid DS: dtsize ("+ num2str(dtsize)+ ") different from Drv "+ num2str(Drv._dsize()));
-			bdm_assert_debug (utsize == Urv._dsize(), "invalid DS: utsize ("+ num2str(utsize)+ ") different from Urv "+ num2str(Urv._dsize()));
-
-			L_dt = L.add (Drv, "");
-			L_ut = L.add (Urv, "");
-		}
-		//! Register DS for logging into logger L
-		virtual void logit (logger &L) {
-			vec tmp (Drv._dsize() + Urv._dsize());
-			getdata (tmp);
-			// d is first in getdata
-			L.logit (L_dt, tmp.left (Drv._dsize()));
-			// u follows after d in getdata
-			L.logit (L_ut, tmp.mid (Drv._dsize(), Urv._dsize()));
-		}
-		//!access function
-		virtual const RV& _drv() const {
-	//		return concat (Drv, Urv);// why!!!
-			return Drv;// why!!!
-		}
-		//!access function
-		const RV& _urv() const {
-			return Urv;
-		}
-		//! set random variables
-		virtual void set_drv (const  RV &drv, const RV &urv) {
-			Drv = drv;
-			Urv = urv;
-		}
+class DS : public root {
+protected:
+	int dtsize;
+	int utsize;
+	//!Description of data returned by \c getdata().
+	RV Drv;
+	//!Description of data witten by by \c write().
+	RV Urv; //
+	//! Remember its own index in Logger L
+	int L_dt, L_ut;
+public:
+	//! default constructors
+	DS() : Drv(), Urv() {};
+
+	//! Returns full vector of observed data=[output, input]
+	virtual void getdata ( vec &dt ) {
+		bdm_error ( "abstract class" );
+	}
+
+	//! Returns data records at indeces.
+	virtual void getdata ( vec &dt, const ivec &indeces ) {
+		bdm_error ( "abstract class" );
+	}
+
+	//! Accepts action variable and schedule it for application.
+	virtual void write ( vec &ut ) {
+		bdm_error ( "abstract class" );
+	}
+
+	//! Accepts action variables at specific indeces
+	virtual void write ( vec &ut, const ivec &indeces ) {
+		bdm_error ( "abstract class" );
+	}
+
+	//! Moves from \f$ t \f$ to \f$ t+1 \f$, i.e. perfroms the actions and reads response of the system.
+	virtual void step() = 0;
+
+	//! Register DS for logging into logger L
+	virtual void log_add ( logger &L ) {
+		bdm_assert_debug ( dtsize == Drv._dsize(), "invalid DS: dtsize (" + num2str ( dtsize ) + ") different from Drv " + num2str ( Drv._dsize() ) );
+		bdm_assert_debug ( utsize == Urv._dsize(), "invalid DS: utsize (" + num2str ( utsize ) + ") different from Urv " + num2str ( Urv._dsize() ) );
+
+		L_dt = L.add ( Drv, "" );
+		L_ut = L.add ( Urv, "" );
+	}
+	//! Register DS for logging into logger L
+	virtual void logit ( logger &L ) {
+		vec tmp ( Drv._dsize() + Urv._dsize() );
+		getdata ( tmp );
+		// d is first in getdata
+		L.logit ( L_dt, tmp.left ( Drv._dsize() ) );
+		// u follows after d in getdata
+		L.logit ( L_ut, tmp.mid ( Drv._dsize(), Urv._dsize() ) );
+	}
+	//!access function
+	virtual const RV& _drv() const {
+		//		return concat (Drv, Urv);// why!!!
+		return Drv;// why!!!
+	}
+	//!access function
+	const RV& _urv() const {
+		return Urv;
+	}
+	//! set random variables
+	virtual void set_drv ( const  RV &drv, const RV &urv ) {
+		Drv = drv;
+		Urv = urv;
+	}
 };
 
@@ -967,164 +989,163 @@
 */
 
-class BM : public root
-{
-	protected:
-		//! Random variable of the data (optional)
-		RV drv;
-		//!Logarithm of marginalized data likelihood.
-		double ll;
-		//!  If true, the filter will compute likelihood of the data record and store it in \c ll . Set to false if you want to save computational time.
-		bool evalll;
-	public:
-		//! \name Constructors
-		//! @{
-
-		BM() : ll (0), evalll (true), LIDs (4), LFlags (4) {
-			LIDs = -1;/*empty IDs*/
-			LFlags = 0;
-			LFlags (0) = 1;  /*log only mean*/
+class BM : public root {
+protected:
+	//! Random variable of the data (optional)
+	RV drv;
+	//!Logarithm of marginalized data likelihood.
+	double ll;
+	//!  If true, the filter will compute likelihood of the data record and store it in \c ll . Set to false if you want to save computational time.
+	bool evalll;
+public:
+	//! \name Constructors
+	//! @{
+
+	BM() : ll ( 0 ), evalll ( true ), LIDs ( 4 ), LFlags ( 4 ) {
+		LIDs = -1;/*empty IDs*/
+		LFlags = 0;
+		LFlags ( 0 ) = 1;  /*log only mean*/
+	};
+	BM ( const BM &B ) :  drv ( B.drv ), ll ( B.ll ), evalll ( B.evalll ) {}
+	//! Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually!
+	//! Prototype: \code BM* _copy_() const {return new BM(*this);} \endcode
+	virtual BM* _copy_() const {
+		return NULL;
+	};
+	//!@}
+
+	//! \name Mathematical operations
+	//!@{
+
+	/*! \brief Incremental Bayes rule
+	@param dt vector of input data
+	*/
+	virtual void bayes ( const vec &dt ) = 0;
+	//! Batch Bayes rule (columns of Dt are observations)
+	virtual void bayesB ( const mat &Dt );
+	//! Evaluates predictive log-likelihood of the given data record
+	//! I.e. marginal likelihood of the data with the posterior integrated out.
+	virtual double logpred ( const vec &dt ) const {
+		bdm_error ( "Not implemented" );
+		return 0.0;
+	}
+
+	//! Matrix version of logpred
+	vec logpred_m ( const mat &dt ) const {
+		vec tmp ( dt.cols() );
+		for ( int i = 0; i < dt.cols(); i++ ) {
+			tmp ( i ) = logpred ( dt.get_col ( i ) );
+		}
+		return tmp;
+	}
+
+	//!Constructs a predictive density \f$ f(d_{t+1} |d_{t}, \ldots d_{0}) \f$
+	virtual epdf* epredictor() const {
+		bdm_error ( "Not implemented" );
+		return NULL;
+	};
+	//!Constructs conditional density of 1-step ahead predictor \f$ f(d_{t+1} |d_{t+h-1}, \ldots d_{t}) \f$
+	virtual mpdf* predictor() const {
+		bdm_error ( "Not implemented" );
+		return NULL;
+	};
+	//!@}
+
+	//! \name Extension to conditional BM
+	//! This extension is useful e.g. in Marginalized Particle Filter (\ref bdm::MPF).
+	//! Alternatively, it can be used for automated connection to DS when the condition is observed
+	//!@{
+
+	//! Name of extension variable
+	RV rvc;
+	//! access function
+	const RV& _rvc() const {
+		return rvc;
+	}
+
+	//! Substitute \c val for \c rvc.
+	virtual void condition ( const vec &val ) {
+		bdm_error ( "Not implemented!" );
+	}
+
+	//!@}
+
+
+	//! \name Access to attributes
+	//!@{
+
+	const RV& _drv() const {
+		return drv;
+	}
+	void set_drv ( const RV &rv ) {
+		drv = rv;
+	}
+	void set_rv ( const RV &rv ) {
+		const_cast<epdf&> ( posterior() ).set_rv ( rv );
+	}
+	double _ll() const {
+		return ll;
+	}
+	void set_evalll ( bool evl0 ) {
+		evalll = evl0;
+	}
+	virtual const epdf& posterior() const = 0;
+	//!@}
+
+	//! \name Logging of results
+	//!@{
+
+	//! Set boolean options from a string, recognized are: "logbounds,logll"
+	virtual void set_options ( const string &opt ) {
+		LFlags ( 0 ) = 1;
+		if ( opt.find ( "logbounds" ) != string::npos ) {
+			LFlags ( 1 ) = 1;
+			LFlags ( 2 ) = 1;
+		}
+		if ( opt.find ( "logll" ) != string::npos ) {
+			LFlags ( 3 ) = 1;
+		}
+	}
+	//! IDs of storages in loggers 4:[1=mean,2=lb,3=ub,4=ll]
+	ivec LIDs;
+
+	//! Flags for logging - same size as LIDs, each entry correspond to the same in LIDs
+	ivec LFlags;
+	//! Add all logged variables to a logger
+	virtual void log_add ( logger &L, const string &name = "" ) {
+		// internal
+		RV r;
+		if ( posterior().isnamed() ) {
+			r = posterior()._rv();
+		} else {
+			r = RV ( "est", posterior().dimension() );
 		};
-		BM (const BM &B) :  drv (B.drv), ll (B.ll), evalll (B.evalll) {}
-		//! Copy function required in vectors, Arrays of BM etc. Have to be DELETED manually!
-		//! Prototype: \code BM* _copy_() const {return new BM(*this);} \endcode
-		virtual BM* _copy_() const {
-			return NULL;
-		};
-		//!@}
-
-		//! \name Mathematical operations
-		//!@{
-
-		/*! \brief Incremental Bayes rule
-		@param dt vector of input data
-		*/
-		virtual void bayes (const vec &dt) = 0;
-		//! Batch Bayes rule (columns of Dt are observations)
-		virtual void bayesB (const mat &Dt);
-		//! Evaluates predictive log-likelihood of the given data record
-		//! I.e. marginal likelihood of the data with the posterior integrated out.
-		virtual double logpred (const vec &dt) const {
-			bdm_error ("Not implemented");
-			return 0.0;
+
+		// Add mean value
+		if ( LFlags ( 0 ) ) LIDs ( 0 ) = L.add ( r, name + "mean_" );
+		if ( LFlags ( 1 ) ) LIDs ( 1 ) = L.add ( r, name + "lb_" );
+		if ( LFlags ( 2 ) ) LIDs ( 2 ) = L.add ( r, name + "ub_" );
+		if ( LFlags ( 3 ) ) LIDs ( 3 ) = L.add ( RV ( "ll", 1 ), name );    //TODO: "local" RV
+	}
+	virtual void logit ( logger &L ) {
+		L.logit ( LIDs ( 0 ), posterior().mean() );
+		if ( LFlags ( 1 ) || LFlags ( 2 ) ) {  //if one of them is off, its LID==-1 and will not be stored
+			vec ub, lb;
+			posterior().qbounds ( lb, ub );
+			L.logit ( LIDs ( 1 ), lb );
+			L.logit ( LIDs ( 2 ), ub );
 		}
-
-		//! Matrix version of logpred
-		vec logpred_m (const mat &dt) const {
-			vec tmp (dt.cols());
-			for (int i = 0; i < dt.cols(); i++) {
-				tmp (i) = logpred (dt.get_col (i));
-			}
-			return tmp;
+		if ( LFlags ( 3 ) ) L.logit ( LIDs ( 3 ), ll );
+	}
+	//!@}
+	void from_setting ( const Setting &set ) {
+		shared_ptr<RV> r = UI::build<RV> ( set, "drv", UI::optional );
+		if ( r ) {
+			set_drv ( *r );
 		}
-
-		//!Constructs a predictive density \f$ f(d_{t+1} |d_{t}, \ldots d_{0}) \f$
-		virtual epdf* epredictor() const {
-			bdm_error ("Not implemented");
-			return NULL;
-		};
-		//!Constructs conditional density of 1-step ahead predictor \f$ f(d_{t+1} |d_{t+h-1}, \ldots d_{t}) \f$
-		virtual mpdf* predictor() const {
-			bdm_error ("Not implemented");
-			return NULL;
-		};
-		//!@}
-
-		//! \name Extension to conditional BM
-		//! This extension is useful e.g. in Marginalized Particle Filter (\ref bdm::MPF).
-		//! Alternatively, it can be used for automated connection to DS when the condition is observed
-		//!@{
-
-		//! Name of extension variable
-		RV rvc;
-		//! access function
-		const RV& _rvc() const {
-			return rvc;
+		string opt;
+		if ( !UI::get ( opt, set, "options", UI::optional ) ) {
+			set_options ( opt );
 		}
-
-		//! Substitute \c val for \c rvc.
-		virtual void condition (const vec &val) {
-			bdm_error ("Not implemented!");
-		}
-
-		//!@}
-
-
-		//! \name Access to attributes
-		//!@{
-
-		const RV& _drv() const {
-			return drv;
-		}
-		void set_drv (const RV &rv) {
-			drv = rv;
-		}
-		void set_rv (const RV &rv) {
-			const_cast<epdf&> (posterior()).set_rv (rv);
-		}
-		double _ll() const {
-			return ll;
-		}
-		void set_evalll (bool evl0) {
-			evalll = evl0;
-		}
-		virtual const epdf& posterior() const = 0;
-		//!@}
-
-		//! \name Logging of results
-		//!@{
-
-		//! Set boolean options from a string, recognized are: "logbounds,logll"
-		virtual void set_options (const string &opt) {
-			LFlags (0) = 1;
-			if (opt.find ("logbounds") != string::npos) {
-				LFlags (1) = 1;
-				LFlags (2) = 1;
-			}
-			if (opt.find ("logll") != string::npos) {
-				LFlags (3) = 1;
-			}
-		}
-		//! IDs of storages in loggers 4:[1=mean,2=lb,3=ub,4=ll]
-		ivec LIDs;
-
-		//! Flags for logging - same size as LIDs, each entry correspond to the same in LIDs
-		ivec LFlags;
-		//! Add all logged variables to a logger
-		virtual void log_add (logger &L, const string &name = "") {
-			// internal
-			RV r;
-			if (posterior().isnamed()) {
-				r = posterior()._rv();
-			} else {
-				r = RV ("est", posterior().dimension());
-			};
-
-			// Add mean value
-			if (LFlags (0)) LIDs (0) = L.add (r, name + "mean_");
-			if (LFlags (1)) LIDs (1) = L.add (r, name + "lb_");
-			if (LFlags (2)) LIDs (2) = L.add (r, name + "ub_");
-			if (LFlags (3)) LIDs (3) = L.add (RV ("ll", 1), name);              //TODO: "local" RV
-		}
-		virtual void logit (logger &L) {
-			L.logit (LIDs (0), posterior().mean());
-			if (LFlags (1) || LFlags (2)) {        //if one of them is off, its LID==-1 and will not be stored
-				vec ub, lb;
-				posterior().qbounds (lb, ub);
-				L.logit (LIDs (1), lb);
-				L.logit (LIDs (2), ub);
-			}
-			if (LFlags (3)) L.logit (LIDs (3), ll);
-		}
-		//!@}
-		void from_setting (const Setting &set){
-			shared_ptr<RV> r = UI::build<RV> ( set, "drv", UI::optional );
-			if (r) {
-				set_drv (*r);
-			}
-			string opt;
-			if(!UI::get(opt, set, "options", UI::optional)) {
-				set_options(opt);
-			}
-		}
+	}
 
 };
@@ -1135,7 +1156,6 @@
 
 template<class EPDF>
-vec mpdf_internal<EPDF>::samplecond (const vec &cond)
-{
-	condition (cond);
+vec mpdf_internal<EPDF>::samplecond ( const vec &cond ) {
+	condition ( cond );
 	vec temp = iepdf.sample();
 	return temp;
@@ -1143,12 +1163,11 @@
 
 template<class EPDF>
-mat mpdf_internal<EPDF>::samplecond_m (const vec &cond, int N)
-{
-	condition (cond);
-	mat temp (dimension(), N);
-	vec smp (dimension());
-	for (int i = 0; i < N; i++) {
+mat mpdf_internal<EPDF>::samplecond_m ( const vec &cond, int N ) {
+	condition ( cond );
+	mat temp ( dimension(), N );
+	vec smp ( dimension() );
+	for ( int i = 0; i < N; i++ ) {
 		smp = iepdf.sample();
-		temp.set_col (i, smp);
+		temp.set_col ( i, smp );
 	}
 
@@ -1157,24 +1176,21 @@
 
 template<class EPDF>
-double mpdf_internal<EPDF>::evallogcond (const vec &dt, const vec &cond)
-{
+double mpdf_internal<EPDF>::evallogcond ( const vec &dt, const vec &cond ) {
 	double tmp;
-	condition (cond);
-	tmp = iepdf.evallog (dt);
+	condition ( cond );
+	tmp = iepdf.evallog ( dt );
 	return tmp;
 }
 
 template<class EPDF>
-vec mpdf_internal<EPDF>::evallogcond_m (const mat &Dt, const vec &cond)
-{
-	condition (cond);
-	return iepdf.evallog_m (Dt);
+vec mpdf_internal<EPDF>::evallogcond_m ( const mat &Dt, const vec &cond ) {
+	condition ( cond );
+	return iepdf.evallog_m ( Dt );
 }
 
 template<class EPDF>
-vec mpdf_internal<EPDF>::evallogcond_m (const Array<vec> &Dt, const vec &cond)
-{
-	condition (cond);
-	return iepdf.evallog_m (Dt);
+vec mpdf_internal<EPDF>::evallogcond_m ( const Array<vec> &Dt, const vec &cond ) {
+	condition ( cond );
+	return iepdf.evallog_m ( Dt );
 }
 
Index: library/bdm/base/bdmbase.cpp
===================================================================
--- library/bdm/base/bdmbase.cpp (revision 598)
+++ library/bdm/base/bdmbase.cpp (revision 600)
@@ -5,15 +5,16 @@
 namespace bdm {
 
-const int RV_BUFFER_STEP = 1;
-RVmap RV_MAP;
-Array<string> RV_NAMES ( RV_BUFFER_STEP );
-ivec RV_SIZES ( RV_BUFFER_STEP );
-
-RV RV0 = RV();
+const int RV::BUFFER_STEP = 1;
+
+Array<string> RV::NAMES ( RV::BUFFER_STEP );
+
+ivec RV::SIZES ( RV::BUFFER_STEP );
+
+RV::str2int_map RV::MAP;
 
 void RV::clear_all() {
-	RV_MAP.clear();
-	RV_SIZES.clear();
-	RV_NAMES = Array<string> ( RV_BUFFER_STEP );
+	MAP.clear();
+	SIZES.clear();
+	NAMES = Array<string> ( BUFFER_STEP );
 }
 
@@ -21,26 +22,26 @@
 	//Refer
 	int id;
-	RVmap::const_iterator iter = RV_MAP.find ( name );
-	if ( iter == RV_MAP.end() ) {
-		id = RV_MAP.size() + 1;
+	str2int_map::const_iterator iter = MAP.find ( name );
+	if ( iter == MAP.end() ) {
+		id = MAP.size() + 1;
 		//debug
 		/*		{
 					cout << endl;
-					RVmap::const_iterator iter = RV_MAP.begin();
-					for(RVmap::const_iterator iter=RV_MAP.begin(); iter!=RV_MAP.end(); iter++){
+					str2int_map::const_iterator iter = MAP.begin();
+					for(str2int_map::const_iterator iter=MAP.begin(); iter!=MAP.end(); iter++){
 						cout << "key: " << iter->first << " val: " << iter->second <<endl;
 					}
 				}*/
 
-		RV_MAP.insert ( make_pair ( name, id ) ); //add new rv
-		if ( id >= RV_NAMES.length() ) {
-			RV_NAMES.set_length ( id + RV_BUFFER_STEP, true );
-			RV_SIZES.set_length ( id + RV_BUFFER_STEP, true );
-		}
-		RV_NAMES ( id ) = name;
-		RV_SIZES ( id ) = size;
+		MAP.insert ( make_pair ( name, id ) ); //add new rv
+		if ( id >= NAMES.length() ) {
+			NAMES.set_length ( id + BUFFER_STEP, true );
+			SIZES.set_length ( id + BUFFER_STEP, true );
+		}
+		NAMES ( id ) = name;
+		SIZES ( id ) = size;
 	} else {
 		id = iter->second;
-		bdm_assert_debug ( RV_SIZES ( id ) == size, "RV " + name + " of different size already exists" );
+		bdm_assert_debug ( SIZES ( id ) == size, "RV " + name + " of different size already exists" );
 	}
 	return id;
@@ -50,5 +51,5 @@
 	int tmp = 0;
 	for ( int i = 0; i < len; i++ ) {
-		tmp += RV_SIZES ( ids ( i ) );
+		tmp += SIZES ( ids ( i ) );
 	}
 	return tmp;
@@ -59,5 +60,5 @@
 	int tmp = 0;
 	for ( int i = 0; i < len; i++ ) {
-		tmp += RV_SIZES ( ids ( i ) );
+		tmp += SIZES ( ids ( i ) );
 		szs ( i ) = tmp;
 	}
@@ -134,11 +135,11 @@
 }
 
-shared_ptr<mpdf> epdf::condition (const RV &rv) const {
-	bdm_warning ("Not implemented");
+shared_ptr<mpdf> epdf::condition ( const RV &rv ) const {
+	bdm_warning ( "Not implemented" );
 	return shared_ptr<mpdf>();
 }
 
-shared_ptr<epdf> epdf::marginal (const RV &rv) const {
-	bdm_warning ("Not implemented");
+shared_ptr<epdf> epdf::marginal ( const RV &rv ) const {
+	bdm_warning ( "Not implemented" );
 	return shared_ptr<epdf>();
 }
@@ -150,8 +151,8 @@
 }
 
-vec epdf::evallog_m (const mat &Val) const {
-	vec x (Val.cols());
-	for (int i = 0; i < Val.cols(); i++) {
-		x (i) = evallog ( Val.get_col (i) );
+vec epdf::evallog_m ( const mat &Val ) const {
+	vec x ( Val.cols() );
+	for ( int i = 0; i < Val.cols(); i++ ) {
+		x ( i ) = evallog ( Val.get_col ( i ) );
 	}
 
@@ -159,8 +160,8 @@
 }
 
-vec epdf::evallog_m (const Array<vec> &Avec) const {
-	vec x (Avec.size());
-	for (int i = 0; i < Avec.size(); i++) {
-		x (i) = evallog ( Avec (i) );
+vec epdf::evallog_m ( const Array<vec> &Avec ) const {
+	vec x ( Avec.size() );
+	for ( int i = 0; i < Avec.size(); i++ ) {
+		x ( i ) = evallog ( Avec ( i ) );
 	}
 
@@ -168,8 +169,8 @@
 }
 
-mat mpdf::samplecond_m (const vec &cond, int N) {
-	mat M( dimension(), N );
+mat mpdf::samplecond_m ( const vec &cond, int N ) {
+	mat M ( dimension(), N );
 	for ( int i = 0; i < N; i++ ) {
-		M.set_col ( i, samplecond( cond ) );
+		M.set_col ( i, samplecond ( cond ) );
 	}
 
@@ -189,42 +190,42 @@
 }
 
-void datalink::set_connection (const RV &rv, const RV &rv_up) {
+void datalink::set_connection ( const RV &rv, const RV &rv_up ) {
 	downsize = rv._dsize();
-	  upsize = rv_up._dsize();
-	  v2v_up = rv.dataind (rv_up);
-	  bdm_assert_debug (v2v_up.length() == downsize, "rv is not fully in rv_up");
-}
-
-void datalink::set_connection (int ds, int us, const ivec &upind) {
+	upsize = rv_up._dsize();
+	v2v_up = rv.dataind ( rv_up );
+	bdm_assert_debug ( v2v_up.length() == downsize, "rv is not fully in rv_up" );
+}
+
+void datalink::set_connection ( int ds, int us, const ivec &upind ) {
 	downsize = ds;
 	upsize = us;
 	v2v_up = upind;
-    bdm_assert_debug (v2v_up.length() == downsize, "rv is not fully in rv_up");
-}
-
-void datalink_part::set_connection (const RV &rv, const RV &rv_up) {
-	 rv.dataind (rv_up, v2v_down, v2v_up);
-	 downsize = v2v_down.length();
-	 upsize = v2v_up.length();
-}
-
-void datalink_m2e::set_connection (const RV &rv, const RV &rvc, const RV &rv_up) {
-	datalink::set_connection (rv, rv_up);
+	bdm_assert_debug ( v2v_up.length() == downsize, "rv is not fully in rv_up" );
+}
+
+void datalink_part::set_connection ( const RV &rv, const RV &rv_up ) {
+	rv.dataind ( rv_up, v2v_down, v2v_up );
+	downsize = v2v_down.length();
+	upsize = v2v_up.length();
+}
+
+void datalink_m2e::set_connection ( const RV &rv, const RV &rvc, const RV &rv_up ) {
+	datalink::set_connection ( rv, rv_up );
 	condsize = rvc._dsize();
 	//establish v2c connection
-	rvc.dataind (rv_up, v2c_lo, v2c_up);
-}
-
-vec datalink_m2e::get_cond (const vec &val_up) {
-	vec tmp (condsize);
-	set_subvector (tmp, v2c_lo, val_up (v2c_up));
+	rvc.dataind ( rv_up, v2c_lo, v2c_up );
+}
+
+vec datalink_m2e::get_cond ( const vec &val_up ) {
+	vec tmp ( condsize );
+	set_subvector ( tmp, v2c_lo, val_up ( v2c_up ) );
 	return tmp;
 }
 
-void datalink_m2e::pushup_cond (vec &val_up, const vec &val, const vec &cond) {
-	bdm_assert_debug (downsize == val.length(), "Wrong val");
-	bdm_assert_debug (upsize == val_up.length(), "Wrong val_up");
-	set_subvector (val_up, v2v_up, val);
-	set_subvector (val_up, v2c_up, cond);
+void datalink_m2e::pushup_cond ( vec &val_up, const vec &val, const vec &cond ) {
+	bdm_assert_debug ( downsize == val.length(), "Wrong val" );
+	bdm_assert_debug ( upsize == val_up.length(), "Wrong val_up" );
+	set_subvector ( val_up, v2v_up, val );
+	set_subvector ( val_up, v2c_up, cond );
 }
 
@@ -233,6 +234,6 @@
 	for ( int i = 0; i < rv.len ; i++ ) {
 		id = rv.ids ( i );
-		os << id << "(" << RV_SIZES ( id ) << ")" <<  // id(size)=
-		"=" << RV_NAMES ( id )  << "_{"  << rv.times ( i ) << "}; "; //name_{time}
+		os << id << "(" << RV::SIZES ( id ) << ")" <<  // id(size)=
+		"=" << RV::NAMES ( id )  << "_{"  << rv.times ( i ) << "}; "; //name_{time}
 	}
 	return os;
@@ -364,9 +365,9 @@
 	shared_ptr<epdf> e ( UI::build<epdf> ( set, "epdf", UI::compulsory ) );
 	iepdf = e;
-	set_ep(iepdf.get());
+	set_ep ( iepdf.get() );
 }
 
 RV get_composite_rv ( const Array<shared_ptr<mpdf> > &mpdfs,
-		      bool checkoverlap ) {
+                      bool checkoverlap ) {
 	RV rv; //empty rv
 	bool rvaddok;
