edoNormalMulti.h
00001 /*
00002 The Evolving Distribution Objects framework (EDO) is a template-based,
00003 ANSI-C++ evolutionary computation library which helps you to write your
00004 own estimation of distribution algorithms.
00005 
00006 This library is free software; you can redistribute it and/or
00007 modify it under the terms of the GNU Lesser General Public
00008 License as published by the Free Software Foundation; either
00009 version 2.1 of the License, or (at your option) any later version.
00010 
00011 This library is distributed in the hope that it will be useful,
00012 but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014 Lesser General Public License for more details.
00015 
00016 You should have received a copy of the GNU Lesser General Public
00017 License along with this library; if not, write to the Free Software
00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019 
00020 Copyright (C) 2010 Thales group
00021 */
00022 /*
00023     Authors:
00024              Johann Dreo <johann.dreo@thalesgroup.com>
00025              Caner Candan <caner.candan@thalesgroup.com>
00026 */
00027 
00028 #ifndef _edoNormalMulti_h
00029 #define _edoNormalMulti_h
00030 
00031 #include "edoDistrib.h"
00032 
00033 #ifdef WITH_BOOST
00034 #include <boost/numeric/ublas/symmetric.hpp>
00035 #include <boost/numeric/ublas/lu.hpp>
00036 namespace ublas = boost::numeric::ublas;
00037 #else
00038 #ifdef WITH_EIGEN
00039 #include <Eigen/Dense>
00040 #endif // WITH_EIGEN
00041 #endif // WITH_BOOST
00042 
00071 template < typename EOT >
00072 class edoNormalMulti : public edoDistrib< EOT >
00073 {
00074 #ifdef WITH_BOOST
00075 
00076 
00077 public:
00078     typedef typename EOT::AtomType AtomType;
00079 
00080     edoNormalMulti( unsigned int dim = 1 ) :
00081             _mean( const ublas::vector<AtomType>(0,dim)        ),
00082         _varcovar( const ublas::identity_matrix<AtomType>(dim) )
00083     {
00084         assert(_mean.size() > 0);
00085         assert(_mean.size() == _varcovar.size1());
00086         assert(_mean.size() == _varcovar.size2());
00087     }
00088 
00089     edoNormalMulti
00090     (
00091      const ublas::vector< AtomType >& mean,
00092      const ublas::symmetric_matrix< AtomType, ublas::lower >& varcovar
00093      )
00094         : _mean(mean), _varcovar(varcovar)
00095     {
00096         assert(_mean.size() > 0);
00097         assert(_mean.size() == _varcovar.size1());
00098         assert(_mean.size() == _varcovar.size2());
00099     }
00100 
00101     unsigned int size()
00102     {
00103         assert(_mean.size() == _varcovar.size1());
00104         assert(_mean.size() == _varcovar.size2());
00105         return _mean.size();
00106     }
00107 
00108     ublas::vector< AtomType > mean() const {return _mean;}
00109     ublas::symmetric_matrix< AtomType, ublas::lower > varcovar() const {return _varcovar;}
00110 
00111 private:
00112     ublas::vector< AtomType > _mean;
00113     ublas::symmetric_matrix< AtomType, ublas::lower > _varcovar;
00114 
00115 #else
00116 #ifdef WITH_EIGEN
00117 
00118 
00119 public:
00120     typedef typename EOT::AtomType AtomType;
00121     typedef Eigen::Matrix< AtomType, Eigen::Dynamic, 1> Vector;
00122     typedef Eigen::Matrix< AtomType, Eigen::Dynamic, Eigen::Dynamic> Matrix;
00123 
00124     edoNormalMulti( unsigned int dim = 1 ) :
00125             _mean( Vector::Zero(dim) ),
00126         _varcovar( Matrix::Identity(dim,dim) )
00127     {
00128         assert(_mean.size() > 0);
00129         assert(_mean.innerSize() == _varcovar.innerSize());
00130         assert(_mean.innerSize() == _varcovar.outerSize());
00131     }
00132 
00133     edoNormalMulti(
00134         const Vector & mean,
00135         const Matrix & varcovar
00136     )
00137         : _mean(mean), _varcovar(varcovar)
00138     {
00139         assert(_mean.innerSize() > 0);
00140         assert(_mean.innerSize() == _varcovar.innerSize());
00141         assert(_mean.innerSize() == _varcovar.outerSize());
00142     }
00143 
00144     unsigned int size()
00145     {
00146         assert(_mean.innerSize() == _varcovar.innerSize());
00147         assert(_mean.innerSize() == _varcovar.outerSize());
00148         return _mean.innerSize();
00149     }
00150 
00151     Vector mean() const {return _mean;}
00152     Matrix varcovar() const {return _varcovar;}
00153 
00154 private:
00155     Vector _mean;
00156     Matrix _varcovar;
00157 
00158 #endif // WITH_EIGEN
00159 #endif // WITH_BOOST
00160 
00161 }; // class edoNormalMulti
00162 
00163 #endif // !_edoNormalMulti_h
 All Classes Functions Variables Typedefs