-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameters.cpp
More file actions
471 lines (410 loc) · 14.4 KB
/
Parameters.cpp
File metadata and controls
471 lines (410 loc) · 14.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
/*----------------------------------------------------------------------------
*
* Copyright (C) 2026 Greta Bocedi, Stephen C.F. Palmer, Justin M.J. Travis, Anne-Kathleen Malchow, Roslyn Henry, Théo Pannetier, Jette Wolff, Damaris Zurell
*
* This file is part of RangeShifter.
*
* RangeShifter is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* RangeShifter is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with RangeShifter. If not, see <https://www.gnu.org/licenses/>.
*
--------------------------------------------------------------------------*/
//---------------------------------------------------------------------------
#include "Parameters.h"
//---------------------------------------------------------------------------
//---------------------------------------------------------------------------
// Environmental gradient parameters
paramGrad::paramGrad(void) {
gradient = false; gradType = 0; grad_inc = 0.05f;
opt_y0 = opt_y = factor = extProbOpt = 0.0;
shifting = false; shift_rate = 0.5; shift_begin = 0; shift_stop = 100;
}
paramGrad::~paramGrad() { }
void paramGrad::setGradient(int gtype, float inc, float y, float f, float p)
{
if (gtype > 0 && gtype < 4)
{ // valid gradient type
gradient = true; gradType = gtype;
if (inc >= 0.0 && inc <= 1.0) grad_inc = inc;
if (y >= 0.0) opt_y0 = opt_y = y;
if (f >= 0.0) factor = f;
if (p > 0.0 && p < 1.0) extProbOpt = p;
}
else {
gradient = false; gradType = 0;
}
}
void paramGrad::setShifting(float r, int begin, int end)
{
shifting = true;
if (r > 0.0) shift_rate = r;
if (begin >= 0) shift_begin = begin;
if (end > 0) shift_stop = end;
}
void paramGrad::noGradient(void) { gradient = false; gradType = 0; }
void paramGrad::noShifting(void) { shifting = false; }
envGradParams paramGrad::getGradient(void) {
envGradParams g;
g.gradient = gradient; g.gradType = gradType; g.grad_inc = grad_inc;
g.opt_y = opt_y; g.factor = factor; g.extProbOpt = extProbOpt;
g.shifting = shifting; g.shift_rate = shift_rate;
g.shift_begin = shift_begin; g.shift_stop = shift_stop;
return g;
}
void paramGrad::incrOptY(void)
{
if (gradient && shifting) opt_y += shift_rate;
}
void paramGrad::resetOptY(void) { opt_y = opt_y0; }
//---------------------------------------------------------------------------
// Environmental stochasticity parameters
paramStoch::paramStoch(void) {
stoch = false; local = false; inK = false; localExt = false;
ac = 0.0; std = 0.25;
locExtProb = 0.1;
}
paramStoch::~paramStoch(void) {}
void paramStoch::setStoch(envStochParams e)
{
stoch = e.stoch; local = e.local; inK = e.inK; localExt = e.localExt;
if (e.ac >= 0.0 && e.ac < 1.0) ac = e.ac;
if (e.std > 0.0 && e.std <= 1.0) std = e.std;
locExtProb = e.locExtProb;
}
bool paramStoch::envStoch(void) { return stoch; }
envStochParams paramStoch::getStoch(void)
{
envStochParams e;
e.stoch = stoch; e.local = local; e.inK = inK; e.localExt = localExt;
e.ac = ac; e.std = std;
e.locExtProb = locExtProb;
return e;
}
//---------------------------------------------------------------------------
// Initialisation (seeding) parameters
paramInit::paramInit(void) {
seedType = freeType = spDistType = initDens = 0;
initAge = initFrzYr = 0;
restrictRange = false;
restrictRows = 100;
restrictFreq = 10;
finalFrzYr = 99999999;
indsCell = 1; indsHa = 0.0;
minSeedX = 0; maxSeedX = 99999999; minSeedY = 0; maxSeedY = 99999999;
nSeedPatches = 1; nSpDistPatches = 1;
indsFile = "NULL";
for (int i = 0; i < gMaxNbStages; i++) {
initProp[i] = 0.0;
}
}
paramInit::~paramInit(void) {
initinds.clear();
}
void paramInit::setInit(initParams i) {
if (i.seedType >= 0 && i.seedType <= 3) seedType = i.seedType;
if (i.freeType >= 0 && i.freeType <= 2) freeType = i.freeType;
if (i.spDistType >= 0 && i.spDistType <= 2) spDistType = i.spDistType;
initDens = i.initDens;
initAge = i.initAge;
if (i.initFrzYr >= 0) initFrzYr = i.initFrzYr;
restrictRange = i.restrictRange;
if (i.restrictRows > 0) restrictRows = i.restrictRows;
if (i.restrictFreq > 0) restrictFreq = i.restrictFreq;
if (i.finalFrzYr > 0) finalFrzYr = i.finalFrzYr;
if (i.indsCell >= 1) indsCell = i.indsCell;
if (i.indsHa > 0.0) indsHa = i.indsHa;
if (i.minSeedX >= 0) minSeedX = i.minSeedX;
if (i.maxSeedX >= 0) maxSeedX = i.maxSeedX;
if (i.minSeedY >= 0) minSeedY = i.minSeedY;
if (i.maxSeedY >= 0) maxSeedY = i.maxSeedY;
if (i.nSeedPatches >= 1) nSeedPatches = i.nSeedPatches;
if (i.nSpDistPatches >= 1) nSpDistPatches = i.nSpDistPatches;
indsFile = i.indsFile;
}
initParams paramInit::getInit(void) {
initParams i;
i.seedType = seedType; i.freeType = freeType; i.spDistType = spDistType;
i.initDens = initDens; i.initAge = initAge;
i.initFrzYr = initFrzYr;
i.restrictRange = restrictRange;
i.restrictRows = restrictRows; i.restrictFreq = restrictFreq;
i.finalFrzYr = finalFrzYr;
i.indsCell = indsCell; i.indsHa = indsHa;
i.minSeedX = minSeedX; i.minSeedY = minSeedY;
i.maxSeedX = maxSeedX; i.maxSeedY = maxSeedY;
i.nSeedPatches = nSeedPatches; i.nSpDistPatches = nSpDistPatches;
i.indsFile = indsFile;
return i;
}
void paramInit::setProp(short stg, float p) {
if (stg >= 0 && stg < gMaxNbStages && p >= 0.0 && p <= 1.0) initProp[stg] = p;
}
float paramInit::getProp(short stg) {
float p = 0.0;
if (stg >= 0 && stg < gMaxNbStages) p = initProp[stg];
return p;
}
void paramInit::addInitInd(initInd iind) {
initinds.push_back(iind);
}
initInd paramInit::getInitInd(int ix) {
initInd iind;
if (ix >= 0 && ix < (int)initinds.size()) {
iind = initinds[ix];
}
else {
iind.year = iind.patchID = iind.x = iind.y = iind.sex = iind.age = iind.stage = 0;
iind.species = -1;
}
return iind;
}
void paramInit::resetInitInds(void) { initinds.clear(); }
int paramInit::numInitInds(void) { return (int)initinds.size(); }
//---------------------------------------------------------------------------
// Simulation parameters
paramSim::paramSim(const string& pathToProjDir) :
dir{pathToProjDir}
{
simulation = 0;
reps = years = 1;
outIntRange = 1;
outStartPop = outStartInd = 0;
outStartTraitCell = outStartTraitRow = outStartConn = 0;
outputGlobalFstStart = outputPairwiseFstStart = 0;
outIntOcc = outIntPop = outIntInd = outputGlobalFstInterval = outputPairwiseFstInterval= 10;
outIntTraitCell = outIntTraitRow = outIntConn = 10;
traitInt = 10;
batchMode = absorbing = false;
outRange = outOccup = outPop = outInds = false;
outTraitsCells = outTraitsRows = outConnect = false;
outputGenes = outputGlobalFst = outPairwiseFst = false;
saveVisits = false;
#if RS_RCPP
outStartPaths = 0; outIntPaths = 0;
outPaths = false; ReturnPopMatrix = false; ReturnPopDataFrame = false; CreatePopFile = true;
#endif
}
paramSim::~paramSim(void) { }
void paramSim::setSim(simParams s) {
if (s.batchNum >= 0) batchNum = s.batchNum;
if (s.simulation >= 0) simulation = s.simulation;
if (s.reps >= 1) reps = s.reps;
if (s.years >= 1) years = s.years;
if (s.traitInt >= 1) traitInt = s.traitInt;
batchMode = s.batchMode; absorbing = s.absorbing;
outRange = s.outRange; outOccup = s.outOccup;
outPop = s.outPop; outInds = s.outInds;
outTraitsCells = s.outTraitsCells; outTraitsRows = s.outTraitsRows;
outConnect = s.outConnect;
if (s.outStartPop >= 0) outStartPop = s.outStartPop;
if (s.outStartInd >= 0) outStartInd = s.outStartInd;
if (s.outStartTraitCell >= 0) outStartTraitCell = s.outStartTraitCell;
if (s.outStartTraitRow >= 0) outStartTraitRow = s.outStartTraitRow;
if (s.outStartConn >= 0) outStartConn = s.outStartConn;
if (s.outIntRange >= 1) outIntRange = s.outIntRange;
if (s.outIntOcc >= 1) outIntOcc = s.outIntOcc;
if (s.outIntPop >= 1) outIntPop = s.outIntPop;
if (s.outIntInd >= 1) outIntInd = s.outIntInd;
if (s.outIntTraitCell >= 1) outIntTraitCell = s.outIntTraitCell;
if (s.outIntTraitRow >= 1) outIntTraitRow = s.outIntTraitRow;
if (s.outIntConn >= 1) outIntConn = s.outIntConn;
saveVisits = s.saveVisits;
#if RS_RCPP
outStartPaths = s.outStartPaths;
outIntPaths = s.outIntPaths;
outPaths = s.outPaths;
ReturnPopMatrix = s.ReturnPopMatrix;
ReturnPopDataFrame = s.ReturnPopDataFrame;
ReturnStages = s.ReturnStages;
CreatePopFile = s.CreatePopFile;
#endif
fixReplicateSeed = s.fixReplicateSeed;
}
void paramSim::setGeneticSim(string patchSamplingOption, bool outputGenes, int outputGenesStart, int outputGenesInterval, bool outPairwiseFst,
int outputGlobalFst, int outputStartGlobalFst, int outputGlobalFstInterval, int outputStartPairwiseFst, int outputPairwiseFstIntervals, bool outputPerLocusFst) {
this->patchSamplingOption = patchSamplingOption;
this->outputGenes = outputGenes;
this->outputGenesStart = outputGenesStart;
this->outputGenesInterval = outputGenesInterval;
this->outputGlobalFst = outputGlobalFst;
this->outputGlobalFstStart = outputStartGlobalFst;
this->outputGlobalFstInterval = outputGlobalFstInterval;
this->outPairwiseFst = outPairwiseFst;
this->outputPairwiseFstStart = outputStartPairwiseFst;
this->outputPairwiseFstInterval = outputPairwiseFstIntervals;
this->outputPerLocusFst = outputPerLocusFst;
}
simParams paramSim::getSim() {
simParams s;
s.batchNum = batchNum;
s.simulation = simulation; s.reps = reps; s.years = years;
s.outRange = outRange; s.outOccup = outOccup; s.outPop = outPop; s.outInds = outInds;
s.outTraitsCells = outTraitsCells; s.outTraitsRows = outTraitsRows; s.outConnect = outConnect;
s.outStartPop = outStartPop; s.outStartInd = outStartInd;
s.outStartTraitCell = outStartTraitCell; s.outStartTraitRow = outStartTraitRow;
s.outStartConn = outStartConn;
s.outIntRange = outIntRange;
s.outIntOcc = outIntOcc; s.outIntPop = outIntPop;
s.outIntInd = outIntInd;
s.outIntTraitCell = outIntTraitCell;
s.outIntTraitRow = outIntTraitRow;
s.outIntConn = outIntConn;
s.batchMode = batchMode;
s.absorbing = absorbing;
s.traitInt = traitInt;
#if RS_RCPP
s.saveVisits = saveVisits;
s.outStartPaths = outStartPaths;
s.outIntPaths = outIntPaths;
s.outPaths = outPaths;
s.ReturnPopMatrix = ReturnPopMatrix;
s.ReturnPopDataFrame = ReturnPopDataFrame;
s.ReturnStages = ReturnStages;
s.CreatePopFile = CreatePopFile;
#endif
s.patchSamplingOption = patchSamplingOption;
s.outputGenes = outputGenes;
s.outputGenesStart = outputGenesStart;
s.outputGenesInterval = outputGenesInterval;
s.outputGlobalFst = outputGlobalFst;
s.outputGlobalFstStart = outputGlobalFstStart;
s.outputGlobalFstInterval = outputGlobalFstInterval;
s.outPairwiseFst = outPairwiseFst;
s.outputPairwiseFstStart = outputPairwiseFstStart;
s.outputPairwiseFstInterval = outputPairwiseFstInterval;
s.outputPerLocusFst = outputPerLocusFst;
return s;
}
int paramSim::getSimNum(void) { return simulation; }
// return directory name depending on option specified
string paramSim::getDir(int option) {
string s;
switch (option) {
case 0: // working directory
s = dir;
break;
#if LINUX_CLUSTER || RS_RCPP
case 1: // Inputs folder
s = dir + "Inputs/";
break;
case 2: // Outputs folder
s = dir + "Outputs/";
break;
case 3: // Maps folder
s = dir + "Output_Maps/";
break;
#else
case 1: // Inputs folder
s = dir + "Inputs\\";
break;
case 2: // Outputs folder
s = dir + "Outputs\\";
break;
case 3: // Maps folder
s = dir + "Output_Maps\\";
break;
#endif
default:
s = "ERROR_ERROR_ERROR";
}
return s;
}
string to_string(const TraitType& tr) {
switch (tr)
{
case NEUTRAL: return "NEUTRAL";
case GENETIC_LOAD: return "GENETIC_LOAD";
case GENETIC_LOAD1: return "GENETIC_LOAD1";
case GENETIC_LOAD2: return "GENETIC_LOAD2";
case GENETIC_LOAD3: return "GENETIC_LOAD3";
case GENETIC_LOAD4: return "GENETIC_LOAD4";
case GENETIC_LOAD5: return "GENETIC_LOAD5";
case E_D0: return "E_D0";
case E_D0_M: return "E_D0_M";
case E_D0_F: return "E_D0_F";
case E_ALPHA: return "E_ALPHA";
case E_ALPHA_M: return "E_ALPHA_M";
case E_ALPHA_F: return "E_ALPHA_F";
case E_BETA: return "E_BETA";
case E_BETA_M: return "E_BETA_M";
case E_BETA_F: return "E_BETA_F";
case S_S0: return "S_S0";
case S_S0_M: return "S_S0_M";
case S_S0_F: return "S_S0_F";
case S_ALPHA: return "S_ALPHA";
case S_ALPHA_M: return "S_ALPHA_M";
case S_ALPHA_F: return "S_ALPHA_F";
case S_BETA: return "S_BETA";
case S_BETA_M: return "S_BETA_M";
case S_BETA_F: return "S_BETA_F";
case CRW_STEPLENGTH: return "CRW_STEPLENGTH";
case CRW_STEPCORRELATION: return "CRW_STEPCORRELATION";
case KERNEL_MEANDIST_1: return "KERNEL_MEANDIST_1";
case KERNEL_MEANDIST_2: return "KERNEL_MEANDIST_2";
case KERNEL_MEANDIST_1_F: return "KERNEL_MEANDIST_1_F";
case KERNEL_MEANDIST_2_F: return "KERNEL_MEANDIST_2_F";
case KERNEL_MEANDIST_1_M: return "KERNEL_MEANDIST_1_M";
case KERNEL_MEANDIST_2_M: return "KERNEL_MEANDIST_2_M";
case KERNEL_PROBABILITY: return "KERNEL_PROBABILITY";
case KERNEL_PROBABILITY_F: return "KERNEL_PROBABILITY_F";
case KERNEL_PROBABILITY_M: return "KERNEL_PROBABILITY_M";
case SMS_DP: return "SMS_DP";
case SMS_GB: return "SMS_GB";
case SMS_ALPHADB: return "SMS_ALPHADB";
case SMS_BETADB: return "SMS_BETADB";
case INVALID_TRAIT: return "INVALID_TRAIT";
default: return "";
}
}
string to_string(const GenParamType& param) {
switch (param)
{
case MEAN: return "MEAN";
case SD: return "SD";
case MIN: return "MIN";
case MAX: return "MAX";
case SHAPE: return "SHAPE";
case SCALE: return "SCALE";
case INVALID: return "INVALID";
default: return "";
}
}
string to_string(const DistributionType& dist) {
switch (dist)
{
case UNIFORM: return "UNIFORM";
case NORMAL: return "NORMAL";
case GAMMA: return "GAMMA";
case NEGEXP: return "NEGEXP";
case SCALED: return "SCALED";
case KAM: return "KAM";
case SSM: return "SSM";
case NONE: return "NONE";
default: return "";
}
}
string to_string(const ExpressionType& expr) {
switch (expr)
{
case AVERAGE: return "AVERAGE";
case ADDITIVE: return "ADDITIVE";
case NOTEXPR: return "NOTEXPR";
case MULTIPLICATIVE: return "MULTIPLICATIVE";
default: return "";
}
}
#if RS_RCPP
bool paramSim::getReturnPopMatrix(void) { return ReturnPopMatrix; }
bool paramSim::getReturnPopDataFrame(void) { return ReturnPopDataFrame; }
bool paramSim::getCreatePopFile(void) { return CreatePopFile; }
#endif
//---------------------------------------------------------------------------