# eoEsChromInit.h

    00001 //
    00002 /* (c) Maarten Keijzer 2000, GeNeura Team, 1998 - EEAAX 1999
    00003
    00004 This library is free software; you can redistribute it and/or modify it under
    00005 the terms of the GNU Lesser General Public License as published by the Free
    00006 Software Foundation; either version 2 of the License, or (at your option) any
    00007 later version.
    00008
    00009 This library is distributed in the hope that it will be useful, but WITHOUT ANY
    00010 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
    00011 PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    00012
    00013 You should have received a copy of the GNU Lesser General Public License along
    00014 with this library; if not, write to the Free Software Foundation, Inc., 59
    00015 Temple Place, Suite 330, Boston, MA 02111-1307 USA
    00016
    00017 Contact: http://eodev.sourceforge.net
    00018          todos@geneura.ugr.es, http://geneura.ugr.es
    00019          Marc.Schoenauer@polytechnique.fr
    00020          mak@dhi.dk
    00021  */
    00022
    00023
    00024 #ifndef _eoEsChromInit_H
    00025 #define _eoEsChromInit_H
    00026
    00027 #include <cmath>
    00028 #include <vector>
    00029
    00030 #include <es/eoRealInitBounded.h>
    00031 #include <es/eoEsSimple.h>
    00032 #include <es/eoEsStdev.h>
    00033 #include <es/eoEsFull.h>
    00034
    00035 #ifndef M_PI
    00036 #define M_PI 3.1415926535897932384626433832795
    00037 #endif
    00038
    00054 template <class EOT>
    00055 class eoEsChromInit : public eoRealInitBounded<EOT>
    00056 {
    00057 public:
    00058
    00059     using eoRealInitBounded<EOT>::size;
    00060     using eoRealInitBounded<EOT>::theBounds;
    00061
    00062     typedef typename EOT::Fitness FitT;
    00063
    00071     eoEsChromInit(eoRealVectorBounds& _bounds, double _sigma = 0.3, bool _to_scale=false)
    00072         : eoRealInitBounded<EOT>(_bounds)
    00073         {
    00074             // a bit of pre-computations, to save time later (even if some are useless)
    00075             //
    00076             // first, in the case of one unique sigma
    00077             // sigma is scaled by the average range (if that means anything!)
    00078             if (_to_scale)
    00079             {
    00080                 double scaleUnique = 0;
    00081                 for (unsigned i=0; i<size(); i++)
    00082                     scaleUnique += theBounds().range(i);
    00083                 scaleUnique /= size();
    00084                 uniqueSigma = _sigma * scaleUnique;
    00085             }
    00086             else
    00087                 uniqueSigma = _sigma;
    00088             // now the case of a vector of sigmas first allocate space according
    00089             // to the size of the bounds (see eoRealInitBounded)
    00090             vecSigma.resize(size());
    00091             // each sigma is scaled by the range of the corresponding variable
    00092             for(unsigned i=0; i<size(); i++)
    00093                 if(_to_scale)
    00094                     vecSigma[i] = _sigma * theBounds().range(i);
    00095                 else
    00096                     vecSigma[i] = _sigma;
    00097         }
    00098
    00099
    00109     eoEsChromInit(eoRealVectorBounds& _bounds, std::vector<double> _vecSigma)
    00110         : eoRealInitBounded<EOT>(_bounds), uniqueSigma(_vecSigma[0]), vecSigma(_vecSigma)
    00111         {}
    00112
    00113
    00114     void operator()(EOT& _eo)
    00115         {
    00116             eoRealInitBounded<EOT>::operator()(_eo);
    00117             create_self_adapt(_eo);
    00118             _eo.invalidate();
    00119         }
    00120
    00121
    00122 private:
    00123
    00128     void create_self_adapt(eoReal<FitT>&)
    00129         {}
    00130
    00131
    00132
    00139     void create_self_adapt(eoEsSimple<FitT>& result)
    00140         {
    00141             // pre-computed in the Ctor
    00142             result.stdev = uniqueSigma;
    00143         }
    00144
    00145
    00146
    00155     void create_self_adapt(eoEsStdev<FitT>& result)
    00156         {
    00157             // pre-computed in the constructor
    00158             result.stdevs = vecSigma;
    00159         }
    00160
    00161
    00162
    00169     void create_self_adapt(eoEsFull<FitT>& result)
    00170         {
    00171             // first the stdevs (pre-computed in the Ctor)
    00172             result.stdevs = vecSigma;
    00173             unsigned int theSize = size();
    00174             // nb of rotation angles: N*(N-1)/2 (in general!)
    00175             result.correlations.resize(theSize*(theSize - 1) / 2);
    00176             for (unsigned i=0; i<result.correlations.size(); ++i)
    00177             {
    00178                 // uniform in [-PI, PI)
    00179                 result.correlations[i] = rng.uniform(2 * M_PI) - M_PI;
    00180             }
    00181         }
    00182
    00183
    00184
    00186     double uniqueSigma;
    00187
    00189     std::vector<double> vecSigma;
    00190 };
    00191
    00192 #endif
    00193
    00194
    00195
    00196 // Local Variables:
    00197 // coding: iso-8859-1
    00198 // mode:C++
    00199 // c-file-style: "Stroustrup"
    00200 // comment-column: 35
    00201 // fill-column: 80
    00202 // End: