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 : |
ulcessvp |
11 |
unsigned s1 = 0;
|
17 : |
|
|
unsigned s2 = 0;
|
18 : |
|
|
unsigned s3 = 0;
|
19 : |
|
|
|
20 : |
agomez |
1 |
int count = 0;
|
21 : |
agomez |
20 |
while (!infile.eof() && strcasecmp(text,"[pso]") && strcasecmp(text, "[simann]") && strcasecmp(text, "[hooke]") && strcasecmp(text, "[bfgs]")) {
|
22 : |
agomez |
1 |
infile >> ws;
|
23 : |
|
|
if (strcasecmp(text, "seed") == 0) {
|
24 : |
ulcessvp |
11 |
int s = 0;
|
25 : |
|
|
infile >> s >> ws;
|
26 : |
|
|
s1 = s;
|
27 : |
|
|
handle.logMessage(LOGMESSAGE, "Initialising random number generator with", s);
|
28 : |
|
|
srand(s1);
|
29 : |
ulcessvp |
12 |
// seed for the metropolis acceptance of SA
|
30 : |
ulcessvp |
11 |
} if (strcasecmp(text, "seedM") == 0) {
|
31 : |
|
|
int s = 0;
|
32 : |
|
|
infile >> s >> ws;
|
33 : |
|
|
s2 = s;
|
34 : |
|
|
handle.logMessage(LOGMESSAGE, "Initialising random number generator with", s);
|
35 : |
ulcessvp |
12 |
// seed for the order if the parameters of SA
|
36 : |
ulcessvp |
11 |
} if (strcasecmp(text, "seedP") == 0) {
|
37 : |
|
|
int s = 0;
|
38 : |
|
|
infile >> s >> ws;
|
39 : |
|
|
s3 = s;
|
40 : |
|
|
handle.logMessage(LOGMESSAGE, "Initialising random number generator with", s);
|
41 : |
|
|
|
42 : |
|
|
} else if (strcasecmp(text, "simanniter") == 0) {
|
43 : |
agomez |
1 |
infile >> simanniter;
|
44 : |
|
|
count++;
|
45 : |
|
|
|
46 : |
|
|
} else if (strcasecmp(text, "t") == 0) {
|
47 : |
|
|
infile >> t;
|
48 : |
|
|
count++;
|
49 : |
|
|
|
50 : |
|
|
} else if (strcasecmp(text, "rt") == 0) {
|
51 : |
|
|
infile >> rt;
|
52 : |
|
|
count++;
|
53 : |
|
|
|
54 : |
|
|
} else if (strcasecmp(text, "simanneps") == 0) {
|
55 : |
|
|
infile >> simanneps;
|
56 : |
|
|
count++;
|
57 : |
|
|
|
58 : |
|
|
} else if (strcasecmp(text, "nt") == 0) {
|
59 : |
|
|
infile >> nt;
|
60 : |
|
|
count++;
|
61 : |
|
|
|
62 : |
|
|
} else if (strcasecmp(text, "ns") == 0) {
|
63 : |
|
|
infile >> ns;
|
64 : |
|
|
count++;
|
65 : |
|
|
|
66 : |
|
|
} else if (strcasecmp(text, "vm") == 0) {
|
67 : |
|
|
infile >> vminit;
|
68 : |
|
|
count++;
|
69 : |
|
|
|
70 : |
|
|
} else if (strcasecmp(text, "cstep") == 0) {
|
71 : |
|
|
infile >> cs;
|
72 : |
|
|
count++;
|
73 : |
|
|
|
74 : |
|
|
} else if (strcasecmp(text, "check") == 0) {
|
75 : |
|
|
infile >> tempcheck;
|
76 : |
|
|
count++;
|
77 : |
|
|
|
78 : |
|
|
} else if (strcasecmp(text, "uratio") == 0) {
|
79 : |
|
|
infile >> uratio;
|
80 : |
|
|
count++;
|
81 : |
|
|
|
82 : |
|
|
} else if (strcasecmp(text, "lratio") == 0) {
|
83 : |
|
|
infile >> lratio;
|
84 : |
|
|
count++;
|
85 : |
|
|
|
86 : |
|
|
} else if (strcasecmp(text, "scale") == 0) {
|
87 : |
|
|
infile >> scale;
|
88 : |
|
|
count++;
|
89 : |
|
|
|
90 : |
|
|
} else {
|
91 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - unrecognised option", text);
|
92 : |
|
|
infile >> text; //read and ignore the next entry
|
93 : |
|
|
}
|
94 : |
|
|
infile >> text;
|
95 : |
|
|
}
|
96 : |
|
|
|
97 : |
ulcessvp |
11 |
if (s1 != 0) {
|
98 : |
|
|
seed = s1;
|
99 : |
|
|
if (s2 == 0)
|
100 : |
|
|
seedM = s1;
|
101 : |
|
|
else seedM = s2;
|
102 : |
|
|
if (s3 == 0)
|
103 : |
|
|
seedP = s1;
|
104 : |
|
|
else seedP = s3;
|
105 : |
|
|
} else {
|
106 : |
|
|
if (s2 != 0)
|
107 : |
|
|
seedP = s2;
|
108 : |
|
|
if (s3 != 0)
|
109 : |
|
|
seedP = s3;
|
110 : |
|
|
}
|
111 : |
|
|
|
112 : |
agomez |
1 |
if (count == 0)
|
113 : |
|
|
handle.logMessage(LOGINFO, "Warning - no parameters specified for Simulated Annealing optimisation algorithm");
|
114 : |
|
|
|
115 : |
|
|
//check the values specified in the optinfo file ...
|
116 : |
|
|
if ((uratio < 0.5) || (uratio > 1.0)) {
|
117 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of uratio outside bounds", uratio);
|
118 : |
|
|
uratio = 0.7;
|
119 : |
|
|
}
|
120 : |
|
|
if ((lratio < rathersmall) || (lratio > 0.5)) {
|
121 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of lratio outside bounds", lratio);
|
122 : |
|
|
lratio = 0.3;
|
123 : |
|
|
}
|
124 : |
|
|
if ((rt < rathersmall) || (rt > 1.0)) {
|
125 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of rt outside bounds", rt);
|
126 : |
|
|
rt = 0.85;
|
127 : |
|
|
}
|
128 : |
|
|
if (t < rathersmall) {
|
129 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of t outside bounds", t);
|
130 : |
|
|
t = 100.0;
|
131 : |
|
|
}
|
132 : |
|
|
if (nt < 1) {
|
133 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of nt outside bounds", nt);
|
134 : |
|
|
nt = 2;
|
135 : |
|
|
}
|
136 : |
|
|
if (ns < 1) {
|
137 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of ns outside bounds", ns);
|
138 : |
|
|
ns = 5;
|
139 : |
|
|
}
|
140 : |
|
|
if (tempcheck < 1) {
|
141 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of check outside bounds", tempcheck);
|
142 : |
|
|
tempcheck = 4;
|
143 : |
|
|
}
|
144 : |
|
|
if (vminit < rathersmall) {
|
145 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of vm outside bounds", vminit);
|
146 : |
|
|
vminit = 1.0;
|
147 : |
|
|
}
|
148 : |
|
|
if (cs < rathersmall) {
|
149 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of cstep outside bounds", cs);
|
150 : |
|
|
cs = 2.0;
|
151 : |
|
|
}
|
152 : |
|
|
if (simanneps < rathersmall) {
|
153 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of simanneps outside bounds", simanneps);
|
154 : |
|
|
simanneps = 1e-4;
|
155 : |
|
|
}
|
156 : |
|
|
if (scale != 0 && scale != 1) {
|
157 : |
|
|
handle.logMessage(LOGINFO, "Warning in optinfofile - value of scale outside bounds", scale);
|
158 : |
|
|
scale = 0;
|
159 : |
|
|
}
|
160 : |
|
|
}
|
161 : |
|
|
|
162 : |
|
|
void OptInfoSimann::Print(ofstream& outfile, int prec) {
|
163 : |
|
|
outfile << "; Simulated Annealing algorithm ran for " << iters
|
164 : |
|
|
<< " function evaluations\n; and stopped when the likelihood value was "
|
165 : |
|
|
<< setprecision(prec) << score;
|
166 : |
|
|
if (converge == -1)
|
167 : |
|
|
outfile << "\n; because an error occured during the optimisation\n";
|
168 : |
|
|
else if (converge == 1)
|
169 : |
|
|
outfile << "\n; because the convergence criteria were met\n";
|
170 : |
|
|
else
|
171 : |
|
|
outfile << "\n; because the maximum number of function evaluations was reached\n";
|
172 : |
|
|
}
|