<commit_before>// @(#)root/tmva $Id$    
// Author: <NAME>

/**********************************************************************************
 * 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):                                                        *
 *      <NAME> <<EMAIL>>  - 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>
#include <map>

#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
#ifndef ROOT_TMVA_MsgLogger
#include "TMVA/MsgLogger.h"
#endif

class TH1F;

namespace TMVA {

   class GeneticPopulation {

   public:

      GeneticPopulation();
      virtual ~GeneticPopulation();

      typedef std::pair<const Double_t, GeneticGenes > entry;
      
      void SetRandomSeed( UInt_t seed = 0);

      void CreatePopulation( Int_t size );
      void AddPopulation( GeneticPopulation *genePool );
      void AddPopulation( GeneticPopulation &genePool );
      void TrimPopulation();
      void GiveHint( std::vector< Double_t >& hint, Double_t fitness = 0 );
      void MakeChildren();
      void MakeCopies( int number );
      GeneticGenes MakeSex( GeneticGenes male, GeneticGenes female );

      void MakeMutants( Double_t probability = 30, Bool_t near = kFALSE, 
                        Double_t spread = 0.1, Bool_t mirror = kFALSE  );
      void Mutate( Double_t probability = 20, Int_t startIndex = 0, Bool_t near = kFALSE, 
                   Double_t spread = 0.1, Bool_t mirror = kFALSE  );
      GeneticGenes Mutate(  GeneticGenes individual, Double_t probability, Bool_t near,      
                            Double_t spread, Bool_t mirror );
      
      void NextGeneration();
      
      void AddFactor( Interval *interval );

      GeneticGenes* GetGenes();
      GeneticGenes* GetGenes( Int_t index );

      void     ClearResults( );
      void     Reset();
      Bool_t   SetFitness( GeneticGenes *g, Double_t fitness, Bool_t add = kTRUE );
      Double_t GetFitness( Int_t index );
      Double_t GetFitness( );

      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 );

      Double_t GetCounterFitness() const { return fCounterFitness; }
      Int_t    GetPopulationSize() const { return fPopulationSize; }

      std::multimap<Double_t, GeneticGenes>* GetGenePool()    const { return fGenePool; }
      std::multimap<Double_t, GeneticGenes>* GetNewGenePool() const { return fNewGenePool; }
      std::vector<TMVA::GeneticRange*>&      GetRanges()            { return fRanges; }
  
   private:

      Double_t fCounterFitness;                            // internal use
      Int_t    fPopulationSize;                            // population size      

      std::multimap<Double_t, GeneticGenes>* fGenePool;    // the "genePool" where the individuals of the current generation are stored
      std::multimap<Double_t, GeneticGenes>* fNewGenePool; // the genePool where the offspring individuals are stored<commit_msg>From Leo, Diego, Axel, Paul and Philippe:<commit_after>// @(#)root/tmva $Id$    
// Author: <NAME>

/**********************************************************************************
 * 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):                                                        *
 *      <NAME> <<EMAIL>>  - 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>
#include <map>

#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
#ifndef ROOT_TMVA_MsgLogger
#include "TMVA/MsgLogger.h"
#endif

class TH1F;

namespace TMVA {

   class GeneticPopulation {

   public:

      GeneticPopulation();
      virtual ~GeneticPopulation();

      typedef std::pair<const Double_t, GeneticGenes > entry;
      
      void SetRandomSeed( UInt_t seed = 0);

      void CreatePopulation( Int_t size );
      void AddPopulation( GeneticPopulation *genePool );
      void AddPopulation( GeneticPopulation &genePool );
      void TrimPopulation();
      void GiveHint( std::vector< Double_t >& hint, Double_t fitness = 0 );
      void MakeChildren();
      void MakeCopies( int number );
      GeneticGenes MakeSex( GeneticGenes male, GeneticGenes female );

      void MakeMutants( Double_t probability = 30, Bool_t near = kFALSE, 
                        Double_t spread = 0.1, Bool_t mirror = kFALSE  );
      void Mutate( Double_t probability = 20, Int_t startIndex = 0, Bool_t near = kFALSE, 
                   Double_t spread = 0.1, Bool_t mirror = kFALSE  );
      GeneticGenes Mutate(  GeneticGenes individual, Double_t probability, Bool_t near,      
                            Double_t spread, Bool_t mirror );
      
      void NextGeneration();
      
      void AddFactor( Interval *interval );

      GeneticGenes* GetGenes();
      GeneticGenes* GetGenes( Int_t index );

      void     ClearResults( );
      void     Reset();
      Bool_t   SetFitness( GeneticGenes *g, Double_t fitness, Bool_t add = kTRUE );
      Double_t GetFitness( Int_t index );
      Double_t GetFitness( );

      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 );

      Double_t GetCounterFitness() const { return fCounterFitness; }
      Int_t    GetPopulationSize() const { return fPopulationSize; }

      std::multimap<Double_t, TMVA::GeneticGenes>* GetGenePool()    const { return fGenePool; }
      std::multimap<Double_t, TMVA::GeneticGenes>* GetNewGenePool() const { return fNewGenePool; }
      std::vector<TMVA::GeneticRange*>&      GetRanges()            { return fRanges; }
  
   private:

      Double_t fCounterFitness;                            // internal use
      Int_t    fPopulationSize;                            // population size      

      std::multimap<Double_t, GeneticGenes>* fGenePool;    // the "genePool" where the individuals of the current generation are stored
      std::multimap<Double_t, GeneticGenes>* fNewGenePool; // the genePool where the offspring individuals are stored
{'fraction_non_alphanumeric': 0.13068289899182042, 'fraction_numerical': 0.0036142286475175957, 'mean_word_length': 1.294348679903993, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 78, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4796563', 'n_tokens_mistral': 2500, 'n_tokens_neox': 2291, 'n_words': 631}