EvolvingObjects
|
00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- 00002 00003 //----------------------------------------------------------------------------- 00004 // make_PBILupdate.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 _make_PBILupdate_h 00027 #define _make_PBILupdate_h 00028 00029 #include <ga/eoPBILOrg.h> 00030 #include <utils/eoRNG.h> 00031 #include <utils/eoParser.h> 00032 #include <utils/eoState.h> 00033 00034 00036 00047 template <class EOT> 00048 eoDistribUpdater<EOT> & do_make_PBILupdate(eoParser & _parser, eoState& _state, EOT) 00049 { 00050 // ast the moment, a single update rule is available 00051 // but at some point we'll have to choose among different rules 00052 00053 std::string UType = _parser.createParam(std::string("PBIL"), "updateRule", "Type of update rule (only PBIL additive at the moment)", 'U', "Algorithm").value(); 00054 00055 unsigned nbBest = _parser.createParam(unsigned(1), "nbBest", "Number of good guys to update from", 'B', "Algorithm").value(); 00056 double LRBest = _parser.createParam(0.1, "LRBest", "Learning Rate (from best guys)", 'L', "Algorithm").value(); 00057 unsigned nbWorst = _parser.createParam(unsigned(0), "nbWorst", "Number of bad guys to update from", 'W', "Algorithm").value(); 00058 double LRWorst = _parser.createParam(0.01, "LRWorst", "Learning Rate (from best guys)", 'L', "Algorithm").value(); 00059 double tolerance = _parser.createParam(0.0, "tolerance", "Keeping away from 0 and 1", 't', "Algorithm").value(); 00060 00061 // a pointer to choose among several possible types 00062 eoDistribUpdater<EOT> * ptUpdate; 00063 00064 if (UType == std::string("PBIL")) 00065 { 00066 if ( (nbWorst == 0) && (nbBest == 1) ) 00067 ptUpdate = new eoPBILOrg<EOT>(LRBest, tolerance); 00068 else 00069 ptUpdate = new eoPBILAdditive<EOT>(LRBest, nbBest, tolerance, LRWorst, nbWorst); 00070 } 00071 else 00072 throw std::runtime_error("Only PBIL additive update rule available at the moment"); 00073 00074 // done: don't forget to store the allocated pointers 00075 _state.storeFunctor(ptUpdate); 00076 return *ptUpdate; 00077 } 00078 00079 #endif