Logo ROOT   6.18/05
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
30Range 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
50 fTo = fInterval->GetMax();
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 }
90 return fRandomGenerator->Uniform(fFrom, fTo);
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
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
double Double_t
Definition: RtypesCore.h:55
#define ClassImp(name)
Definition: Rtypes.h:365
Range definition for genetic algorithm.
Definition: GeneticRange.h:42
virtual ~GeneticRange()
destructor
Double_t fTotalLength
Definition: GeneticRange.h:62
GeneticRange(TRandom3 *rnd, Interval *interval)
defines the "f" (from) and "t" (to) of the coefficient and takes a randomgenerator
Double_t ReMap(Double_t val)
remapping the value to the allowed space
Interval * fInterval
Definition: GeneticRange.h:61
Double_t RandomDiscrete()
creates a new random value for the coefficient; returns a discrete value
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:
Double_t ReMapMirror(Double_t val)
remapping the value to the allowed space by reflecting on the boundaries
TRandom3 * fRandomGenerator
Definition: GeneticRange.h:71
The TMVA::Interval Class.
Definition: Interval.h:61
virtual Double_t GetMin() const
Definition: Interval.h:71
virtual Double_t GetMax() const
Definition: Interval.h:72
virtual Int_t GetNbins() const
Definition: Interval.h:74
Random number generator class based on M.
Definition: TRandom3.h:27