Logo ROOT   6.08/07
Reference Guide
GeneticRange.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Peter Speckmayer
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : TMVA::GeneticRange *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Peter Speckmayer <speckmay@mail.cern.ch> - CERN, Switzerland *
15  * *
16  * Copyright (c) 2005: *
17  * CERN, Switzerland *
18  * MPI-K Heidelberg, Germany *
19  * *
20  * Redistribution and use in source and binary forms, with or without *
21  * modification, are permitted according to the terms listed in LICENSE *
22  * (http://tmva.sourceforge.net/LICENSE) *
23  * *
24  * File and Version Information: *
25  **********************************************************************************/
26 
27 //_______________________________________________________________________
28 //
29 // Range definition for genetic algorithm
30 //_______________________________________________________________________
31 
32 #include "TRandom3.h"
33 
34 #include "TMVA/GeneticRange.h"
35 #include "TMVA/Interval.h"
36 
38 
39 ////////////////////////////////////////////////////////////////////////////////
40 /// defines the "f" (from) and "t" (to) of the coefficient
41 /// and takes a randomgenerator
42 ///
43 
45 {
46  fInterval = interval;
47 
48  fFrom = fInterval->GetMin();
49  fTo = fInterval->GetMax();
50  fNbins= fInterval->GetNbins();
51  fTotalLength = fTo-fFrom;
52 
53  fRandomGenerator = rnd;
54 }
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// creates a new random value for the coefficient; returns a discrete value
58 ///
59 
61 {
62  Double_t value = fRandomGenerator->Uniform(0, 1);
63  return fInterval->GetElement( Int_t(value*fNbins) );
64 }
65 
66 ////////////////////////////////////////////////////////////////////////////////
67 /// creates a new random value for the coefficient
68 /// Parameters:
69 /// Bool_t near : takes a random value near the current value
70 /// double value : this is the current value
71 /// double spread : the sigma of the gaussian which is taken to calculate the new value
72 /// Bool_t mirror : if the new value would be outside of the range, mirror = false
73 /// maps the value between the constraints by periodic boundary conditions.
74 /// With mirror = true, the value gets "reflected" on the boundaries.
75 ///
76 
78 {
79  if (fInterval->GetNbins() > 0) { // discrete interval
80  return RandomDiscrete();
81  }
82  else if (fFrom == fTo) {
83  return fFrom;
84  }
85  else if (near) {
86  Double_t ret;
87  ret = fRandomGenerator->Gaus( value, fTotalLength*spread );
88  if (mirror ) return ReMapMirror( ret );
89  else return ReMap( ret );
90  }
92 }
93 
94 ////////////////////////////////////////////////////////////////////////////////
95 /// remapping the value to the allowed space
96 ///
97 
99 {
100  if (fFrom >= fTo ) return val;
101  if (val < fFrom ) return ReMap( (val-fFrom) + fTo );
102  if (val >= fTo ) return ReMap( (val-fTo) + fFrom );
103  return val;
104 }
105 
106 ////////////////////////////////////////////////////////////////////////////////
107 /// remapping the value to the allowed space by reflecting on the
108 /// boundaries
109 
111 {
112  if (fFrom >= fTo ) return val;
113  if (val < fFrom ) return ReMap( fFrom - (val-fFrom) );
114  if (val >= fTo ) return ReMap( fTo - (val-fTo) );
115  return val;
116 }
117 
118 ////////////////////////////////////////////////////////////////////////////////
119 /// destructor
120 
122 {
123 }
124 
Random number generator class based on M.
Definition: TRandom3.h:29
TRandom3 * fRandomGenerator
Definition: GeneticRange.h:73
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition: TRandom.cxx:235
virtual Double_t GetElement(Int_t position) const
calculates the value of the "number" bin in a discrete interval.
Definition: Interval.cxx:122
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
Double_t ReMapMirror(Double_t val)
remapping the value to the allowed space by reflecting on the boundaries
Double_t Random(Bool_t near=kFALSE, Double_t value=0, Double_t spread=0.1, Bool_t mirror=kFALSE)
creates a new random value for the coefficient Parameters: Bool_t near : takes a random value near th...
virtual Int_t GetNbins() const
Definition: Interval.h:76
Double_t ReMap(Double_t val)
remapping the value to the allowed space
virtual ~GeneticRange()
destructor
#define ClassImp(name)
Definition: Rtypes.h:279
double Double_t
Definition: RtypesCore.h:55
virtual Double_t Uniform(Double_t x1=1)
Returns a uniform deviate on the interval (0, x1).
Definition: TRandom.cxx:606
Double_t fTotalLength
Definition: GeneticRange.h:64
Abstract ClassifierFactory template that handles arbitrary types.
Interval * fInterval
Definition: GeneticRange.h:63
Double_t RandomDiscrete()
creates a new random value for the coefficient; returns a discrete value