ROOT  6.06/09
Reference Guide
ConvergenceTest.cxx
Go to the documentation of this file.
1 // @(#)root/tmva $Id$
2 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
3 
4 /**********************************************************************************
5  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis *
6  * Package: TMVA *
7  * Class : ConvergenceTest *
8  * Web : http://tmva.sourceforge.net *
9  * *
10  * Description: *
11  * Implementation (see header for description) *
12  * *
13  * Authors (alphabetical): *
14  * Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland *
15  * Peter Speckmayer <Peter.Speckmayer@cern.ch> - CERN, Switzerland *
16  * Joerg Stelzer <Joerg.Stelzer@cern.ch> - CERN, Switzerland *
17  * Helge Voss <Helge.Voss@cern.ch> - MPI-K Heidelberg, Germany *
18  * *
19  * Copyright (c) 2006: *
20  * CERN, Switzerland *
21  * MPI-K Heidelberg, Germany *
22  * *
23  * Redistribution and use in source and binary forms, with or without *
24  * modification, are permitted according to the terms listed in LICENSE *
25  * (http://tmva.sourceforge.net/LICENSE) *
26  **********************************************************************************/
27 
28 #include "TMVA/ConvergenceTest.h"
29 #include "TMath.h"
30 
31 
32 ////////////////////////////////////////////////////////////////////////////////
33 /// constructor
34 
36  : fCurrentValue( 0 ),
37  fImprovement( 0 ),
38  fSteps( 0 ),
39  fCounter( -1 ),
40  fConvValue( FLT_MAX ),
41  fMaxCounter( 0 ),
42  fBestResult( FLT_MAX ),
43  fLastResult( FLT_MAX )
44 {
45 }
46 
47 ////////////////////////////////////////////////////////////////////////////////
48 /// destructor
49 
51 {
52 }
53 
54 
55 
56 ////////////////////////////////////////////////////////////////////////////////
57 /// gives back true if the last "steps" steps have lead to an improvement of the
58 /// "fitness" of the "individuals" of at least "improvement"
59 ///
60 /// this gives a simple measure of if the estimator of the MLP is
61 /// converging and no major improvement is to be expected.
62 ///
63 
65 {
66  if( fSteps < 0 || fImprovement < 0 ) return kFALSE;
67 
68  if (fCounter < 0) {
69  fConvValue = fCurrentValue;
70  }
71  Float_t improvement = 0;
72  if( withinConvergenceBand )
73  improvement = TMath::Abs(fCurrentValue - fConvValue);
74  else
75  improvement = fConvValue - fCurrentValue;
76  if ( improvement <= fImprovement || fSteps<0) {
77  fCounter ++;
78  } else {
79  fCounter = 0;
80  fConvValue = fCurrentValue;
81  }
82  if (fCounter < fSteps) return kFALSE;
83  return kTRUE;
84 }
85 
86 ////////////////////////////////////////////////////////////////////////////////
87 /// returns a float from 0 (just started) to 1 (finished)
88 
90 {
91  if( fCounter > fMaxCounter )
92  fMaxCounter = fCounter;
93  return Float_t(fMaxCounter)/Float_t(fSteps);
94 }
95 
96 
97 ////////////////////////////////////////////////////////////////////////////////
98 /// this function provides the ability to change the learning rate according to
99 /// the success of the last generations.
100 ///
101 /// Parameters:
102 /// int ofSteps : = if OF the number of STEPS given in this variable (ofSteps) the
103 /// rate of improvement has to be calculated
104 ///
105 /// using this function one can increase the stepSize of the mutation when we have
106 /// good success (to pass fast through the easy phase-space) and reduce the learning rate
107 /// if we are in a difficult "territory" of the phase-space.
108 ///
109 
111 {
112  // < is valid for "less" comparison (for minimiztions)
113  if ( fBestResult > fLastResult || fSuccessList.size() <=0 ) {
114  fLastResult = fBestResult;
115  fSuccessList.push_front( 1 ); // it got better
116  } else {
117  fSuccessList.push_front( 0 ); // it stayed the same
118  }
119  while( ofSteps <= fSuccessList.size() ) // remove the older entries in the success-list
120  fSuccessList.erase( fSuccessList.begin() );
121  Int_t n = 0;
122  Int_t sum = 0;
123  std::deque<Short_t>::iterator vec = fSuccessList.begin();
124  for (; vec != fSuccessList.end() ; vec++) {
125  sum += *vec;
126  n++;
127  }
128 
129  return n ? sum/Float_t(n) : 0;
130 }
float Float_t
Definition: RtypesCore.h:53
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
const Bool_t kFALSE
Definition: Rtypes.h:92
Short_t Abs(Short_t d)
Definition: TMathBase.h:110
Bool_t HasConverged(Bool_t withinConvergenceBand=kFALSE)
gives back true if the last "steps" steps have lead to an improvement of the "fitness" of the "indivi...
Float_t Progress()
returns a float from 0 (just started) to 1 (finished)
unsigned int UInt_t
Definition: RtypesCore.h:42
ConvergenceTest()
constructor
~ConvergenceTest()
destructor
Float_t SpeedControl(UInt_t ofSteps)
this function provides the ability to change the learning rate according to the success of the last g...
const Bool_t kTRUE
Definition: Rtypes.h:91
const Int_t n
Definition: legend1.C:16