Logo ROOT   6.10/09
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 /*! \class TMVA::GeneticRange
28 \ingroup TMVA
29 
30 Range definition for genetic algorithm.
31 
32 */
33 
34 #include "TRandom3.h"
35 
36 #include "TMVA/GeneticRange.h"
37 #include "TMVA/Interval.h"
38 
40 
41 ////////////////////////////////////////////////////////////////////////////////
42 /// defines the "f" (from) and "t" (to) of the coefficient
43 /// and takes a randomgenerator
44 
46 {
47  fInterval = interval;
48 
49  fFrom = fInterval->GetMin();
50  fTo = fInterval->GetMax();
51  fNbins= fInterval->GetNbins();
52  fTotalLength = fTo-fFrom;
53 
54  fRandomGenerator = rnd;
55 }
56 
57 ////////////////////////////////////////////////////////////////////////////////
58 /// creates a new random value for the coefficient; returns a discrete value
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 
77 {
78  if (fInterval->GetNbins() > 0) { // discrete interval
79  return RandomDiscrete();
80  }
81  else if (fFrom == fTo) {
82  return fFrom;
83  }
84  else if (near) {
85  Double_t ret;
86  ret = fRandomGenerator->Gaus( value, fTotalLength*spread );
87  if (mirror ) return ReMapMirror( ret );
88  else return ReMap( ret );
89  }
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// remapping the value to the allowed space
95 
97 {
98  if (fFrom >= fTo ) return val;
99  if (val < fFrom ) return ReMap( (val-fFrom) + fTo );
100  if (val >= fTo ) return ReMap( (val-fTo) + fFrom );
101  return val;
102 }
103 
104 ////////////////////////////////////////////////////////////////////////////////
105 /// remapping the value to the allowed space by reflecting on the boundaries
106 
108 {
109  if (fFrom >= fTo ) return val;
110  if (val < fFrom ) return ReMap( fFrom - (val-fFrom) );
111  if (val >= fTo ) return ReMap( fTo - (val-fTo) );
112  return val;
113 }
114 
115 ////////////////////////////////////////////////////////////////////////////////
116 /// destructor
117 
119 {
120 }
121 
Random number generator class based on M.
Definition: TRandom3.h:27
TRandom3 * fRandomGenerator
Definition: GeneticRange.h:71
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:120
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:
virtual Int_t GetNbins() const
Definition: Interval.h:74
The TMVA::Interval Class.
Definition: Interval.h:61
Double_t ReMap(Double_t val)
remapping the value to the allowed space
virtual ~GeneticRange()
destructor
#define ClassImp(name)
Definition: Rtypes.h:336
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:62
Abstract ClassifierFactory template that handles arbitrary types.
Interval * fInterval
Definition: GeneticRange.h:61
Double_t RandomDiscrete()
creates a new random value for the coefficient; returns a discrete value
Range definition for genetic algorithm.
Definition: GeneticRange.h:42