1 : |
agomez |
1 |
#include "optinfo.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "gadget.h" |
4 : |
|
|
#include "global.h" |
5 : |
|
|
|
6 : |
|
|
OptInfoHooke::OptInfoHooke()
|
7 : |
|
|
: OptInfo(), hookeiter(1000), rho(0.5), lambda(0.0), hookeeps(1e-4), bndcheck(0.9999) {
|
8 : |
|
|
type = OPTHOOKE;
|
9 : |
|
|
handle.logMessage(LOGMESSAGE, "Initialising Hooke & Jeeves optimisation algorithm");
|
10 : |
|
|
}
|
11 : |
|
|
|
12 : |
|
|
void OptInfoHooke::read(CommentStream& infile, char* text) {
|
13 : |
|
|
handle.logMessage(LOGMESSAGE, "Reading Hooke & Jeeves optimisation parameters");
|
14 : |
|
|
|
15 : |
|
|
int count = 0;
|
16 : |
agomez |
20 |
while (!infile.eof() && strcasecmp(text,"[pso]") && strcasecmp(text, "[simann]") && strcasecmp(text, "[hooke]") && strcasecmp(text, "[bfgs]")) {
|
17 : |
agomez |
1 |
infile >> ws;
|
18 : |
|
|
if (strcasecmp(text, "seed") == 0) {
|
19 : |
|
|
int seed = 0;
|
20 : |
|
|
infile >> seed >> ws;
|
21 : |
|
|
handle.logMessage(LOGMESSAGE, "Initialising random number generator with", seed);
|
22 : |
|
|
srand(seed);
|
23 : |
|
|
|
24 : |
|
|
} else if (strcasecmp(text, "rho") == 0) {
|
25 : |
|
|
infile >> rho;
|
26 : |
|
|
count++;
|
27 : |
|
|
|
28 : |
|
|
} else if (strcasecmp(text, "lambda") == 0) {
|
29 : |
|
|
infile >> lambda;
|
30 : |
|
|
count++;
|
31 : |
|
|
|
32 : |
|
|
} else if (strcasecmp(text, "hookeeps") == 0) {
|
33 : |
|
|
infile >> hookeeps;
|
34 : |
|
|
count++;
|
35 : |
|
|
|
36 : |
|
|
} else if (strcasecmp(text, "hookeiter") == 0) {
|
37 : |
|
|
infile >> hookeiter;
|
38 : |
|
|
count++;
|
39 : |
|
|
|
40 : |
|
|
} else if (strcasecmp(text, "bndcheck") == 0) {
|
41 : |
|
|
infile >> bndcheck;
|
42 : |
|
|
count++;
|
43 : |
|
|
|
44 : |
|
|
} else {
|
45 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text);
|
46 : |
|
|
infile >> text; //read and ignore the next entry
|
47 : |
|
|
}
|
48 : |
|
|
infile >> text;
|
49 : |
|
|
}
|
50 : |
|
|
|
51 : |
|
|
if (count == 0)
|
52 : |
|
|
handle.logMessage(LOGINFO, "Warning - no parameters specified for Hooke & Jeeves optimisation algorithm");
|
53 : |
|
|
|
54 : |
|
|
//check the values specified in the optinfo file ...
|
55 : |
|
|
if ((rho < rathersmall) || (rho > 1.0)) {
|
56 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of rho outside bounds", rho);
|
57 : |
|
|
rho = 0.5;
|
58 : |
|
|
}
|
59 : |
|
|
if ((lambda < 0.0) || (lambda > 1.0)) {
|
60 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of lambda outside bounds", lambda);
|
61 : |
|
|
lambda = rho;
|
62 : |
|
|
}
|
63 : |
|
|
if ((bndcheck < 0.5) || (bndcheck > 1.0)) {
|
64 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of bndcheck outside bounds", bndcheck);
|
65 : |
|
|
bndcheck = 0.9999;
|
66 : |
|
|
}
|
67 : |
|
|
if (hookeeps < rathersmall) {
|
68 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of hookeeps outside bounds", hookeeps);
|
69 : |
|
|
hookeeps = 1e-4;
|
70 : |
|
|
}
|
71 : |
|
|
}
|
72 : |
|
|
|
73 : |
|
|
void OptInfoHooke::Print(ofstream& outfile, int prec) {
|
74 : |
|
|
outfile << "; Hooke & Jeeves algorithm ran for " << iters
|
75 : |
|
|
<< " function evaluations\n; and stopped when the likelihood value was "
|
76 : |
|
|
<< setprecision(prec) << score;
|
77 : |
|
|
if (converge == -1)
|
78 : |
|
|
outfile << "\n; because an error occured during the optimisation\n";
|
79 : |
|
|
else if (converge == 1)
|
80 : |
|
|
outfile << "\n; because the convergence criteria were met\n";
|
81 : |
|
|
else
|
82 : |
|
|
outfile << "\n; because the maximum number of function evaluations was reached\n";
|
83 : |
|
|
}
|