1 : |
agomez |
1 |
#include "optinfo.h" |
2 : |
|
|
#include "errorhandler.h" |
3 : |
|
|
#include "gadget.h" |
4 : |
|
|
#include "global.h" |
5 : |
|
|
|
6 : |
|
|
OptInfoSimann::OptInfoSimann()
|
7 : |
|
|
: OptInfo(), rt(0.85), simanneps(1e-4), ns(5), nt(2), t(100.0), cs(2.0),
|
8 : |
|
|
vminit(1.0), simanniter(2000), uratio(0.7), lratio(0.3), tempcheck(4), scale(0) {
|
9 : |
|
|
type = OPTSIMANN;
|
10 : |
|
|
handle.logMessage(LOGMESSAGE, "Initialising Simulated Annealing optimisation algorithm");
|
11 : |
|
|
}
|
12 : |
|
|
|
13 : |
|
|
void OptInfoSimann::read(CommentStream& infile, char* text) {
|
14 : |
|
|
handle.logMessage(LOGMESSAGE, "Reading Simulated Annealing optimisation parameters");
|
15 : |
|
|
|
16 : |
|
|
int count = 0;
|
17 : |
|
|
while (!infile.eof() && strcasecmp(text, "[simann]") && strcasecmp(text, "[hooke]") && strcasecmp(text, "[bfgs]")) {
|
18 : |
|
|
infile >> ws;
|
19 : |
|
|
if (strcasecmp(text, "seed") == 0) {
|
20 : |
|
|
int seed = 0;
|
21 : |
|
|
infile >> seed >> ws;
|
22 : |
|
|
handle.logMessage(LOGMESSAGE, "Initialising random number generator with", seed);
|
23 : |
|
|
srand(seed);
|
24 : |
|
|
|
25 : |
|
|
} else if (strcasecmp(text, "simanniter") == 0) {
|
26 : |
|
|
infile >> simanniter;
|
27 : |
|
|
count++;
|
28 : |
|
|
|
29 : |
|
|
} else if (strcasecmp(text, "t") == 0) {
|
30 : |
|
|
infile >> t;
|
31 : |
|
|
count++;
|
32 : |
|
|
|
33 : |
|
|
} else if (strcasecmp(text, "rt") == 0) {
|
34 : |
|
|
infile >> rt;
|
35 : |
|
|
count++;
|
36 : |
|
|
|
37 : |
|
|
} else if (strcasecmp(text, "simanneps") == 0) {
|
38 : |
|
|
infile >> simanneps;
|
39 : |
|
|
count++;
|
40 : |
|
|
|
41 : |
|
|
} else if (strcasecmp(text, "nt") == 0) {
|
42 : |
|
|
infile >> nt;
|
43 : |
|
|
count++;
|
44 : |
|
|
|
45 : |
|
|
} else if (strcasecmp(text, "ns") == 0) {
|
46 : |
|
|
infile >> ns;
|
47 : |
|
|
count++;
|
48 : |
|
|
|
49 : |
|
|
} else if (strcasecmp(text, "vm") == 0) {
|
50 : |
|
|
infile >> vminit;
|
51 : |
|
|
count++;
|
52 : |
|
|
|
53 : |
|
|
} else if (strcasecmp(text, "cstep") == 0) {
|
54 : |
|
|
infile >> cs;
|
55 : |
|
|
count++;
|
56 : |
|
|
|
57 : |
|
|
} else if (strcasecmp(text, "check") == 0) {
|
58 : |
|
|
infile >> tempcheck;
|
59 : |
|
|
count++;
|
60 : |
|
|
|
61 : |
|
|
} else if (strcasecmp(text, "uratio") == 0) {
|
62 : |
|
|
infile >> uratio;
|
63 : |
|
|
count++;
|
64 : |
|
|
|
65 : |
|
|
} else if (strcasecmp(text, "lratio") == 0) {
|
66 : |
|
|
infile >> lratio;
|
67 : |
|
|
count++;
|
68 : |
|
|
|
69 : |
|
|
} else if (strcasecmp(text, "scale") == 0) {
|
70 : |
|
|
infile >> scale;
|
71 : |
|
|
count++;
|
72 : |
|
|
|
73 : |
|
|
} else {
|
74 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text);
|
75 : |
|
|
infile >> text; //read and ignore the next entry
|
76 : |
|
|
}
|
77 : |
|
|
infile >> text;
|
78 : |
|
|
}
|
79 : |
|
|
|
80 : |
|
|
if (count == 0)
|
81 : |
|
|
handle.logMessage(LOGINFO, "Warning - no parameters specified for Simulated Annealing optimisation algorithm");
|
82 : |
|
|
|
83 : |
|
|
//check the values specified in the optinfo file ...
|
84 : |
|
|
if ((uratio < 0.5) || (uratio > 1.0)) {
|
85 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of uratio outside bounds", uratio);
|
86 : |
|
|
uratio = 0.7;
|
87 : |
|
|
}
|
88 : |
|
|
if ((lratio < rathersmall) || (lratio > 0.5)) {
|
89 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of lratio outside bounds", lratio);
|
90 : |
|
|
lratio = 0.3;
|
91 : |
|
|
}
|
92 : |
|
|
if ((rt < rathersmall) || (rt > 1.0)) {
|
93 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of rt outside bounds", rt);
|
94 : |
|
|
rt = 0.85;
|
95 : |
|
|
}
|
96 : |
|
|
if (t < rathersmall) {
|
97 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of t outside bounds", t);
|
98 : |
|
|
t = 100.0;
|
99 : |
|
|
}
|
100 : |
|
|
if (nt < 1) {
|
101 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of nt outside bounds", nt);
|
102 : |
|
|
nt = 2;
|
103 : |
|
|
}
|
104 : |
|
|
if (ns < 1) {
|
105 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of ns outside bounds", ns);
|
106 : |
|
|
ns = 5;
|
107 : |
|
|
}
|
108 : |
|
|
if (tempcheck < 1) {
|
109 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of check outside bounds", tempcheck);
|
110 : |
|
|
tempcheck = 4;
|
111 : |
|
|
}
|
112 : |
|
|
if (vminit < rathersmall) {
|
113 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of vm outside bounds", vminit);
|
114 : |
|
|
vminit = 1.0;
|
115 : |
|
|
}
|
116 : |
|
|
if (cs < rathersmall) {
|
117 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of cstep outside bounds", cs);
|
118 : |
|
|
cs = 2.0;
|
119 : |
|
|
}
|
120 : |
|
|
if (simanneps < rathersmall) {
|
121 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of simanneps outside bounds", simanneps);
|
122 : |
|
|
simanneps = 1e-4;
|
123 : |
|
|
}
|
124 : |
|
|
if (scale != 0 && scale != 1) {
|
125 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of scale outside bounds", scale);
|
126 : |
|
|
scale = 0;
|
127 : |
|
|
}
|
128 : |
|
|
}
|
129 : |
|
|
|
130 : |
|
|
void OptInfoSimann::Print(ofstream& outfile, int prec) {
|
131 : |
|
|
outfile << "; Simulated Annealing algorithm ran for " << iters
|
132 : |
|
|
<< " function evaluations\n; and stopped when the likelihood value was "
|
133 : |
|
|
<< setprecision(prec) << score;
|
134 : |
|
|
if (converge == -1)
|
135 : |
|
|
outfile << "\n; because an error occured during the optimisation\n";
|
136 : |
|
|
else if (converge == 1)
|
137 : |
|
|
outfile << "\n; because the convergence criteria were met\n";
|
138 : |
|
|
else
|
139 : |
|
|
outfile << "\n; because the maximum number of function evaluations was reached\n";
|
140 : |
|
|
}
|