EvolvingObjects
|
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 //----------------------------------------------------------------------------- 00004 // eoPBILOrg.h 00005 // (c) Marc Schoenauer, Maarten Keijzer, 2001 00006 /* 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00020 00021 Contact: Marc.Schoenauer@polytechnique.fr 00022 mkeijzer@dhi.dk 00023 */ 00024 //----------------------------------------------------------------------------- 00025 00026 #ifndef _eoPBILOrg_H 00027 #define _eoPBILOrg_H 00028 00029 #include <eoDistribUpdater.h> 00030 #include <ga/eoPBILDistrib.h> 00031 00041 template <class EOT> 00042 class eoPBILOrg : public eoDistribUpdater<EOT> 00043 { 00044 public: 00046 eoPBILOrg(double _LR, double _tolerance=0.0 ) : 00047 LR(_LR), maxBound(1.0-_tolerance), minBound(_tolerance) 00048 {} 00049 00050 00052 virtual void operator()(eoDistribution<EOT> & _distrib, eoPop<EOT>& _pop) 00053 { 00054 const EOT & best = _pop.best_element(); 00055 eoPBILDistrib<EOT>& distrib = dynamic_cast<eoPBILDistrib<EOT>&>(_distrib); 00056 00057 std::vector<double> & p = distrib.value(); 00058 00059 for (unsigned g=0; g<distrib.size(); g++) 00060 { 00061 // double & r = value()[g]; 00062 p[g] *= (1-LR); 00063 if ( best[g] ) 00064 p[g] += LR; 00065 // else nothing 00066 00067 // stay away from 0 and 1 00068 p[g] = std::min(maxBound, p[g]); 00069 p[g] = std::max(minBound, p[g]); 00070 } 00071 } 00072 00073 private: 00074 double LR; // learning rate for best guys 00075 double maxBound, minBound; // proba stay away from 0 and 1 by at least tolerance 00076 }; 00077 00078 #endif