ROOT logo
// @(#)root/tmva $Id: GeneticPopulation.h 31574 2009-12-05 18:23:21Z stelzer $    
// Author: Peter Speckmayer

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : GeneticPopulation                                                     *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *    Population definition for genetic algorithm                                 *
 *                                                                                *
 * Authors (alphabetical):                                                        *
 *      Peter Speckmayer <speckmay@mail.cern.ch>  - CERN, Switzerland             *
 *                                                                                *
 * Copyright (c) 2005:                                                            *
 *      CERN, Switzerland                                                         * 
 *      MPI-K Heidelberg, Germany                                                 * 
 *                                                                                *
 * Redistribution and use in source and binary forms, with or without             *
 * modification, are permitted according to the terms listed in LICENSE           *
 * (http://tmva.sourceforge.net/LICENSE)                                          *
 **********************************************************************************/

#ifndef ROOT_TMVA_GeneticPopulation
#define ROOT_TMVA_GeneticPopulation

//////////////////////////////////////////////////////////////////////////
//                                                                      //
// GeneticPopulation                                                    //
//                                                                      //
// Population definition for genetic algorithm                          //
//                                                                      //
//////////////////////////////////////////////////////////////////////////

#include <string>
#include <vector>

#ifndef ROOT_Riosfwd
#include "Riosfwd.h"
#endif
#ifndef ROOT_TMVA_GeneticGenes
#include "TMVA/GeneticGenes.h"
#endif
#ifndef ROOT_TMVA_Interval
#include "TMVA/Interval.h"
#endif
#ifndef ROOT_TMVA_GeneticRange
#include "TMVA/GeneticRange.h"
#endif

class TH1F;

namespace TMVA {

   class MsgLogger;

   class GeneticPopulation {

   public:

      GeneticPopulation(const std::vector<TMVA::Interval*>& ranges, Int_t size, UInt_t seed = 0);
      virtual ~GeneticPopulation();

      void SetRandomSeed( UInt_t seed = 0);

      void MakeChildren();
      void Mutate( Double_t probability = 20, Int_t startIndex = 0, Bool_t near = kFALSE, 
                   Double_t spread = 0.1, Bool_t mirror = kFALSE  );

      GeneticGenes* GetGenes( Int_t index );
      Int_t         GetPopulationSize() const { return fGenePool.size(); }
      Double_t      GetFitness() const { return fGenePool.size()>0? fGenePool[0].GetFitness() : 0; }

      const std::vector<TMVA::GeneticGenes>& GetGenePool() const { return fGenePool; }
      const std::vector<TMVA::GeneticRange*>& GetRanges() const { return fRanges; }

      std::vector<TMVA::GeneticGenes>&  GetGenePool() { return fGenePool; }
      std::vector<TMVA::GeneticRange*>& GetRanges()   { return fRanges; }

      void Print( Int_t untilIndex = -1 );
      void Print( ostream & out, Int_t utilIndex = -1 );

      TH1F* VariableDistribution( Int_t varNumber, Int_t bins, Int_t min, Int_t max  );
      std::vector< Double_t > VariableDistribution( Int_t varNumber );

      // To keep compatibility: These methods might be reimplemented
      // or just eliminated later on. They are used by the
      // GeneticFitter class.
     
      void MakeCopies( int number );
      void NextGeneration() {}
      void AddPopulation( GeneticPopulation *strangers );
      void AddPopulation( GeneticPopulation &strangers );
      void TrimPopulation();
      void GiveHint( std::vector< Double_t >& hint, Double_t fitness = 0 );
      void Sort();

   private:
      GeneticGenes MakeSex( GeneticGenes male, GeneticGenes female );
  
   private:

      std::vector<TMVA::GeneticGenes>  fGenePool;    // the "genePool" where the individuals of the current generation are stored
      std::vector<TMVA::GeneticRange*> fRanges;      // contains the ranges inbetween the values of the coefficients have to be

      TRandom3*fRandomGenerator;    // random Generator for this population

      mutable MsgLogger* fLogger;   // message logger
      MsgLogger& Log() const { return *fLogger; }    

      Int_t fPopulationSizeLimit;

      ClassDef(GeneticPopulation,0) //Population definition for genetic algorithm
   };

} // namespace TMVA

#endif
 GeneticPopulation.h:1
 GeneticPopulation.h:2
 GeneticPopulation.h:3
 GeneticPopulation.h:4
 GeneticPopulation.h:5
 GeneticPopulation.h:6
 GeneticPopulation.h:7
 GeneticPopulation.h:8
 GeneticPopulation.h:9
 GeneticPopulation.h:10
 GeneticPopulation.h:11
 GeneticPopulation.h:12
 GeneticPopulation.h:13
 GeneticPopulation.h:14
 GeneticPopulation.h:15
 GeneticPopulation.h:16
 GeneticPopulation.h:17
 GeneticPopulation.h:18
 GeneticPopulation.h:19
 GeneticPopulation.h:20
 GeneticPopulation.h:21
 GeneticPopulation.h:22
 GeneticPopulation.h:23
 GeneticPopulation.h:24
 GeneticPopulation.h:25
 GeneticPopulation.h:26
 GeneticPopulation.h:27
 GeneticPopulation.h:28
 GeneticPopulation.h:29
 GeneticPopulation.h:30
 GeneticPopulation.h:31
 GeneticPopulation.h:32
 GeneticPopulation.h:33
 GeneticPopulation.h:34
 GeneticPopulation.h:35
 GeneticPopulation.h:36
 GeneticPopulation.h:37
 GeneticPopulation.h:38
 GeneticPopulation.h:39
 GeneticPopulation.h:40
 GeneticPopulation.h:41
 GeneticPopulation.h:42
 GeneticPopulation.h:43
 GeneticPopulation.h:44
 GeneticPopulation.h:45
 GeneticPopulation.h:46
 GeneticPopulation.h:47
 GeneticPopulation.h:48
 GeneticPopulation.h:49
 GeneticPopulation.h:50
 GeneticPopulation.h:51
 GeneticPopulation.h:52
 GeneticPopulation.h:53
 GeneticPopulation.h:54
 GeneticPopulation.h:55
 GeneticPopulation.h:56
 GeneticPopulation.h:57
 GeneticPopulation.h:58
 GeneticPopulation.h:59
 GeneticPopulation.h:60
 GeneticPopulation.h:61
 GeneticPopulation.h:62
 GeneticPopulation.h:63
 GeneticPopulation.h:64
 GeneticPopulation.h:65
 GeneticPopulation.h:66
 GeneticPopulation.h:67
 GeneticPopulation.h:68
 GeneticPopulation.h:69
 GeneticPopulation.h:70
 GeneticPopulation.h:71
 GeneticPopulation.h:72
 GeneticPopulation.h:73
 GeneticPopulation.h:74
 GeneticPopulation.h:75
 GeneticPopulation.h:76
 GeneticPopulation.h:77
 GeneticPopulation.h:78
 GeneticPopulation.h:79
 GeneticPopulation.h:80
 GeneticPopulation.h:81
 GeneticPopulation.h:82
 GeneticPopulation.h:83
 GeneticPopulation.h:84
 GeneticPopulation.h:85
 GeneticPopulation.h:86
 GeneticPopulation.h:87
 GeneticPopulation.h:88
 GeneticPopulation.h:89
 GeneticPopulation.h:90
 GeneticPopulation.h:91
 GeneticPopulation.h:92
 GeneticPopulation.h:93
 GeneticPopulation.h:94
 GeneticPopulation.h:95
 GeneticPopulation.h:96
 GeneticPopulation.h:97
 GeneticPopulation.h:98
 GeneticPopulation.h:99
 GeneticPopulation.h:100
 GeneticPopulation.h:101
 GeneticPopulation.h:102
 GeneticPopulation.h:103
 GeneticPopulation.h:104
 GeneticPopulation.h:105
 GeneticPopulation.h:106
 GeneticPopulation.h:107
 GeneticPopulation.h:108
 GeneticPopulation.h:109
 GeneticPopulation.h:110
 GeneticPopulation.h:111
 GeneticPopulation.h:112
 GeneticPopulation.h:113
 GeneticPopulation.h:114
 GeneticPopulation.h:115
 GeneticPopulation.h:116
 GeneticPopulation.h:117
 GeneticPopulation.h:118
 GeneticPopulation.h:119