SimulatedAnnealing.h

Go to the documentation of this file.
00001 // @(#)root/tmva $Id: SimulatedAnnealing.h 31574 2009-12-05 18:23:21Z stelzer $   
00002 // Author: Andreas Hoecker, Joerg Stelzer, Helge Voss, Krzysztof Danielowski, Kamil Kraszewski, Maciej Kruk
00003 
00004 /**********************************************************************************
00005  * Project: TMVA - a Root-integrated toolkit for multivariate data analysis       *
00006  * Package: TMVA                                                                  *
00007  * Class  : SimulatedAnnealing                                                    *
00008  * Web    : http://tmva.sourceforge.net                                           *
00009  *                                                                                *
00010  * Description:                                                                   *
00011  *      Implementation of simulated annealing fitting procedure                   *
00012  *                                                                                *
00013  * Authors (alphabetical):                                                        *
00014  *      Krzysztof Danielowski <danielow@cern.ch>       - IFJ & AGH, Poland        *
00015  *      Kamil Kraszewski      <kalq@cern.ch>           - IFJ & UJ, Poland         *
00016  *      Maciej Kruk           <mkruk@cern.ch>          - IFJ & AGH, Poland        *
00017  *                                                                                *
00018  * Copyright (c) 2008:                                                            *
00019  *      IFJ-Krakow, Poland                                                        *
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 #ifndef ROOT_TMVA_SimulatedAnnealing
00029 #define ROOT_TMVA_SimulatedAnnealing
00030 
00031 //////////////////////////////////////////////////////////////////////////
00032 //                                                                      //
00033 // SimulatedAnnealing                                                   //
00034 //                                                                      //
00035 // Base implementation of simulated annealing fitting procedure         //
00036 //                                                                      //
00037 //////////////////////////////////////////////////////////////////////////
00038 
00039 #include <vector>
00040 #include <list>
00041 
00042 #ifndef ROOT_TMVA_Types
00043 #include "TMVA/Types.h"
00044 #endif
00045 
00046 class TRandom;
00047 
00048 namespace TMVA {
00049 
00050    class IFitterTarget;
00051    class Interval;
00052    class MsgLogger;
00053 
00054    class SimulatedAnnealing {
00055 
00056    public:
00057 
00058       SimulatedAnnealing( IFitterTarget& target, const std::vector<TMVA::Interval*>& ranges );
00059       virtual ~SimulatedAnnealing();
00060 
00061       // returns FCN value at minimum
00062       Double_t Minimize( std::vector<Double_t>& parameters );
00063 
00064       // accessors
00065       void SetMaxCalls          ( Int_t    mc    ) { fMaxCalls = mc; }
00066       void SetInitTemp          ( Double_t it    ) { fInitialTemperature = it; }
00067       void SetMinTemp           ( Double_t min   ) { fMinTemperature = min; }
00068       void SetAccuracy          ( Double_t eps   ) { fEps = eps; }
00069       void SetTemperatureScale  ( Double_t scale ) { fTemperatureScale = scale; }
00070       void SetAdaptiveSpeed     ( Double_t speed ) { fAdaptiveSpeed = speed; }
00071 
00072       void SetOptions( Int_t maxCalls, Double_t initialTemperature, Double_t minTemperature, Double_t eps,
00073                        TString  kernelTemperatureS, Double_t temperatureScale, Double_t adaptiveSpeed, 
00074                        Double_t temperatureAdaptiveStep, Bool_t useDefaultScale, Bool_t useDefaultTemperature );
00075 
00076 
00077    private:
00078 
00079       enum EKernelTemperature {
00080          kSqrt = 0,
00081          kIncreasingAdaptive,
00082          kDecreasingAdaptive,
00083          kLog,
00084          kHomo,
00085          kSin,
00086          kGeo
00087       } fKernelTemperature;
00088 
00089       void FillWithRandomValues( std::vector<Double_t>& parameters );
00090       void ReWriteParameters( std::vector<Double_t>& from, std::vector<Double_t>& to );
00091       void GenerateNewTemperature(Double_t& currentTemperature, Int_t Iter );
00092       void GenerateNeighbour( std::vector<Double_t>& parameters, std::vector<Double_t>& oldParameters, Double_t currentTemperature );
00093       Bool_t ShouldGoIn( Double_t currentFit, Double_t localFit, Double_t currentTemperature );
00094       void SetDefaultScale();
00095       Double_t GenerateMaxTemperature( std::vector<Double_t>& parameters );
00096       std::vector<Double_t> GenerateNeighbour( std::vector<Double_t>& parameters, Double_t currentTemperature );
00097 
00098       IFitterTarget&                fFitterTarget;           // the fitter target
00099       TRandom*                      fRandom;                 // random generator
00100       const std::vector<TMVA::Interval*>& fRanges;                 // parameter ranges
00101 
00102       // fitter setup 
00103       Int_t                         fMaxCalls;               // maximum number of minimisation calls
00104       Double_t                      fInitialTemperature;     // initial temperature
00105       Double_t                      fMinTemperature;         // mimimum temperature
00106       Double_t                      fEps;                    // epsilon
00107       Double_t                      fTemperatureScale;       // how fast temperature change
00108       Double_t                      fAdaptiveSpeed;          // how fast temperature change in adaptive (in adaptive two variables describe
00109                                                              // the change of temperature, but fAdaptiveSpeed should be 1.0 and its not 
00110                                                              // recomended to change it)
00111       Double_t                      fTemperatureAdaptiveStep;// used to calculate InitialTemperature if fUseDefaultTemperature
00112 
00113       Bool_t                        fUseDefaultScale;        // if TRUE, SA calculates its own TemperatureScale
00114       Bool_t                        fUseDefaultTemperature;  // if TRUE, SA calculates its own InitialTemperature (MinTemperautre)
00115 
00116       mutable MsgLogger*            fLogger;   // message logger
00117       MsgLogger& Log() const { return *fLogger; }
00118 
00119       Double_t fProgress;
00120 
00121       ClassDef(SimulatedAnnealing,0)  // Base class for Simulated Annealing fitting
00122    };
00123 
00124 } // namespace TMVA
00125 
00126 #endif
00127 

Generated on Tue Jul 5 14:27:38 2011 for ROOT_528-00b_version by  doxygen 1.5.1