Log In | Get Help   
Home My Page Projects Code Snippets Project Openings Mareframe
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files
[mareframe] Annotation of /trunk/gadget/optinfo.h
[mareframe] / trunk / gadget / optinfo.h Repository:
ViewVC logotype

Annotation of /trunk/gadget/optinfo.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 11 - (view) (download)

1 : agomez 1 #ifndef optinfo_h
2 :     #define optinfo_h
3 :    
4 :     #include "maininfo.h"
5 :     #include "doublematrix.h"
6 :     #include "doublevector.h"
7 :     #include "intvector.h"
8 : ulcessvp 11 #include "seq_optimize_template.h"
9 : agomez 1
10 :     enum OptType { OPTHOOKE = 1, OPTSIMANN, OPTBFGS };
11 :    
12 :     /**
13 :     * \class OptInfo
14 :     * \brief This is the base class used to perform the optimisation calculation for the model
15 :     *
16 :     * \note This will always be overridden by the derived classes that actually perform the optimisation calculation
17 :     */
18 :     class OptInfo {
19 :     public:
20 :     /**
21 :     * \brief This is the default OptInfo constructor
22 :     */
23 :     OptInfo() { converge = 0; iters = 0; score = 0.0; };
24 :     /**
25 :     * \brief This is the default OptInfo destructor
26 :     */
27 :     ~OptInfo() {};
28 :     /**
29 :     * \brief This is the function used to read in the optimisation parameters
30 :     * \param infile is the CommentStream to read the optimisation parameters from
31 :     * \param text is a text string used to compare parameter names
32 :     */
33 :     virtual void read(CommentStream& infile, char* text) {};
34 :     /**
35 :     * \brief This function will print information from the optimisation algorithm
36 :     * \param outfile is the ofstream that the optimisation information gets sent to
37 :     * \param prec is the precision to use in the output file
38 :     */
39 :     virtual void Print(ofstream& outfile, int prec) {};
40 :     /**
41 :     * \brief This is the function used to call the optimisation algorithms
42 :     */
43 :     virtual void OptimiseLikelihood() {};
44 : ulcessvp 11 //FIXME doc
45 :     virtual void OptimiseLikelihoodOMP() {};
46 :     //FIXME doc
47 :     void setSeed(unsigned* val) {seed = val[0]; seedM = val[1]; seedP = val[2];};
48 : agomez 1 /**
49 :     * \brief This will return the type of optimisation class
50 :     * \return type
51 :     */
52 :     OptType getType() const { return type; };
53 :     protected:
54 :     /**
55 :     * \brief This is the flag used to denote whether the optimisation converged or not
56 :     */
57 :     int converge;
58 :     /**
59 :     * \brief This is the number of iterations that took place during the optimisation
60 :     */
61 :     int iters;
62 :     /**
63 :     * \brief This is the value of the best likelihood score from the optimisation
64 :     */
65 :     double score;
66 :     /**
67 :     * \brief This denotes what type of optimisation class has been created
68 :     */
69 :     OptType type;
70 : ulcessvp 11 //FIXME doc
71 :     unsigned seed;
72 :     unsigned seedM;
73 :     unsigned seedP;
74 : agomez 1 };
75 :    
76 :     /**
77 :     * \class OptInfoHooke
78 :     * \brief This is the class used for the Hooke & Jeeves optimisation
79 :     *
80 :     * The Hooke & Jeeves optimisation is the default optimisation, and is a simple and fast optimising method, but somewhat unreliable, which is often described as a "hill climbing" technique. From the initial starting point the algorithm takes a step in various directions, and conducts a new model run. If the new likelihood score is better than the old one then the algorithm uses the new point as it's best guess. If it is worse then the algorithm retains the old point. The search proceeds in series of these steps, each step slightly smaller than the previous one. When the algorithm finds a point which it cannot improve on with a small step in any direction then it accepts this point as being the "solution", and exits. It is recommended that you re-run the optimisation, using the final point of one run as the start of the next.
81 :     *
82 :     * The Hooke & Jeeves algorithm used in Gadget is derived from that originally presented by R. Hooke and T. A. Jeeves, ''Direct Search Solution of Numerical and Statistical Problems'' in the April 1961 (Vol. 8, pp. 212-229) issue of the Journal of the ACM, with improvements presented by Arthur F Kaupe Jr., ''Algorithm 178: Direct Search'' in the June 1963 (Vol 6, pp.313-314) issue of the Communications of the ACM.
83 :    
84 :     */
85 :     class OptInfoHooke : public OptInfo {
86 :     public:
87 :     /**
88 :     * \brief This is the default OptInfoHooke constructor
89 :     */
90 :     OptInfoHooke();
91 :     /**
92 :     * \brief This is the default OptInfoHooke destructor
93 :     */
94 :     virtual ~OptInfoHooke() {};
95 :     /**
96 :     * \brief This is the function used to read in the Hooke & Jeeves parameters
97 :     * \param infile is the CommentStream to read the optimisation parameters from
98 :     * \param text is a text string used to compare parameter names
99 :     */
100 :     virtual void read(CommentStream& infile, char* text);
101 :     /**
102 :     * \brief This function will print information from the optimisation algorithm
103 :     * \param outfile is the ofstream that the optimisation information gets sent to
104 :     * \param prec is the precision to use in the output file
105 :     */
106 :     virtual void Print(ofstream& outfile, int prec);
107 :     /**
108 :     * \brief This is the function that will calculate the likelihood score using the Hooke & Jeeves optimiser
109 :     */
110 :     virtual void OptimiseLikelihood();
111 : ulcessvp 11 #ifdef GADGET_OPENMP
112 :     //TODO doc
113 :     virtual void OptimiseLikelihoodOMP();
114 :     #endif
115 : agomez 1 private:
116 :     /**
117 :     * \brief This function will calculate the best point that can be found close to the current point
118 :     * \param delta is the DoubleVector of the steps to take when looking for the best point
119 :     * \param point is the DoubleVector that will contain the parameters corresponding to the best function value found from the search
120 :     * \param prevbest is the current best point value
121 :     * \param param is the IntVector containing the order that the parameters should be searched in
122 :     * \return the best function value found from the search
123 :     */
124 :     double bestNearby(DoubleVector& delta, DoubleVector& point, double prevbest, IntVector& param);
125 : ulcessvp 11 //TODO doc
126 :     double bestNearbyOMP(DoubleVector& delta, DoubleVector& point, double prevbest, IntVector& param);
127 :     double bestNearbyOMP2(DoubleVector& delta, DoubleVector& point, double prevbest, IntVector& param);
128 : agomez 1 /**
129 :     * \brief This is the maximum number of iterations for the Hooke & Jeeves optimisation
130 :     */
131 :     int hookeiter;
132 :     /**
133 :     * \brief This is the reduction factor for the step length
134 :     */
135 :     double rho;
136 :     /**
137 :     * \brief This is the initial step length
138 :     */
139 :     double lambda;
140 :     /**
141 :     * \brief This is the minimum step length, use as the halt criteria for the optimisation process
142 :     */
143 :     double hookeeps;
144 :     /**
145 :     * \brief This is the limit when checking if a parameter is stuck on the bound
146 :     */
147 :     double bndcheck;
148 :     };
149 :    
150 :     /**
151 :     * \class OptInfoSimann
152 :     * \brief This is the class used for the Simualted Annealing optimisation
153 :     *
154 :     * Simulated Annealing is a global optimisation method that distinguishes different local optima. Starting from an initial point, the algorithm takes a step and the function is evaluated. When minimizing a function, any downhill step is accepted and the process repeats from this new point. An uphill step may be accepted (thus, it can escape from local optima). This uphill decision is made by the Metropolis criteria. It uses a parameter known as "temperature" and the size of the uphill step in a probabilistic manner, and varying the temperature will affect the number of the uphill moves that are accepted. As the optimisation process proceeds, the length of the steps decline and the algorithm closes in on the global optimum.
155 :     *
156 :     * The Simulated Annealing algorithm used in Gadget is derived from that presented by Corana et al, ''Minimising Multimodal Functions of Continuous Variables with the 'Simulated Annealing' Algorithm'' in the September 1987 (Vol. 13, pp. 262-280) issue of the ACM Transactions on Mathematical Software and Goffe et al, ''Global Optimisation of Statistical Functions with Simulated Annealing'' in the January/February 1994 (Vol. 60, pp. 65-100) issue of the Journal of Econometrics.
157 :     */
158 :     class OptInfoSimann : public OptInfo {
159 :     public:
160 :     /**
161 :     * \brief This is the default OptInfoSimann constructor
162 :     */
163 :     OptInfoSimann();
164 :     /**
165 :     * \brief This is the default OptInfoSimann destructor
166 :     */
167 :     virtual ~OptInfoSimann() {};
168 :     /**
169 :     * \brief This is the function used to read in the Simulated Annealing parameters
170 :     * \param infile is the CommentStream to read the optimisation parameters from
171 :     * \param text is a text string used to compare parameter names
172 :     */
173 :     virtual void read(CommentStream& infile, char* text);
174 :     /**
175 :     * \brief This function will print information from the optimisation algorithm
176 :     * \param outfile is the ofstream that the optimisation information gets sent to
177 :     * \param prec is the precision to use in the output file
178 :     */
179 :     virtual void Print(ofstream& outfile, int prec);
180 :     /**
181 :     * \brief This is the function that will calculate the likelihood score using the Simulated Annealing optimiser
182 :     */
183 :     virtual void OptimiseLikelihood();
184 : ulcessvp 11 //FIXME doc
185 :     #ifdef GADGET_OPENMP
186 :     virtual void OptimiseLikelihoodOMP();
187 :     #endif
188 :     //FIXME doc
189 :     virtual void newValue(int nvars, int l, IntVector& param, DoubleVector& trialx,
190 :     DoubleVector& x, DoubleVector& lowerb, DoubleVector& upperb, DoubleVector& vm);
191 :     // //FIXME doc
192 :     // virtual void buildNewParams_f(Siman& seed, DoubleVector& params);
193 :     // virtual void adjustVm(Siman& seed);
194 :     // virtual void temperature(Siman& seed);
195 : agomez 1 private:
196 :     /**
197 :     * \brief This is the temperature reduction factor
198 :     */
199 :     double rt;
200 :     /**
201 :     * \brief This is the halt criteria for the Simulated Annealing algorithm
202 :     */
203 :     double simanneps;
204 :     /**
205 :     * \brief This is the number of loops before the step length is adjusted
206 :     */
207 :     int ns;
208 :     /**
209 :     * \brief This is the number of loops before the temperature is adjusted
210 :     */
211 :     int nt;
212 :     /**
213 :     * \brief This is the "temperature" used for the Simulated Annealing algorithm
214 :     */
215 :     double t;
216 :     /**
217 :     * \brief This is the factor used to adjust the step length
218 :     */
219 :     double cs;
220 :     /**
221 :     * \brief This is the initial value for the maximum step length
222 :     */
223 :     double vminit;
224 :     /**
225 :     * \brief This is the maximum number of function evaluations for the Simulated Annealing optimiation
226 :     */
227 :     int simanniter;
228 :     /**
229 :     * \brief This is the upper bound when adjusting the step length
230 :     */
231 :     double uratio;
232 :     /**
233 :     * \brief This is the lower bound when adjusting the step length
234 :     */
235 :     double lratio;
236 :     /**
237 :     * \brief This is the number of temperature loops to check when testing for convergence
238 :     */
239 :     int tempcheck;
240 :     /**
241 :     * \brief This is the flag to denote whether the parameters should be scaled or not (default 0, not scale)
242 :     */
243 :     int scale;
244 :     };
245 :    
246 :     /**
247 :     * \class OptInfoBFGS
248 :     * \brief This is the class used for the BFGS optimisation
249 :     *
250 :     * BFGS is a quasi-Newton global optimisation method that uses information about the gradient of the function at the current point to calculate the best direction to look in to find a better point. Using this information, the BFGS algorithm can iteratively calculate a better approximation to the inverse Hessian matrix, which will lead to a better approximation of the minimum value. From an initial starting point, the gradient of the function is calculated and then the algorithm uses this information to calculate the best direction to perform a linesearch for a point that is ''sufficiently better''. The linesearch that is used in Gadget to look for a better point in this direction is the ''Armijo'' linesearch. The algorithm will then adjust the current estimate of the inverse Hessian matrix, and restart from this new point. If a better point cannot be found, then the inverse Hessian matrix is reset and the algorithm restarts from the last accepted point.
251 :     *
252 :     * The BFGS algorithm used in Gadget is derived from that presented by Dimitri P Bertsekas, ''Nonlinear Programming'' (2nd edition, pp22-61) published by Athena Scientific.
253 :     */
254 :     class OptInfoBFGS : public OptInfo {
255 :     public:
256 :     /**
257 :     * \brief This is the default OptInfoBFGS constructor
258 :     */
259 :     OptInfoBFGS();
260 :     /**
261 :     * \brief This is the default OptInfoBFGS destructor
262 :     */
263 :     ~OptInfoBFGS() {};
264 :     /**
265 :     * \brief This is the function used to read in the BFGS parameters
266 :     * \param infile is the CommentStream to read the optimisation parameters from
267 :     * \param text is a text string used to compare parameter names
268 :     */
269 :     virtual void read(CommentStream& infile, char* text);
270 :     /**
271 :     * \brief This function will print information from the optimisation algorithm
272 :     * \param outfile is the ofstream that the optimisation information gets sent to
273 :     * \param prec is the precision to use in the output file
274 :     */
275 :     virtual void Print(ofstream& outfile, int prec);
276 :     /**
277 :     * \brief This is the function that will calculate the likelihood score using the BFGS optimiser
278 :     */
279 :     virtual void OptimiseLikelihood();
280 : ulcessvp 11 //FIXME doc
281 :     #ifdef GADGET_OPENMP
282 :     virtual void OptimiseLikelihoodOMP();
283 :     #endif
284 : agomez 1 private:
285 :     /**
286 :     * \brief This function will numerically calculate the gradient of the function at the current point
287 :     * \param point is the DoubleVector that contains the parameters corresponding to the current function value
288 :     * \param pointvalue is the current function value
289 :     * \param newgrad is the DoubleVector that will contain the gradient vector for the current point
290 :     */
291 :     void gradient(DoubleVector& point, double pointvalue, DoubleVector& newgrad);
292 :     /**
293 :     * \brief This function will calculate the smallest eigenvalue of the inverse Hessian matrix
294 :     * \param M is the DoubleMatrix containing the inverse Hessian matrix
295 :     * \return the smallest eigen value of the matrix
296 :     */
297 :     double getSmallestEigenValue(DoubleMatrix M);
298 :     /**
299 :     * \brief This is the maximum number of function evaluations for the BFGS optimiation
300 :     */
301 :     int bfgsiter;
302 :     /**
303 :     * \brief This is the halt criteria for the BFGS algorithm
304 :     */
305 :     double bfgseps;
306 :     /**
307 :     * \brief This is the adjustment factor in the Armijo linesearch
308 :     */
309 :     double beta;
310 :     /**
311 :     * \brief This is the halt criteria for the Armijo linesearch
312 :     */
313 :     double sigma;
314 :     /**
315 :     * \brief This is the initial step size for the Armijo linesearch
316 :     */
317 :     double step;
318 :     /**
319 :     * \brief This is the accuracy term used when calculating the gradient
320 :     */
321 :     double gradacc;
322 :     /**
323 :     * \brief This is the factor used to adjust the gradient accuracy term
324 :     */
325 :     double gradstep;
326 :     /**
327 :     * \brief This is the halt criteria for the gradient accuracy term
328 :     */
329 :     double gradeps;
330 :     };
331 :    
332 :     #endif

root@forge.cesga.es
ViewVC Help
Powered by ViewVC 1.0.0  

Powered By FusionForge