ROOT logo
// @(#)root/tmva $Id: GeneticRange.cxx 29122 2009-06-22 06:51:30Z brun $    
// Author: Peter Speckmayer

/**********************************************************************************
 * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
 * Package: TMVA                                                                  *
 * Class  : TMVA::GeneticRange                                                    *
 * Web    : http://tmva.sourceforge.net                                           *
 *                                                                                *
 * Description:                                                                   *
 *      Implementation (see header for description)                               *
 *                                                                                *
 * 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)                                          *
 *                                                                                *
 * File and Version Information:                                                  *
 **********************************************************************************/

//_______________________________________________________________________
//                                                                      
// Range definition for genetic algorithm                               
//_______________________________________________________________________

#include "TRandom3.h"

#include "TMVA/GeneticRange.h"

ClassImp(TMVA::GeneticRange)

//_______________________________________________________________________
TMVA::GeneticRange::GeneticRange( TRandom3*rnd, Interval *interval )
{
   // defines the "f" (from) and "t" (to) of the coefficient
   // and takes a randomgenerator
   //
   fInterval = interval;
   
   fFrom = fInterval->GetMin();
   fTo   = fInterval->GetMax();
   fNbins= fInterval->GetNbins();
   fTotalLength = fTo-fFrom;

   fRandomGenerator = rnd;
}

//_______________________________________________________________________
Double_t TMVA::GeneticRange::RandomDiscrete()
{
   // creates a new random value for the coefficient; returns a discrete value
   //
   Double_t value = fRandomGenerator->Uniform(0, 1);
   return fInterval->GetElement( Int_t(value*fNbins) );
}

//_______________________________________________________________________
Double_t TMVA::GeneticRange::Random( Bool_t near, Double_t value, Double_t spread, Bool_t mirror )
{
   // creates a new random value for the coefficient
   // Parameters:
   //        Bool_t near     : takes a random value near the current value
   //        double value  : this is the current value
   //        double spread : the sigma of the gaussian which is taken to calculate the new value
   //        Bool_t mirror   : if the new value would be outside of the range, mirror = false
   //                        maps the value between the constraints by periodic boundary conditions.
   //                        With mirror = true, the value gets "reflected" on the boundaries.
   //
   if (fInterval->GetNbins() > 0) {   // discrete interval
       return RandomDiscrete();
   }
   else if (fFrom == fTo) {
      return fFrom;
   }
   else if (near) {
      Double_t ret;
      ret = fRandomGenerator->Gaus( value, fTotalLength*spread );
      if (mirror ) return ReMapMirror( ret );
      else return ReMap( ret );
   }
   return fRandomGenerator->Uniform(fFrom, fTo);
}

//_______________________________________________________________________
Double_t TMVA::GeneticRange::ReMap( Double_t val )
{
   // remapping the value to the allowed space
   //
   if (fFrom >= fTo ) return val;
   if (val < fFrom ) return ReMap( (val-fFrom) + fTo );
   if (val >= fTo )    return ReMap( (val-fTo) + fFrom );
   return val;
}

//_______________________________________________________________________
Double_t TMVA::GeneticRange::ReMapMirror( Double_t val )
{
   // remapping the value to the allowed space by reflecting on the 
   // boundaries
   if (fFrom >= fTo ) return val;
   if (val < fFrom  ) return ReMap( fFrom - (val-fFrom) );
   if (val >= fTo   ) return ReMap( fTo - (val-fTo)  );
   return val;
}

//_______________________________________________________________________
TMVA::GeneticRange::~GeneticRange()
{
   // destructor
}

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