Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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 * *
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 * (see tmva/doc/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
39
40////////////////////////////////////////////////////////////////////////////////
41/// defines the "f" (from) and "t" (to) of the coefficient
42/// and takes a randomgenerator
43
55
56////////////////////////////////////////////////////////////////////////////////
57/// creates a new random value for the coefficient; returns a discrete value
58
60{
61 Double_t value = fRandomGenerator->Uniform(0, 1);
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
76{
77 if (fInterval->GetNbins() > 0) { // discrete interval
78 return RandomDiscrete();
79 }
80 else if (fFrom == fTo) {
81 return fFrom;
82 }
83 else if (near) {
85 ret = fRandomGenerator->Gaus( value, fTotalLength*spread );
86 if (mirror ) return ReMapMirror( ret );
87 else return ReMap( ret );
88 }
89 return fRandomGenerator->Uniform(fFrom, fTo);
90}
91
92////////////////////////////////////////////////////////////////////////////////
93/// remapping the value to the allowed space
94
96{
97 if (fFrom >= fTo ) return val;
98 if (val < fFrom ) return ReMap( (val-fFrom) + fTo );
99 if (val >= fTo ) return ReMap( (val-fTo) + fFrom );
100 return val;
101}
102
103////////////////////////////////////////////////////////////////////////////////
104/// remapping the value to the allowed space by reflecting on the boundaries
105
107{
108 if (fFrom >= fTo ) return val;
109 if (val < fFrom ) return ReMap( fFrom - (val-fFrom) );
110 if (val >= fTo ) return ReMap( fTo - (val-fTo) );
111 return val;
112}
113
114////////////////////////////////////////////////////////////////////////////////
115/// destructor
116
120
int Int_t
Signed integer 4 bytes (int)
Definition RtypesCore.h:59
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
virtual ~GeneticRange()
destructor
Double_t fTotalLength
the distance between the lower and upper constraints
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
holds the complete information of the interval
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
the randomGenerator for calculating the new values
Double_t fTo
the constraints of the coefficient
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