edoSamplerNormalAdaptive.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 Dréo <johann.dreo@thalesgroup.com>
00025     Pierre Savéant <pierre.saveant@thalesgroup.com>
00026 */
00027 
00028 #ifndef _edoSamplerNormalAdaptive_h
00029 #define _edoSamplerNormalAdaptive_h
00030 
00031 #include <cmath>
00032 #include <limits>
00033 
00034 #include <edoSampler.h>
00035 
00043 #ifdef WITH_EIGEN
00044 
00045 template< class EOT, typename D = edoNormalAdaptive< EOT > >
00046 class edoSamplerNormalAdaptive : public edoSampler< D >
00047 {
00048 public:
00049     typedef typename EOT::AtomType AtomType;
00050 
00051     typedef typename D::Vector Vector;
00052     typedef typename D::Matrix Matrix;
00053 
00054     edoSamplerNormalAdaptive( edoRepairer<EOT> & repairer ) 
00055         : edoSampler< D >( repairer)
00056     {}
00057 
00058 
00059     EOT sample( D& distrib )
00060     {
00061         unsigned int N = distrib.size();
00062         assert( N > 0);
00063 
00064         // T = vector of size elements drawn in N(0,1)
00065         Vector T( N );
00066         for ( unsigned int i = 0; i < N; ++i ) {
00067             T( i ) = rng.normal();
00068         }
00069         assert(T.innerSize() == N );
00070         assert(T.outerSize() == 1);
00071 
00072         // mean(N,1) + sigma * B(N,N) * ( D(N,1) .* T(N,1) )
00073         Vector sol = distrib.mean()
00074             + distrib.sigma()
00075             * distrib.coord_sys() * (distrib.scaling().cwiseProduct(T) ); // C * T = B * (D .* T)
00076         assert( sol.size() == N );
00077         /*Vector sol = distrib.mean() + distrib.sigma()
00078             * distrib.coord_sys().dot( distrib.scaling().dot( T ) );*/
00079 
00080         // copy in the EOT structure (more probably a vector)
00081         EOT solution( N );
00082         for( unsigned int i = 0; i < N; i++ ) {
00083             solution[i]= sol(i);
00084         }
00085 
00086         return solution;
00087     }
00088 };
00089 #endif // WITH_EIGEN
00090 
00091 #endif // !_edoSamplerNormalAdaptive_h
 All Classes Functions Variables Typedefs