ConvergenceTest.cxx

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: ConvergenceTest.cxx 29122 2009-06-22 06:51:30Z brun $
00002 // Author: Andreas Hoecker, Peter Speckmayer, Joerg Stelzer, Helge Voss
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : ConvergenceTest                                                             *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Implementation (see header for description)                               *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Andreas Hoecker <Andreas.Hocker@cern.ch> - CERN, Switzerland              *
00015  *      Peter Speckmayer <Peter.Speckmayer@cern.ch>  - CERN, Switzerland          *
00016  *      Joerg Stelzer   <Joerg.Stelzer@cern.ch>  - CERN, Switzerland              *
00017  *      Helge Voss      <Helge.Voss@cern.ch>     - MPI-K Heidelberg, Germany      *
00018  *                                                                                *
00019  * Copyright (c) 2006:                                                            *
00020  *      CERN, Switzerland                                                         *
00021  *      MPI-K Heidelberg, Germany                                                 *
00022  *                                                                                *
00023  * Redistribution and use in source and binary forms, with or without             *
00024  * modification, are permitted according to the terms listed in LICENSE           *
00025  * (http://tmva.sourceforge.net/LICENSE)                                          *
00026  **********************************************************************************/
00027 
00028 #include "TMVA/ConvergenceTest.h"
00029 #include "TMath.h"
00030 
00031 
00032 //_______________________________________________________________________
00033 TMVA::ConvergenceTest::ConvergenceTest() 
00034    : fCurrentValue( 0 ),
00035      fImprovement( 0 ),
00036      fSteps( 0 ),
00037      fCounter( -1 ),
00038      fConvValue( FLT_MAX ),
00039      fMaxCounter( 0 ),
00040      fBestResult( FLT_MAX ),
00041      fLastResult( FLT_MAX )
00042 {
00043    // constructor
00044 }
00045 
00046 //_______________________________________________________________________
00047 TMVA::ConvergenceTest::~ConvergenceTest() 
00048 {
00049    // destructor
00050 }
00051 
00052 
00053 
00054 //_______________________________________________________________________
00055 Bool_t TMVA::ConvergenceTest::HasConverged( Bool_t withinConvergenceBand )
00056 {
00057    // gives back true if the last "steps" steps have lead to an improvement of the
00058    // "fitness" of the "individuals" of at least "improvement"
00059    // 
00060    // this gives a simple measure of if the estimator of the MLP is
00061    // converging and no major improvement is to be expected. 
00062    //
00063    if( fSteps < 0 || fImprovement < 0 ) return kFALSE;
00064 
00065    if (fCounter < 0) {
00066       fConvValue = fCurrentValue;
00067    }
00068    Float_t improvement = 0; 
00069    if( withinConvergenceBand )
00070       improvement = TMath::Abs(fCurrentValue - fConvValue);
00071    else
00072       improvement = fConvValue - fCurrentValue;
00073    if ( improvement <= fImprovement || fSteps<0) {
00074       fCounter ++;
00075    } else {
00076       fCounter = 0;
00077       fConvValue = fCurrentValue;
00078    }
00079    if (fCounter < fSteps) return kFALSE;
00080    return kTRUE;
00081 }
00082 
00083 //_______________________________________________________________________
00084 Float_t TMVA::ConvergenceTest::Progress()
00085 {
00086    // returns a float from 0 (just started) to 1 (finished)
00087    if( fCounter > fMaxCounter ) 
00088       fMaxCounter = fCounter; 
00089    return Float_t(fMaxCounter)/Float_t(fSteps);  
00090 }
00091 
00092 
00093 //_______________________________________________________________________
00094 Float_t TMVA::ConvergenceTest::SpeedControl( UInt_t ofSteps )
00095 {
00096    // this function provides the ability to change the learning rate according to
00097    // the success of the last generations. 
00098    // 
00099    // Parameters:
00100    //      int ofSteps :  = if OF the number of STEPS given in this variable (ofSteps) the 
00101    //                       rate of improvement has to be calculated
00102    //
00103    // using this function one can increase the stepSize of the mutation when we have 
00104    // good success (to pass fast through the easy phase-space) and reduce the learning rate
00105    // if we are in a difficult "territory" of the phase-space. 
00106    //
00107 
00108    // < is valid for "less" comparison (for minimiztions)
00109    if ( fBestResult > fLastResult || fSuccessList.size() <=0 ) { 
00110       fLastResult = fBestResult;
00111       fSuccessList.push_front( 1 ); // it got better
00112    } else {
00113       fSuccessList.push_front( 0 ); // it stayed the same
00114    }
00115    while( ofSteps <= fSuccessList.size() ) // remove the older entries in the success-list
00116       fSuccessList.erase( fSuccessList.begin() );
00117    Int_t n = 0;
00118    Int_t sum = 0;
00119    std::deque<Short_t>::iterator vec = fSuccessList.begin();
00120    for (; vec<fSuccessList.end() ; vec++) {
00121       sum += *vec;
00122       n++;
00123    }
00124 
00125    return sum/Float_t(n);
00126 }

Generated on Tue Jul 5 15:16:42 2011 for ROOT_528-00b_version by  doxygen 1.5.1