1 |
#include "ecosystem.h" |
#include "ecosystem.h" |
2 |
#include "runid.h" |
#include "runid.h" |
3 |
#include "global.h" |
#include "global.h" |
4 |
|
#ifdef _OPENMP |
5 |
|
#include <omp.h> |
6 |
|
#endif |
7 |
|
|
8 |
|
#ifdef _OPENMP |
9 |
|
extern Ecosystem** EcoSystems; |
10 |
|
//extern StochasticData* data; |
11 |
|
#endif |
12 |
|
extern volatile int interrupted_print; |
13 |
|
|
14 |
Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { |
Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { |
15 |
|
|
16 |
funceval = 0; |
funceval = 0; |
17 |
interrupted = 0; |
//interrupted = 0; |
18 |
likelihood = 0.0; |
likelihood = 0.0; |
19 |
keeper = new Keeper; |
keeper = new Keeper; |
20 |
|
|
41 |
infile.open(filename, ios::in); |
infile.open(filename, ios::in); |
42 |
handle.checkIfFailure(infile, filename); |
handle.checkIfFailure(infile, filename); |
43 |
handle.Open(filename); |
handle.Open(filename); |
44 |
this->readOptimisation(commin); |
unsigned seed; |
45 |
|
main.getForcePrint(); |
46 |
|
this->readOptimisation(commin, main.getSeed()); |
47 |
handle.Close(); |
handle.Close(); |
48 |
infile.close(); |
infile.close(); |
49 |
infile.clear(); |
infile.clear(); |
112 |
void Ecosystem::Optimise() { |
void Ecosystem::Optimise() { |
113 |
int i; |
int i; |
114 |
for (i = 0; i < optvec.Size(); i++) { |
for (i = 0; i < optvec.Size(); i++) { |
115 |
|
#ifdef _OPENMP |
116 |
|
int j, numThr = omp_get_max_threads ( ); |
117 |
|
DoubleVector v = this->getValues(); |
118 |
|
for (j = 0; j < numThr; j++) |
119 |
|
EcoSystems[j]->Update(v); |
120 |
|
#endif |
121 |
|
#ifdef SPECULATIVE |
122 |
|
optvec[i]->OptimiseLikelihoodOMP(); |
123 |
|
#else |
124 |
optvec[i]->OptimiseLikelihood(); |
optvec[i]->OptimiseLikelihood(); |
125 |
|
#endif |
126 |
this->writeOptValues(); |
this->writeOptValues(); |
127 |
} |
} |
128 |
} |
} |
169 |
for (i = 0; i < likevec.Size(); i++) |
for (i = 0; i < likevec.Size(); i++) |
170 |
tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
171 |
|
|
172 |
handle.logMessage(LOGINFO, "\nAfter a total of", funceval, "function evaluations the best point found is"); |
int iters = 0; |
173 |
|
#ifdef _OPENMP |
174 |
|
int numThr = omp_get_max_threads ( ); |
175 |
|
for (i = 0; i < numThr; i++) |
176 |
|
iters += EcoSystems[i]->getFuncEval(); |
177 |
|
#endif |
178 |
|
handle.logMessage(LOGINFO, "\nAfter a total of", funceval+iters, "function evaluations the best point found is"); |
179 |
keeper->writeBestValues(); |
keeper->writeBestValues(); |
180 |
handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are"); |
handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are"); |
181 |
handle.logMessage(LOGINFO, tmpvec); |
handle.logMessage(LOGINFO, tmpvec); |
195 |
} |
} |
196 |
|
|
197 |
void Ecosystem::writeParams(const char* const filename, int prec) const { |
void Ecosystem::writeParams(const char* const filename, int prec) const { |
198 |
if ((funceval > 0) && (interrupted == 0)) { |
if ((funceval > 0) && (interrupted_print == 0)) { |
199 |
//JMB - print the final values to any output files specified |
//JMB - print the final values to any output files specified |
200 |
//in case they have been missed by the -print value |
//in case they have been missed by the -print value |
201 |
if (printinfo.getPrint()) |
if (printinfo.getPrint()) |
202 |
keeper->writeValues(likevec, printinfo.getPrecision()); |
keeper->writeValues(likevec, printinfo.getPrecision()); |
203 |
} |
} |
204 |
keeper->writeParams(optvec, filename, prec, interrupted); |
keeper->writeParams(optvec, filename, prec, interrupted_print); |
205 |
} |
} |