GAPopulation.H

Go to the documentation of this file.
00001 /*!@file GA/GAPopulation.H A population class for genetic algorithm. */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/GA/GAPopulation.H $
00035 // $Id: GAPopulation.H 6003 2005-11-29 17:22:45Z rjpeters $
00036 //
00037 
00038 #ifndef GAPOPULTAION_H
00039 #define GAPOPULTAION_H
00040 
00041 #include "GA/GAChromosome.H"
00042 
00043 #include <iosfwd>
00044 
00045 //! Population class for genetic algorithm
00046 /*! This is a population class for genetic algorithm. It's a size N
00047     array of chromosomes, and their potential offspring and comes with
00048     various method to handle them. */
00049 
00050 class GAPopulation
00051 {
00052   friend std::istream& operator>> (std::istream& in, GAPopulation& pop);
00053 
00054   friend std::ostream& operator<< (std::ostream& out, GAPopulation& pop);
00055 
00056 public:
00057 
00058   // ############################################################
00059   /*! @name Constructor and destructor */
00060   //@{
00061 
00062   //! Uninitialized constructor. Need to call resize() later.
00063   GAPopulation();
00064 
00065   //! Construct a size N-population of random chromosomes of size a.
00066   GAPopulation(const int N, const int a);
00067 
00068   //! Change sizes, do not initialize.
00069   void resize(const int N, const int a);
00070 
00071   //! Initialize with N random chromosomes of size a.
00072   void init(const int N, const int a);
00073 
00074   //! Destructor
00075   ~GAPopulation();
00076 
00077   //@}
00078 
00079   // ############################################################
00080   /*! @name Access functions */
00081   //@{
00082 
00083   //! Set the chromosome #i to c.
00084   void set_chromosome(const int i, const GAChromosome& c);
00085 
00086   //! Return the chromosome #i.
00087   GAChromosome get_chromosome(const int i) const;
00088 
00089   //! Return the mean fitness.
00090   float get_mean_fitness() const;
00091 
00092   //! Return the standard deviation.
00093   float get_sigma() const;
00094 
00095   //@}
00096 
00097   // ############################################################
00098   /*! @name Evolution functions */
00099   //@{
00100 
00101   //! The offspring become the new generation.
00102   void update();
00103 
00104   //! Compute the mean and total fitness of the chromosomes.
00105   void compute_pop_fitness();
00106 
00107   //! Compute the standard deviation of the chromosomes' fitness.
00108   void compute_sigma();
00109 
00110   //! Apply a linear scaling to the chromosomes' fitness.
00111   void linear_scaling();
00112 
00113   //! Select chromosomes for breeding.
00114   void selection();
00115 
00116   //! Breed chromosomes to produce the offspring.
00117   void crossover();
00118 
00119   //! Mutate the offspring with probability 1/size.
00120   void mutate();
00121 
00122   //@}
00123 
00124 private:
00125   int psize;
00126   int csize;
00127   float total_fitness;
00128   float total_linear_fitness;
00129   float mean_fitness;
00130   float sigma;
00131   GAChromosome *chromosomes;
00132   GAChromosome *offspring;
00133 };
00134 
00135 //! << overloading.
00136 std::istream& operator<< (std::istream& in, GAPopulation& pop);
00137 
00138 //! >> overloading.
00139 std::ostream& operator>> (std::ostream& out, GAPopulation& pop);
00140 
00141 #endif
00142 
00143 // ######################################################################
00144 /* So things look consistent in everyone's emacs... */
00145 /* Local Variables: */
00146 /* indent-tabs-mode: nil */
00147 /* End: */
Generated on Sun May 8 08:40:39 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3