Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
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/*! \class TMVA::ConvergenceTest
29\ingroup TMVA
30
31Check for convergence.
32
33*/
35#include "TMath.h"
36
37////////////////////////////////////////////////////////////////////////////////
38/// constructor
39
41 : fCurrentValue( 0 ),
42 fImprovement( 0 ),
43 fSteps( 0 ),
44 fCounter( -1 ),
45 fConvValue( FLT_MAX ),
46 fMaxCounter( 0 ),
47 fBestResult( FLT_MAX ),
48 fLastResult( FLT_MAX )
49{
50}
51
52////////////////////////////////////////////////////////////////////////////////
53/// destructor
54
56{
57}
58
59////////////////////////////////////////////////////////////////////////////////
60/// gives back true if the last "steps" steps have lead to an improvement of the
61/// "fitness" of the "individuals" of at least "improvement"
62///
63/// this gives a simple measure of if the estimator of the MLP is
64/// converging and no major improvement is to be expected.
65
67{
68 if( fSteps < 0 || fImprovement < 0 ) return kFALSE;
69
70 if (fCounter < 0) {
71 fConvValue = fCurrentValue;
72 }
73 Float_t improvement = 0;
74 if( withinConvergenceBand )
75 improvement = TMath::Abs(fCurrentValue - fConvValue);
76 else
77 improvement = fConvValue - fCurrentValue;
78 if ( improvement <= fImprovement || fSteps<0) {
79 fCounter ++;
80 } else {
81 fCounter = 0;
82 fConvValue = fCurrentValue;
83 }
84 if (fCounter < fSteps) return kFALSE;
85 return kTRUE;
86}
87
88////////////////////////////////////////////////////////////////////////////////
89/// returns a float from 0 (just started) to 1 (finished)
90
92{
93 if( fCounter > fMaxCounter )
94 fMaxCounter = fCounter;
95 return Float_t(fMaxCounter)/Float_t(fSteps);
96}
97
98
99////////////////////////////////////////////////////////////////////////////////
100/// this function provides the ability to change the learning rate according to
101/// the success of the last generations.
102///
103/// Parameters:
104///
105/// - int ofSteps : = if OF the number of STEPS given in this variable (ofSteps) the
106/// rate of improvement has to be calculated
107///
108/// using this function one can increase the stepSize of the mutation when we have
109/// good success (to pass fast through the easy phase-space) and reduce the learning rate
110/// if we are in a difficult "territory" of the phase-space.
111
113{
114 // < is valid for "less" comparison (for minimization)
115 if ( fBestResult > fLastResult || fSuccessList.size() <=0 ) {
116 fLastResult = fBestResult;
117 fSuccessList.push_front( 1 ); // it got better
118 } else {
119 fSuccessList.push_front( 0 ); // it stayed the same
120 }
121 while( ofSteps <= fSuccessList.size() ) // remove the older entries in the success-list
122 fSuccessList.erase( fSuccessList.begin() );
123 Int_t n = 0;
124 Int_t sum = 0;
125 std::deque<Short_t>::iterator vec = fSuccessList.begin();
126 for (; vec != fSuccessList.end() ; ++vec) {
127 sum += *vec;
128 n++;
129 }
130
131 return n ? sum/Float_t(n) : 0;
132}
float Float_t
Definition RtypesCore.h:57
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
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)
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 Int_t n
Definition legend1.C:16
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.
Definition TMathBase.h:123
static uint64_t sum(uint64_t i)
Definition Factory.cxx:2345