Index: library/bdm/math/square_mat.h
===================================================================
--- library/bdm/math/square_mat.h (revision 1064)
+++ library/bdm/math/square_mat.h (revision 1079)
@@ -324,4 +324,5 @@
     }
     void validate() {
+		bdm_assert(L.rows()==D.length(),"Incompatible L and D in ldmat");
         dim= L.rows();
     }
Index: library/bdm/mpdm/arx_agent.h
===================================================================
--- library/bdm/mpdm/arx_agent.h (revision 1064)
+++ library/bdm/mpdm/arx_agent.h (revision 1079)
@@ -86,10 +86,10 @@
             merger->merge();
             enorm<chmat> joint_pred;
-            mat Cov=merger->covariance();
+            mat Cov=merger->merger().covariance();
             if (sumsum(Cov)==0.0) {
                 bdm_error("merging failed");
             }
-            joint_pred.set_parameters(merger->mean(), Cov);
-            joint_pred.set_rv(merger->_rv());
+            joint_pred.set_parameters(merger->merger().mean(), Cov);
+            joint_pred.set_rv(merger->merger()._rv());
 
             enorm<chmat> marg_pred; // remove rvs taht should not be there
Index: library/bdm/base/user_info.cpp
===================================================================
--- library/bdm/base/user_info.cpp (revision 1064)
+++ library/bdm/base/user_info.cpp (revision 1079)
@@ -382,8 +382,12 @@
     if(element.exists("L")) {
         UI::from_setting(matrix.__L(), element["L"]);
-    }
+	} else { 
+		throw  UISettingException ( "UIException: ldmat must contain matrix L.", element);
+	}
     if(element.exists("D")) {
         UI::from_setting(matrix.__D(), element["D"]);
-    }
+    } else {
+		throw  UISettingException ( "UIException: ldmat must contain vector D.", element);
+	}
     matrix.validate();
 }
Index: library/bdm/stat/merger.cpp
===================================================================
--- library/bdm/stat/merger.cpp (revision 1068)
+++ library/bdm/stat/merger.cpp (revision 1079)
@@ -5,5 +5,5 @@
 namespace bdm {
 
-merger_base::merger_base ( const Array<shared_ptr<pdf> > &S ) :
+MergerDiscrete::MergerDiscrete ( const Array<shared_ptr<pdf> > &S ) :
     Npoints ( 0 ), DBG ( false ), dbg_file ( 0 ) {
     set_sources ( S );
@@ -11,18 +11,19 @@
 
 
-void merger_base::set_sources ( const Array<shared_ptr<pdf> > &Sources ) {
-    pdfs = Sources;
-    Nsources = pdfs.length();
+void MergerDiscrete::set_sources ( const Array<shared_ptr<pdf> > &PartSources ) {
+    part_sources = PartSources;
+    Nsources = part_sources.length();
     //set sizes
-    dls.set_size ( Sources.length() );
-    rvzs.set_size ( Sources.length() );
-    zdls.set_size ( Sources.length() );
-
-    rv = get_composite_rv ( pdfs, /* checkoverlap = */ false );
+    sources.set_size ( Nsources);
+	dls.set_size ( Nsources );
+	rvzs.set_size ( Nsources );
+	zdls.set_size ( Nsources );
+
+    RV rv = get_composite_rv ( part_sources, /* checkoverlap = */ false );
 
     RV rvc;
     // Extend rv by rvc!
-    for ( int i = 0; i < pdfs.length(); i++ ) {
-        RV rvx = pdfs ( i )->_rvc().subt ( rv );
+    for ( int i = 0; i < sources.length(); i++ ) {
+        RV rvx = part_sources ( i )->_rvc().subt ( rv );
         rvc.add ( rvx ); // add rv to common rvc
     }
@@ -30,17 +31,15 @@
     // join rv and rvc - see descriprion
     rv.add ( rvc );
-    // get dimension
-    dim = rv._dsize();
-
+	
     // create links between sources and common rv
     RV xytmp;
-    for ( int i = 0; i < pdfs.length(); i++ ) {
+    for ( int i = 0; i < part_sources.length(); i++ ) {		
         //Establich connection between pdfs and merger
         dls ( i ) = new datalink_m2e;
-        dls ( i )->set_connection ( pdfs ( i )->_rv(), pdfs ( i )->_rvc(), rv );
+		dls ( i )->set_connection ( part_sources ( i )->_rv(), part_sources( i )->_rvc(), rv );
 
         // find out what is missing in each pdf
-        xytmp = pdfs ( i )->_rv();
-        xytmp.add ( pdfs ( i )->_rvc() );
+        xytmp = part_sources ( i )->_rv();
+		xytmp.add ( part_sources ( i )->_rvc() );
         // z_i = common_rv-xy
         rvzs ( i ) = rv.subt ( xytmp );
@@ -49,7 +48,10 @@
         zdls ( i )->set_connection ( rvzs ( i ), xytmp, rv ) ;
     };
-}
-
-void merger_base::set_support ( rectangular_support &Sup ) {
+	
+	// 
+	merger().set_rv(rv);
+}
+
+void MergerDiscrete::set_support ( rectangular_support &Sup ) {
     Npoints = Sup.points();
     eSmp.set_parameters ( Npoints, false );
@@ -61,23 +63,24 @@
         samples ( j ) = Sup.next_vec();
     }
-}
-
-void merger_base::merge () {
+    eSmp.validate();
+}
+
+void MergerDiscrete::merge () {
     validate();
 
     //check if sources overlap:
     bool OK = true;
-    for ( int i = 0; i < pdfs.length(); i++ ) {
+    for ( int i = 0; i < part_sources.length(); i++ ) {
         OK &= ( rvzs ( i )._dsize() == 0 ); // z_i is empty
-        OK &= ( pdfs ( i )->_rvc()._dsize() == 0 ); // y_i is empty
+        OK &= ( part_sources ( i )->_rvc()._dsize() == 0 ); // y_i is empty
     }
 
     if ( OK ) {
-        mat lW = zeros ( pdfs.length(), eSmp._w().length() );
+        mat lW = zeros ( part_sources.length(), eSmp._w().length() );
 
         vec emptyvec ( 0 );
-        for ( int i = 0; i < pdfs.length(); i++ ) {
+        for ( int i = 0; i < part_sources.length(); i++ ) {
             for ( int j = 0; j < eSmp._w().length(); j++ ) {
-                lW ( i, j ) = pdfs ( i )->evallogcond ( eSmp._samples() ( j ), emptyvec );
+                lW ( i, j ) = part_sources ( i )->evallogcond ( eSmp._samples() ( j ), emptyvec );
             }
         }
@@ -92,5 +95,5 @@
 }
 
-vec merger_base::merge_points ( mat &lW ) {
+vec MergerDiscrete::merge_points ( mat &lW ) {
     int nu = lW.rows();
     vec result;
@@ -144,39 +147,7 @@
 }
 
-vec merger_base::mean() const {
-    const Vec<double> &w = eSmp._w();
-    const Array<vec> &S = eSmp._samples();
-    vec tmp = zeros ( dim );
-    for ( int i = 0; i < Npoints; i++ ) {
-        tmp += w ( i ) * S ( i );
-    }
-    return tmp;
-}
-
-mat merger_base::covariance() const {
-    const vec &w = eSmp._w();
-    const Array<vec> &S = eSmp._samples();
-
-    vec mea = mean();
-
-//             cout << sum (w) << "," << w*w << endl;
-
-    mat Tmp = zeros ( dim, dim );
-    for ( int i = 0; i < Npoints; i++ ) {
-        vec tmp=S ( i )-mea; //inefficient but numerically stable
-        Tmp += w ( i ) * outer_product (tmp , tmp );
-    }
-    return Tmp;
-}
-
-vec merger_base::variance() const {
-    return eSmp.variance();
-}
-
-
-void merger_base::from_setting ( const Setting& set ) {
+void MergerDiscrete::from_setting ( const Setting& set ) {
     // get support
     // find which method to use
-    epdf::from_setting (set);
     string meth_str;
     UI::get( meth_str, set, "method", UI::compulsory );
@@ -197,7 +168,5 @@
 }
 
-void merger_base::to_setting  (Setting  &set) const {
-    epdf::to_setting(set);
-
+void MergerDiscrete::to_setting  (Setting  &set) const {
     UI::save( METHOD, set, "method");
 
@@ -209,16 +178,13 @@
 }
 
-void merger_base::validate() {
+void MergerDiscrete::validate() {
 //        bdm_assert ( eSmp._w().length() > 0, "Empty support, use set_support()." );
 //        bdm_assert ( dim == eSmp._samples() ( 0 ).length(), "Support points and rv are not compatible!" );
-    epdf::validate();
-    bdm_assert ( isnamed(), "mergers must be named" );
-}
-
-// DEFAULTS FOR MERGER_BASE
-const MERGER_METHOD merger_base::DFLT_METHOD = LOGNORMAL;
-const double merger_base::DFLT_beta = 1.2;
+    MergerBase::validate();
+    //bdm_assert ( merger().isnamed(), "mergers must be named" );
+}
 
 void merger_mix::merge ( ) {
+	int dim = eSmp.dimension();
     if(Npoints<1) {
         set_support(enorm<fsqmat>(zeros(dim), eye(dim)), 1000);
@@ -231,5 +197,5 @@
     vec &w = eSmp._w(); //aux
 
-    mat Smp_ex = ones ( dim + 1, Npoints ); // Extended samples for the ARX model - the last row is ones
+    mat Smp_ex = ones ( dim, Npoints ); // Extended samples for the ARX model
     for ( int i = 0; i < Npoints; i++ ) {
         set_col_part ( Smp_ex, i, Smp ( i ) );
@@ -242,5 +208,5 @@
     vec lw_mix ( Npoints );        // weights of the approximating mixture
     vec lw ( Npoints );            // tmp
-    mat lW = zeros ( Nsources, Npoints ); // array of weights of all sources
+    mat lW = zeros ( Nsources, Npoints ); // array of weights of all part_sources
     vec vec0 ( 0 );
 
@@ -263,5 +229,5 @@
     char dbg_str[100];
 
-    emix* Mpred = Mix.epredictor ( );
+	emix *Mpred = Mix.epredictor ( );
     vec Mix_pdf ( Npoints );
     while ( !converged ) {
@@ -272,5 +238,5 @@
         delete Mpred;
         Mpred = Mix.epredictor ( ); // Allocation => must be deleted at the end!!
-        Mpred->set_rv ( rv ); //the predictor predicts rv of this merger
+        Mpred->set_rv ( merger()._rv() ); //the predictor predicts rv of this merger
 
         // This will be active only later in iterations!!!
@@ -299,5 +265,5 @@
             *dbg_file << Name ( dbg_str ) << Mpred->variance();
             sprintf ( dbg_str, "Mpred_cov%d", niter );
-            *dbg_file << Name ( dbg_str ) << covariance();
+            *dbg_file << Name ( dbg_str ) << Mpred->covariance();
 
 
@@ -313,16 +279,16 @@
         }
         //Importace weighting
-        for ( int i = 0; i < pdfs.length(); i++ ) {
+        for ( int i = 0; i < part_sources.length(); i++ ) {
             lw_src = 0.0;
             //======== Same RVs ===========
             //Split according to dependency in rvs
-            if ( pdfs ( i )->dimension() == dim ) {
+            if ( part_sources ( i )->dimension() == dim ) {
                 // no need for conditioning or marginalization
-                lw_src = pdfs ( i )->evallogcond_mat ( Smp , vec ( 0 ) );
+                lw_src = part_sources ( i )->evallogcond_mat ( Smp , vec ( 0 ) );
             } else {
                 // compute likelihood of marginal on the conditional variable
-                if ( pdfs ( i )->dimensionc() > 0 ) {
+                if ( part_sources ( i )->dimensionc() > 0 ) {
                     // Make marginal on rvc_i
-                    shared_ptr<epdf> tmp_marg = Mpred->marginal ( pdfs ( i )->_rvc() );
+                    shared_ptr<epdf> tmp_marg = Mpred->marginal ( part_sources ( i )->_rvc() );
                     //compute vector of lw_src
                     for ( int k = 0; k < Npoints; k++ ) {
@@ -336,5 +302,5 @@
                 }
                 // Compute likelihood of the missing variable
-                if ( dim > ( pdfs ( i )->dimension() + pdfs ( i )->dimensionc() ) ) {
+                if ( dim > ( part_sources ( i )->dimension() + part_sources ( i )->dimensionc() ) ) {
                     ///////////////
                     // There are variales unknown to pdfs(i) : rvzs
@@ -355,5 +321,5 @@
                 // Compute likelihood of the partial source
                 for ( int k = 0; k < Npoints; k++ ) {
-                    lw_src ( k ) += pdfs ( i )->evallogcond ( dls ( i )->pushdown ( Smp ( k ) ),
+                    lw_src ( k ) += part_sources ( i )->evallogcond ( dls ( i )->pushdown ( Smp ( k ) ),
                                     dls ( i )->get_cond ( Smp ( k ) ) );
                 }
@@ -363,5 +329,5 @@
             lW.set_row ( i, lw_src ); // do not divide by mix
         }
-        lw = merger_base::merge_points ( lW ); //merge
+        lw = MergerDiscrete::merge_points ( lW ); //merge
 
         //Importance weighting
@@ -391,10 +357,8 @@
     }
     delete Mpred;
-//        cout << endl;
-
 }
 
 void merger_mix::from_setting ( const Setting& set ) {
-    merger_base::from_setting ( set );
+    MergerDiscrete::from_setting ( set );
     Ncoms=DFLT_Ncoms;
     UI::get( Ncoms, set, "ncoms", UI::optional );
@@ -406,5 +370,5 @@
 
 void merger_mix::to_setting  (Setting  &set) const  {
-    merger_base::to_setting(set);
+    MergerDiscrete::to_setting(set);
     UI::save( Ncoms, set, "ncoms");
     UI::save (effss_coef , set,  "effss_coef");
@@ -413,5 +377,5 @@
 
 void merger_mix::validate() {
-    merger_base::validate();
+    MergerDiscrete::validate();
     bdm_assert(Ncoms>0,"Ncoms too small");
 }
Index: library/bdm/stat/exp_family.h
===================================================================
--- library/bdm/stat/exp_family.h (revision 1077)
+++ library/bdm/stat/exp_family.h (revision 1079)
@@ -484,5 +484,5 @@
     V.L     = [...];       % L part of matrix V
     V.D     = [...];       % D part of matrix V
-    -or- V  = [...];       % full matrix V
+    -or- fV = [...];       % full matrix V
     -or- dV = [...];       % vector of diagonal of V (when V not given)
 
Index: library/bdm/stat/merger.h
===================================================================
--- library/bdm/stat/merger.h (revision 1072)
+++ library/bdm/stat/merger.h (revision 1079)
@@ -32,11 +32,11 @@
 		//! weights of the sources -- no restrictions
 		vec w;
-		//! get ith source
+		//! source pdfs -- conditioning allowed
 		Array<shared_ptr<epdf> > sources;
 		//! merge 
-		void merge() NOT_IMPLEMENTED_VOID;
+		virtual void merge() NOT_IMPLEMENTED_VOID;
 		//! 
 		//! check if all epdfs are on the same support
-		void validate() {
+		void validate_sources() {
 			int n=sources.length();
 			
@@ -75,8 +75,13 @@
 			vec mea=zeros(dim);
 			// go through all sources
+			epdf * si;
 			for (int i=0; i<n; i++){
-				sq_T Ci = sources(i)->covariance();
+				si = dynamic_cast<epdf*>(sources(i).get());  // transform pdf into epdf
+
+				if (!si) {bdm_error("Can't merger this type of pdf: " + sources(i)->to_string());}
+				
+				sq_T Ci = si->covariance();
 				sq_T wCi = Ci; wCi*=w(i);
-				vec mi = sources(i)->mean();
+				vec mi = si->mean();
 				switch (method) {
 					case ARITHMETIC:{
@@ -133,10 +138,12 @@
 However, these operations can not be performed in general. Hence, this class merges only sources on common support, \f$ y_i={}, z_i={}, \forall i \f$.
 For merging of more general cases, use offsprings merger_mix and merger_grid.
+
+\TODO use sources for extensions
 */
-class merger_base : public epdf {
+class MergerDiscrete : public MergerBase {
 protected:
-    //! Elements of composition
-    Array<shared_ptr<pdf> > pdfs;
-
+	//! partial sources
+	Array<shared_ptr< pdf > > part_sources;
+	
     //! Data link for each pdf in pdfs
     Array<datalink_m2e*> dls;
@@ -177,12 +184,12 @@
 
     //! Default constructor
-    merger_base () : Npoints ( 0 ), Nsources ( 0 ), DBG ( false ), dbg_file ( 0 ) {
+    MergerDiscrete () : Npoints ( 0 ), Nsources ( 0 ), DBG ( false ), dbg_file ( 0 ) {
     }
 
     //!Constructor from sources
-    merger_base ( const Array<shared_ptr<pdf> > &S );
+    MergerDiscrete ( const Array<shared_ptr<pdf> > &S );
 
     //! Function setting the main internal structures
-    void set_sources ( const Array<shared_ptr<pdf> > &Sources );
+    void set_sources ( const Array<shared_ptr<pdf> > &PartSources );
 
     //! Set support points from rectangular grid
@@ -205,5 +212,5 @@
 
     //! Set internal parameters used in approximation
-    void set_method ( MERGER_METHOD MTH = DFLT_METHOD, double beta0 = DFLT_beta ) {
+    void set_method ( MERGER_METHOD MTH = GEOMETRIC, double beta0 = 1.2 ) {
         METHOD = MTH;
         beta = beta0;
@@ -216,5 +223,5 @@
 
     //! Destructor
-    virtual ~merger_base() {
+    virtual ~MergerDiscrete() {
         for ( int i = 0; i < Nsources; i++ ) {
             delete dls ( i );
@@ -229,25 +236,10 @@
 
     //!Merge given sources in given points
-    virtual void merge ();
+    void merge ();
 
     //! Merge log-likelihood values in points using method specified by parameter METHOD
     vec merge_points ( mat &lW );
 
-
-    //! sample from merged density
-//! weight w is a
-    vec mean() const;
-
-    mat covariance() const;
-
-    vec variance() const;
-
-    //! Compute log-probability of argument \c val
-    virtual double evallog ( const vec &val ) const NOT_IMPLEMENTED(0);
-
-    //! Returns a sample, \f$ x \f$ from density \f$ f_x()\f$
-    virtual vec sample() const NOT_IMPLEMENTED(0);
-
-    //!@}
+  //!@}
 
     //! \name Access to attributes
@@ -258,4 +250,6 @@
         return eSmp;
     }
+
+	eEmp & merger() {return eSmp;}
 
     /*! Create object from the following structure
@@ -279,9 +273,9 @@
     //!@}
 };
-UIREGISTER ( merger_base );
-SHAREDPTR ( merger_base );
+UIREGISTER ( MergerDiscrete );
+SHAREDPTR ( MergerDiscrete );
 
 //! \brief Merger using importance sampling with mixture proposal density
-class merger_mix : public merger_base {
+class merger_mix : public MergerDiscrete {
 protected:
     //!Internal mixture of EF models
@@ -311,5 +305,5 @@
     //! Set sources and prepare all internal structures
     void set_sources ( const Array<shared_ptr<pdf> > &S ) {
-        merger_base::set_sources ( S );
+        MergerDiscrete::set_sources ( S );
         //Nsources = S.length();
     }
@@ -349,5 +343,5 @@
     emix* proposal() {
         emix* tmp = Mix.epredictor();
-        tmp->set_rv ( rv );
+        tmp->set_rv ( merger()._rv() );
         return tmp;
     }
@@ -376,4 +370,5 @@
     void validate();
 
+//	const emix &merger(){return *Mpred;}
     //! @}
 };
Index: library/bdm/stat/exp_family.cpp
===================================================================
--- library/bdm/stat/exp_family.cpp (revision 1068)
+++ library/bdm/stat/exp_family.cpp (revision 1079)
@@ -323,6 +323,8 @@
     }
     mat Vful;
-    if (!UI::get(V, set, "V", UI::optional)) {
-        if ( !UI::get ( Vful, set, "V", UI::optional ) ) {
+	if (set.exists("V.L")){
+		UI::get(V, set, "V", UI::optional);
+	} else {
+        if ( !UI::get ( Vful, set, "fV", UI::optional ) ) {
             vec dV;
             UI::get ( dV, set, "dV", UI::compulsory );
@@ -346,5 +348,6 @@
     nPsi = V.rows() - dimx;
     dim = dimx * ( dimx + nPsi );
-
+	if (dim<dimx) {bdm_error("Check if matrix V has correct dimension");}
+	
     if ( nu < 0 ) {
         nu = 0.1 + nPsi + 2 * dimx + 2; // +2 assures finite expected value of R
