source: trunk/MagicSoft/Mars/mtools/MSimulatedAnnealing.h@ 4308

Last change on this file since 4308 was 2817, checked in by gaug, 21 years ago
*** empty log message ***
File size: 4.1 KB
Line 
1#ifndef MARS_MSimulatedAnnealing
2#define MARS_MSimulatedAnnealing
3
4#ifndef MARS_MAGIC
5#include "MAGIC.h"
6#endif
7
8#ifndef ROOT_TMatrix
9#include <TMatrix.h>
10#endif
11
12class MHSimulatedAnnealing;
13class TRandom;
14
15class MSimulatedAnnealing : public TObject
16{
17private:
18
19 static const Float_t gsYtryStr; // Fixed high value to keep the simplex inside the borders
20 static const Float_t gsYtryCon; // Fixed high value to keep the simplex inside the borders
21 static const Int_t gsMaxDim; // Fixed maximum number of dimensions
22 static const Int_t gsMaxStep; // Fixed maximum number of loops with temperature=0
23
24 MHSimulatedAnnealing *fResult; //! The histogram output container
25
26 TRandom *fRandom; // The random number generator -> random numbers between 0 and 1
27
28 Real_t fTolerance; // The convergence break condition
29
30 UShort_t fNdim; // The number of parameters
31 UShort_t fMpts; // The number of simplex points (=fNdim+1)
32
33 UShort_t fNumberOfMoves; // The total number of moves (== CPU time)
34
35 Real_t fStartTemperature; // The start temperature -> will slowly get decreased to 0
36
37 Bool_t fFullStorage; // kTRUE -> the whole simplex gets stored in MHSimlutedAnnealing
38 Bool_t fInit; // kTRUE -> initialization was succesful
39
40 TMatrix fP; // The (ndim+1,ndim) matrix containing the simplex
41
42 TVector fPsum; // The sum of each point of the simplex
43
44 TVector fP0; // The boundary conditions on the weak side
45 TVector fP1; // The boundary conditions on the strong side
46 TVector fY; // The array containing the function evaluation results
47
48 Real_t fYb; // The best function evaluation value ever found
49 Real_t fYconv; // The function evaluation value at the convergence point
50
51 TVector fPb; // The parameters belonging to fYb
52 TVector fPconv; // The parameters belonging to fYconv
53
54 Int_t Amebsa(Int_t iter,
55 const Real_t temp); // The function deciding if the simplex has to get reflected, expanded or contracted
56
57 Real_t Amotsa(const Float_t fac,
58 const UShort_t ihi,
59 Real_t &yhi,
60 const Real_t temp); // The function reflecting, expanding and contracting the simplex: fac=-1 -> reflection, fac=0.5 -> contraction, fac=2.0 -> expansion
61
62 void GetPsum();
63
64protected:
65
66 virtual Float_t FunctionToMinimize(const TVector &arr); // The optimization function
67
68public:
69 enum BorderFlag_t { kENoBorder, kEStrictBorder, kEContractBorder };
70 enum Verbosity_t { kEDefault, kEVerbose, kEDebug };
71
72private:
73 BorderFlag_t fBorder;
74 Verbosity_t fVerbose;
75
76public:
77 MSimulatedAnnealing();
78 virtual ~MSimulatedAnnealing();
79
80 void ModifyTolerance(Float_t tol) { fTolerance = tol; }
81 void ModifyBorderFlag(BorderFlag_t border) { fBorder = border; }
82
83 Bool_t Initialize(const TMatrix &p, const TVector &y,
84 const TVector &p0, const TVector &p1);
85
86 void SetNumberOfMoves(UShort_t moves) { fNumberOfMoves = moves; }
87 void SetStartTemperature(Float_t temp) { fStartTemperature = temp; }
88 void SetFullStorage() { fFullStorage = kTRUE; }
89 void SetVerbosityLevel(Verbosity_t level) { fVerbose = level; }
90 void SetRandom(TRandom *rand) { fRandom = rand; }
91
92 const TVector &GetPb() const { return fPb; }
93 Float_t GetYb() const { return fYb; }
94
95 const TVector &GetPconv() const { return fPconv; }
96 Float_t GetYconv() const { return fYconv; }
97
98
99 MHSimulatedAnnealing *GetResult() { return fResult; }
100
101 Bool_t RunMinimization();
102
103 ClassDef(MSimulatedAnnealing,1) // Class to perform a Simulated Annealing Minimization
104};
105
106#endif
Note: See TracBrowser for help on using the repository browser.