ROOT  6.06/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 //_______________________________________________________________________
28 //
29 // Range definition for genetic algorithm
30 //_______________________________________________________________________
31 
32 #include "TRandom3.h"
33 
34 #include "TMVA/GeneticRange.h"
35 
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// defines the "f" (from) and "t" (to) of the coefficient
40 /// and takes a randomgenerator
41 ///
42 
43 TMVA::GeneticRange::GeneticRange( TRandom3*rnd, Interval *interval )
44 {
45  fInterval = interval;
46 
47  fFrom = fInterval->GetMin();
48  fTo = fInterval->GetMax();
49  fNbins= fInterval->GetNbins();
50  fTotalLength = fTo-fFrom;
51 
52  fRandomGenerator = rnd;
53 }
54 
55 ////////////////////////////////////////////////////////////////////////////////
56 /// creates a new random value for the coefficient; returns a discrete value
57 ///
58 
60 {
62  return fInterval->GetElement( Int_t(value*fNbins) );
63 }
64 
65 ////////////////////////////////////////////////////////////////////////////////
66 /// creates a new random value for the coefficient
67 /// Parameters:
68 /// Bool_t near : takes a random value near the current value
69 /// double value : this is the current value
70 /// double spread : the sigma of the gaussian which is taken to calculate the new value
71 /// Bool_t mirror : if the new value would be outside of the range, mirror = false
72 /// maps the value between the constraints by periodic boundary conditions.
73 /// With mirror = true, the value gets "reflected" on the boundaries.
74 ///
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  }
90  return fRandomGenerator->Uniform(fFrom, fTo);
91 }
92 
93 ////////////////////////////////////////////////////////////////////////////////
94 /// remapping the value to the allowed space
95 ///
96 
98 {
99  if (fFrom >= fTo ) return val;
100  if (val < fFrom ) return ReMap( (val-fFrom) + fTo );
101  if (val >= fTo ) return ReMap( (val-fTo) + fFrom );
102  return val;
103 }
104 
105 ////////////////////////////////////////////////////////////////////////////////
106 /// remapping the value to the allowed space by reflecting on the
107 /// boundaries
108 
110 {
111  if (fFrom >= fTo ) return val;
112  if (val < fFrom ) return ReMap( fFrom - (val-fFrom) );
113  if (val >= fTo ) return ReMap( fTo - (val-fTo) );
114  return val;
115 }
116 
117 ////////////////////////////////////////////////////////////////////////////////
118 /// destructor
119 
121 {
122 }
123 
Random number generator class based on M.
Definition: TRandom3.h:29
TRandom3 * fRandomGenerator
Definition: GeneticRange.h:73
ClassImp(TMVA::GeneticRange) TMVA
defines the "f" (from) and "t" (to) of the coefficient and takes a randomgenerator ...
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
virtual Double_t GetElement(Int_t position) const
calculates the value of the "number" bin in a discrete interval.
Definition: Interval.cxx:121
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...
Double_t ReMap(Double_t val)
remapping the value to the allowed space
virtual ~GeneticRange()
destructor
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
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
float value
Definition: math.cpp:443