Index: bdm/stat/libBM.h
===================================================================
--- bdm/stat/libBM.h (revision 270)
+++ bdm/stat/libBM.h (revision 271)
@@ -11,10 +11,4 @@
 */
 
-/*!
-\defgroup core Core BDM classes
-@{
-\defgroup const Constructors
-\defgroup math Mathematical operations
-*/
 #ifndef BM_H
 #define BM_H
@@ -106,22 +100,22 @@
 	int init ( const  string &name, int size );
 public:
-	//! \name Constructors 
-	//!@{
-	
-	//! Full constructor 
+	//! \name Constructors
+	//!@{
+
+	//! Full constructor
 	RV ( Array<std::string> in_names, ivec in_sizes, ivec in_times ) {init ( in_names,in_sizes,in_times );};
-	//! Constructor with times=0 
+	//! Constructor with times=0
 	RV ( Array<std::string> in_names, ivec in_sizes ) {init ( in_names,in_sizes,zeros_i ( in_names.length() ) );};
-	//! Constructor with sizes=1, times=0 
+	//! Constructor with sizes=1, times=0
 	RV ( Array<std::string> in_names ) {init ( in_names,ones_i ( in_names.length() ),zeros_i ( in_names.length() ) );}
-	//! Constructor of empty RV 
+	//! 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 );
 	//!@}
-	
+
 	//! \name Access functions
 	//!@{
-	
+
 	//! Printing output e.g. for debugging.
 	friend std::ostream &operator<< ( std::ostream &os, const RV &rv );
@@ -129,17 +123,18 @@
 	//! 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 ( 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 ( at );};
+	std::string name ( int at ) const {return RV_NAMES ( ids(at) );};
 	void set_time ( int at, int time0 ) {times ( at ) =time0;};
 	//!@}
-	
+
 	//TODO why not inline and later??
 
 	//! \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;
@@ -154,11 +149,20 @@
 	//! Select only variables at indeces 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 {
+		ivec sz=cumsizes();
+		int i1=0;
+		while ( sz ( i1 ) <di1 ) i1++;
+		int i2=i1;
+		while ( sz ( i2 ) <di2 ) i2++;
+		return subselect ( linspace ( i1,i2 ) );
+	};
 	//! Shift \c time shifted by delta.
 	void t ( int delta );
 	//!@}
-	
-	//!\name Relation to vectors 
-	//!@{
-	
+
+	//!\name Relation to vectors
+	//!@{
+
 	//! generate \c str from rv, by expanding sizes
 	str tostr() const;
@@ -172,5 +176,5 @@
 	int mint () const {return min ( times );};
 	//!@}
-	
+
 };
 
@@ -216,29 +220,29 @@
 public:
 	/*! \name Constructors
-	 Construction of each epdf should support two types of constructors: 
-	\li empty constructor, 
+	 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 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) {set_rv(rv0);};
-	void set_parameters(int dim0){dim=dim0;}
-	//!@}
-	
+	epdf() :dim ( 0 ),rv ( ) {};
+	epdf ( const epdf &e ) :dim ( e.dim ),rv ( e.rv ) {};
+	epdf ( const RV &rv0 ) {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 {it_error("not implemneted");return vec(0);};
+	virtual vec sample () const {it_error ( "not implemneted" );return vec ( 0 );};
 	//! 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
-	virtual double evallog ( const vec &val ) const {it_error("not implemneted");return 0.0;};
+	virtual double evallog ( const vec &val ) const {it_error ( "not implemneted" );return 0.0;};
 	//! Compute log-probability of multiple values argument \c val
 	virtual vec evallog_m ( const mat &Val ) const {
@@ -252,30 +256,30 @@
 	virtual epdf* marginal ( const RV &rv ) const {it_warning ( "Not implemented" ); return NULL;}
 	//! return expected value
-	virtual vec mean() const {it_error("not implemneted");return vec(0);};
+	virtual vec mean() const {it_error ( "not implemneted" );return vec ( 0 );};
 	//! return expected variance (not covariance!)
-	virtual vec variance() const {it_error("not implemneted");return vec(0);};
-	//!@}
-	
+	virtual vec variance() const {it_error ( "not implemneted" );return vec ( 0 );};
+	//!@}
+
 	//! \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: 
+	//! 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; }//it_assert_debug(isnamed(),""); };
-	//! True if rv is assigned 
-	bool isnamed() const {bool b=( dim==rv._dsize() );return b;}
+	//! 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 {it_assert_debug ( isnamed(),"" ); return rv;}
 	//!@}
-	
+
 	//! \name Access to attributes
 	//! @{
-	
+
 	//! Size of the random variable
 	int dimension() const {return dim;}
 	//!@}
-	
+
 };
 
@@ -295,13 +299,13 @@
 	//! \name Constructors
 	//! @{
-	
-	mpdf ( ) :dimc(0),rvc ( ) {};
+
+	mpdf ( ) :dimc ( 0 ),rvc ( ) {};
 	//! copy constructor does not set pointer \c ep - has to be done in offsprings!
-	mpdf (const mpdf &m ) :dimc(m.dimc),rvc (m.rvc ) {};
+	mpdf ( const mpdf &m ) :dimc ( m.dimc ),rvc ( m.rvc ) {};
 	//!@}
 
 	//! \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 ) {
@@ -330,5 +334,5 @@
 	//! \name Access to attributes
 	//! @{
-	
+
 	RV _rv() {return ep->_rv();}
 	RV _rvc() {it_assert_debug ( isnamed(),"" ); return rvc;}
@@ -338,10 +342,10 @@
 	epdf* _e() {return ep;}
 	//!@}
-	
+
 	//! \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());}
+	void set_rv ( const RV &rv0 ) {ep->set_rv ( rv0 );}
+	bool isnamed() {return ( ep->isnamed() ) && ( dimc==rvc._dsize() );}
 	//!@}
 };
@@ -382,6 +386,12 @@
 public:
 	//! Constructor
-	datalink ( const RV &rv, const RV &rv_up ) :
-			downsize ( rv._dsize() ), upsize ( rv_up._dsize() ), v2v_up ( rv.dataind ( rv_up ) )  {
+	datalink () {};
+	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 ) {
+		downsize = rv._dsize();
+		upsize = rv_up._dsize();
+		v2v_up= ( rv.dataind ( rv_up ) );
+
 		it_assert_debug ( v2v_up.length() ==downsize,"rv is not fully in rv_up" );
 	}
@@ -471,10 +481,15 @@
 	logger ( ) : entries ( 0 ),names ( 0 ) {}
 
-	//! returns an identifier which will be later needed for calling the log() function
+	//! 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 name="" ) {
-		int id=entries.length();
-		names=concat ( names, name ); // diff
-		entries.set_length ( id+1,true );
-		entries ( id ) = rv;
+		int id;
+		if ( rv._dsize() >0 ) {
+			id=entries.length();
+			names=concat ( names, name ); // diff
+			entries.set_length ( id+1,true );
+			entries ( id ) = rv;
+		}
+		else { id =-1;}
 		return id; // identifier of the last entry
 	}
@@ -539,5 +554,5 @@
 public:
 	//! default constructors
-	DS() :Drv (  ),Urv ( ) {};
+	DS() :Drv ( ),Urv ( ) {};
 	//! Returns full vector of observed data=[output, input]
 	virtual void getdata ( vec &dt ) {it_error ( "abstract class" );};
@@ -590,7 +605,7 @@
 	//! \name Constructors
 	//! @{
-	
-	BM () :ll (0),evalll ( false) {};
-	BM ( const BM &B ) :  drv(B.drv), ll ( B.ll ), evalll ( B.evalll ) {}
+
+	BM () :ll ( 0 ),evalll ( false ) {};
+	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_(){return new BM(*this);} \endcode
@@ -600,5 +615,5 @@
 	//! \name Mathematical operations
 	//!@{
-	
+
 	/*! \brief Incremental Bayes rule
 	@param dt vector of input data
@@ -614,17 +629,18 @@
 
 	//!Constructs a predictive density \f$ f(d_{t+1} |d_{t}, \ldots d_{0}) \f$
-	virtual epdf* epredictor (  ) const {it_error ( "Not implemented" );return NULL;};
+	virtual epdf* epredictor ( ) const {it_error ( "Not implemented" );return NULL;};
 	//!Constructs a conditional density 1-step ahead predictor \f$ f(d_{t+1} |d_{t+h-1}, \ldots d_{t})
 	virtual mpdf* predictor ( ) const {it_error ( "Not implemented" );return NULL;};
 	//!@}
-	
+
 	//! \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& _epdf() const =0;
+	virtual const epdf& posterior() const =0;
 	virtual const epdf* _e() const =0;
 	//!@}
@@ -657,4 +673,3 @@
 
 }; //namespace
-/*! @} */
 #endif // BM_H
