1 |
#include "ecosystem.h" |
#include "ecosystem.h" |
2 |
#include "runid.h" |
#include "runid.h" |
3 |
#include "global.h" |
#include "global.h" |
4 |
|
#ifndef NO_OPENMP |
5 |
|
#include <omp.h> |
6 |
|
#endif |
7 |
|
|
8 |
|
#ifndef NO_OPENMP |
9 |
|
extern Ecosystem** EcoSystems; |
10 |
|
//extern StochasticData* data; |
11 |
|
#endif |
12 |
|
|
13 |
Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { |
Ecosystem::Ecosystem(const MainInfo& main) : printinfo(main.getPI()) { |
14 |
|
|
40 |
infile.open(filename, ios::in); |
infile.open(filename, ios::in); |
41 |
handle.checkIfFailure(infile, filename); |
handle.checkIfFailure(infile, filename); |
42 |
handle.Open(filename); |
handle.Open(filename); |
43 |
this->readOptimisation(commin); |
unsigned seed; |
44 |
|
main.getForcePrint(); |
45 |
|
this->readOptimisation(commin, main.getSeed()); |
46 |
handle.Close(); |
handle.Close(); |
47 |
infile.close(); |
infile.close(); |
48 |
infile.clear(); |
infile.clear(); |
111 |
void Ecosystem::Optimise() { |
void Ecosystem::Optimise() { |
112 |
int i; |
int i; |
113 |
for (i = 0; i < optvec.Size(); i++) { |
for (i = 0; i < optvec.Size(); i++) { |
114 |
|
#ifndef NO_OPENMP |
115 |
|
int j, numThr = omp_get_max_threads ( ); |
116 |
|
DoubleVector v = this->getValues(); |
117 |
|
for (j = 0; j < numThr; j++) |
118 |
|
EcoSystems[j]->Update(v); |
119 |
|
#endif |
120 |
optvec[i]->OptimiseLikelihood(); |
optvec[i]->OptimiseLikelihood(); |
121 |
this->writeOptValues(); |
this->writeOptValues(); |
122 |
} |
} |
123 |
} |
} |
124 |
|
|
125 |
|
#ifdef GADGET_OPENMP |
126 |
|
void Ecosystem::OptimiseOMP() { |
127 |
|
int i; |
128 |
|
for (i = 0; i < optvec.Size(); ++i) { |
129 |
|
optvec[i]->OptimiseLikelihoodOMP(); |
130 |
|
int j, numThr = omp_get_max_threads ( ); |
131 |
|
DoubleVector v = this->getValues(); |
132 |
|
for (j = 0; j < numThr; j++) |
133 |
|
EcoSystems[j]->Update(v); |
134 |
|
this->writeOptValues(); |
135 |
|
} |
136 |
|
} |
137 |
|
#endif |
138 |
|
|
139 |
double Ecosystem::SimulateAndUpdate(const DoubleVector& x) { |
double Ecosystem::SimulateAndUpdate(const DoubleVector& x) { |
140 |
int i, j; |
int i, j; |
141 |
|
|
178 |
for (i = 0; i < likevec.Size(); i++) |
for (i = 0; i < likevec.Size(); i++) |
179 |
tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
180 |
|
|
181 |
handle.logMessage(LOGINFO, "\nAfter a total of", funceval, "function evaluations the best point found is"); |
int iters = 0; |
182 |
|
#ifndef NO_OPENMP |
183 |
|
int numThr = omp_get_max_threads ( ); |
184 |
|
for (i = 0; i < numThr; i++) |
185 |
|
iters += EcoSystems[i]->getFuncEval(); |
186 |
|
#endif |
187 |
|
handle.logMessage(LOGINFO, "\nAfter a total of", funceval+iters, "function evaluations the best point found is"); |
188 |
keeper->writeBestValues(); |
keeper->writeBestValues(); |
189 |
handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are"); |
handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are"); |
190 |
handle.logMessage(LOGINFO, tmpvec); |
handle.logMessage(LOGINFO, tmpvec); |
194 |
handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); |
handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); |
195 |
} |
} |
196 |
|
|
197 |
|
//#ifdef GADGET_OPENMP |
198 |
|
//void Ecosystem::writeOptValuesOMP() { |
199 |
|
// int i; |
200 |
|
// DoubleVector tmpvec(likevec.Size(), 0.0); |
201 |
|
// for (i = 0; i < likevec.Size(); ++i) |
202 |
|
// tmpvec[i] = likevec[i]->getUnweightedLikelihood(); |
203 |
|
// |
204 |
|
// int iters = 0, numThr = omp_get_max_threads ( ); |
205 |
|
// for (i = 0; i < numThr; i++) |
206 |
|
// iters += EcoSystems[i]->getFuncEval(); |
207 |
|
// handle.logMessage(LOGINFO, "\nAfter a total of", funceval+iters, "function evaluations the best point found is"); |
208 |
|
// keeper->writeBestValues(); |
209 |
|
// handle.logMessage(LOGINFO, "\nThe scores from each likelihood component are"); |
210 |
|
// handle.logMessage(LOGINFO, tmpvec); |
211 |
|
// if (!isZero(keeper->getBestLikelihoodScore())) // no better point has been found |
212 |
|
// handle.logMessage(LOGINFO, "\nThe overall likelihood score is", keeper->getBestLikelihoodScore()); |
213 |
|
// else |
214 |
|
// handle.logMessage(LOGINFO, "\nThe overall likelihood score is", this->getLikelihood()); |
215 |
|
//} |
216 |
|
//#endif |
217 |
|
|
218 |
void Ecosystem::writeInitialInformation(const char* const filename) { |
void Ecosystem::writeInitialInformation(const char* const filename) { |
219 |
keeper->openPrintFile(filename); |
keeper->openPrintFile(filename); |
220 |
keeper->writeInitialInformation(likevec); |
keeper->writeInitialInformation(likevec); |