Nemo  2.3.56
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCE_SelectionSH Class Reference

StatHandler class for the LCE_Selection class. More...

#include <LCEselection.h>

+ Inheritance diagram for LCE_SelectionSH:
+ Collaboration diagram for LCE_SelectionSH:

Public Member Functions

 LCE_SelectionSH (LCE_Selection_base *event)
 
virtual ~LCE_SelectionSH ()
 
virtual bool setStatRecorders (string &token)
 
void addMeanPerPatch (age_t AGE)
 
void addVarPerPatch (age_t AGE)
 
void setDataTable (age_t AGE)
 
void setAdultTable ()
 
void setOffsprgTable ()
 
double getMeanFitness ()
 
double getFitness (unsigned int i)
 
double getSurvival (unsigned int i)
 
double getPedProp (unsigned int i)
 
double getMeanPatchFitness (unsigned int i, unsigned int int_agex)
 
double getMeanPatchFitness (unsigned int i)
 
double getVarPatchFitness (unsigned int i, unsigned int int_agex)
 
- Public Member Functions inherited from EventStatHandler< LCE_Selection_base, LCE_SelectionSH >
 EventStatHandler (LCE_Selection_base *lce)
 
virtual ~EventStatHandler ()
 
- Public Member Functions inherited from StatHandler< SH >
 StatHandler ()
 
virtual ~StatHandler ()
 
virtual void clear ()
 Empties the _recorders list, they are destroyed in StatHandlerBase::reset(). More...
 
virtual StatRecorder< SH > * add (std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(SH::*getStatNoArg)(void), double(SH::*getStatOneArg)(unsigned int), double(SH::*getStatTwoArg)(unsigned int, unsigned int), void(SH::*setStat)(void))
 Adds a StatRecorder to the list, it is also added to the StatHandlerBase::_stats list. More...
 
- Public Member Functions inherited from StatHandlerBase
 StatHandlerBase ()
 
virtual ~StatHandlerBase ()
 
virtual void reset ()
 Empties the _stats list and calls clear() (defined in the derived class). More...
 
Metapopget_pop_ptr ()
 
void set_service (StatServices *srv)
 
StatServicesget_service ()
 
unsigned int getOccurrence ()
 
unsigned int getNumOccurrences ()
 
unsigned int getCurrentOccurrence ()
 
unsigned int getNbRecorders ()
 
std::list< StatRecBase * > & getStats ()
 
virtual void add (StatRecBase *rec)
 
virtual void init ()
 
virtual void update ()
 This function is left empty as the StatServices calls StatRecorder::setVal directly. More...
 
- Public Member Functions inherited from Handler
virtual void init ()=0
 Inits state. More...
 
virtual void update ()=0
 Updates the handler state. More...
 
virtual ~Handler ()
 

Private Attributes

vector< vector< double > > _phenoTable
 
unsigned int _table_set_gen
 
unsigned int _table_set_age
 
unsigned int _table_set_repl
 

Additional Inherited Members

- Protected Types inherited from StatHandler< SH >
typedef std::list< StatRecorder< SH > * >::iterator REC_IT
 
- Protected Attributes inherited from EventStatHandler< LCE_Selection_base, LCE_SelectionSH >
LCE_Selection_base_SHLinkedEvent
 Pointer to the linked LCE. More...
 
- Protected Attributes inherited from StatHandler< SH >
std::list< StatRecorder< SH > * > _recorders
 The list of stat recorders. More...
 
- Protected Attributes inherited from StatHandlerBase
Metapop_pop
 Link to the current population, set through the link to the StatService. More...
 

Detailed Description

StatHandler class for the LCE_Selection class.

Records the fitness stats.

Constructor & Destructor Documentation

◆ LCE_SelectionSH()

LCE_SelectionSH::LCE_SelectionSH ( LCE_Selection_base event)
inline
302 :
304 _table_set_gen(999999), _table_set_age(999999), _table_set_repl(999999)
305 {}
unsigned int _table_set_age
Definition: LCEselection.h:298
unsigned int _table_set_repl
Definition: LCEselection.h:298
unsigned int _table_set_gen
Definition: LCEselection.h:298

◆ ~LCE_SelectionSH()

virtual LCE_SelectionSH::~LCE_SelectionSH ( )
inlinevirtual
307{}

Member Function Documentation

◆ addMeanPerPatch()

void LCE_SelectionSH::addMeanPerPatch ( age_t  AGE)
1204{
1205 unsigned int patchNbr = _pop->getPatchNbr();
1206
1207 if (AGE == ALL) {
1210 return;
1211 }
1212
1213 string suffix = (AGE == ADULTS ? "adlt.":"off."); //at this stage, AGE != ALL
1214 string name = suffix + "W.avg.p";
1215 string long_name = "Mean fitness in patch ";
1216 string patch;
1217
1218 void (LCE_SelectionSH::* setter) (void) = (AGE == ADULTS ?
1221
1222 unsigned int int_agex = static_cast<age_idx> ((AGE == ADULTS ? ADLTx : OFFSx));
1223
1224 //first patch, gets the data table setter:
1225 add(long_name + "1", name + "1", AGE, 0, int_agex,
1227
1228 for(unsigned int p = 1; p < patchNbr; p++) {
1229 patch = tstring::int2str(p+1);
1230 add(long_name + patch, name + patch, AGE, p, int_agex,
1232 }
1233}
StatHandler class for the LCE_Selection class.
Definition: LCEselection.h:295
double getMeanPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1342
void setOffsprgTable()
Definition: LCEselection.h:315
void setAdultTable()
Definition: LCEselection.h:314
void addMeanPerPatch(age_t AGE)
Definition: LCEselection.cc:1203
unsigned int getPatchNbr()
Definition: metapop.h:276
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:61
virtual StatRecorder< SH > * add(std::string Title, std::string Name, age_t AGE, unsigned int ARG1, unsigned int ARG2, double(SH::*getStatNoArg)(void), double(SH::*getStatOneArg)(unsigned int), double(SH::*getStatTwoArg)(unsigned int, unsigned int), void(SH::*setStat)(void))
Adds a StatRecorder to the list, it is also added to the StatHandlerBase::_stats list.
Definition: stathandler.h:144
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:95
#define ALL
All ages age class flag.
Definition: types.h:56
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
@ OFFSx
Definition: types.h:42
@ ADLTx
Definition: types.h:42

References StatHandlerBase::_pop, StatHandler< SH >::add(), addMeanPerPatch(), ADLTx, ADULTS, ALL, getMeanPatchFitness(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, OFFSx, setAdultTable(), and setOffsprgTable().

Referenced by addMeanPerPatch(), and setStatRecorders().

+ Here is the caller graph for this function:

◆ addVarPerPatch()

void LCE_SelectionSH::addVarPerPatch ( age_t  AGE)
1238{
1239 unsigned int patchNbr = _pop->getPatchNbr();
1240
1241 if (AGE == ALL) {
1244 return;
1245 }
1246
1247 string suffix = (AGE == ADULTS ? "adlt.":"off."); //at this stage, AGE != ALL
1248 string name = suffix + "W.var.p";
1249 string long_name = "Var fitness in patch ";
1250 string patch;
1251
1252 void (LCE_SelectionSH::* setter) (void) = (AGE == ADULTS ?
1255
1256 unsigned int int_agex = static_cast<age_idx> ((AGE == ADULTS ? ADLTx : OFFSx));
1257
1258 //first patch, gets the data table setter:
1259 add(long_name + "1", name + "1", AGE, 0, int_agex,
1261
1262 for(unsigned int p = 1; p < patchNbr; p++) {
1263 patch = tstring::int2str(p+1);
1264 add(long_name + patch, name + patch, AGE, p, int_agex,
1266 }
1267}
double getVarPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1369
void addVarPerPatch(age_t AGE)
Definition: LCEselection.cc:1237

References StatHandlerBase::_pop, StatHandler< SH >::add(), addVarPerPatch(), ADLTx, ADULTS, ALL, Metapop::getPatchNbr(), getVarPatchFitness(), tstring::int2str(), OFFSPRG, OFFSx, setAdultTable(), and setOffsprgTable().

Referenced by addVarPerPatch(), and setStatRecorders().

+ Here is the caller graph for this function:

◆ getFitness()

double LCE_SelectionSH::getFitness ( unsigned int  i)
inline
319{return _SHLinkedEvent->_fitness[i];}
LCE_Selection_base * _SHLinkedEvent
Pointer to the linked LCE.
Definition: stathandler.h:193
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:92

References LCE_Selection_base::_fitness, and EventStatHandler< LCE_Selection_base, LCE_SelectionSH >::_SHLinkedEvent.

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ getMeanFitness()

double LCE_SelectionSH::getMeanFitness ( )
inline
double _mean_fitness
Definition: LCEselection.h:89

References LCE_Selection_base::_mean_fitness, and EventStatHandler< LCE_Selection_base, LCE_SelectionSH >::_SHLinkedEvent.

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ getMeanPatchFitness() [1/2]

double LCE_SelectionSH::getMeanPatchFitness ( unsigned int  i)
1357{
1358 double mean = 0;
1359 unsigned int size = _phenoTable[i].size();
1360
1361 for(unsigned int j = 0; j < size; j++)
1362 mean += _phenoTable[i][j];
1363
1364 return mean/size;
1365}
vector< vector< double > > _phenoTable
Definition: LCEselection.h:297

References _phenoTable.

◆ getMeanPatchFitness() [2/2]

double LCE_SelectionSH::getMeanPatchFitness ( unsigned int  i,
unsigned int  int_agex 
)
1343{
1344 age_idx age = static_cast<age_idx> (int_agex);
1345 unsigned int patch_size = _pop->getPatchPtr(i)->size(age);
1346
1347 assert(patch_size == _phenoTable[i].size());
1348
1349 if(patch_size == 0) return (nanf("NULL"));
1350
1351 return getMeanPatchFitness(i);
1352}
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:260
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:496

References _phenoTable, StatHandlerBase::_pop, getMeanPatchFitness(), Metapop::getPatchPtr(), and Patch::size().

Referenced by addMeanPerPatch(), getMeanPatchFitness(), and getVarPatchFitness().

+ Here is the caller graph for this function:

◆ getPedProp()

double LCE_SelectionSH::getPedProp ( unsigned int  i)
inline
321{return _SHLinkedEvent->_ind_cntr[i];}
double _ind_cntr[5]
Definition: LCEselection.h:92

References LCE_Selection_base::_ind_cntr, and EventStatHandler< LCE_Selection_base, LCE_SelectionSH >::_SHLinkedEvent.

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ getSurvival()

double LCE_SelectionSH::getSurvival ( unsigned int  i)
inline
320{return _SHLinkedEvent->_survival[i];}
double _survival[5]
Definition: LCEselection.h:92

References EventStatHandler< LCE_Selection_base, LCE_SelectionSH >::_SHLinkedEvent, and LCE_Selection_base::_survival.

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ getVarPatchFitness()

double LCE_SelectionSH::getVarPatchFitness ( unsigned int  i,
unsigned int  int_agex 
)
1370{
1371 age_idx age = static_cast<age_idx> (int_agex);
1372 unsigned int patch_size = _pop->getPatchPtr(i)->size(age);
1373
1374 assert(patch_size == _phenoTable[i].size());
1375
1376 if(patch_size == 0) return nanf("NULL");
1377
1378 double mean = getMeanPatchFitness(i);
1379 double var = 0;
1380
1381 for(unsigned int j = 0; j < patch_size; j++) {
1382
1383 var += pow(_phenoTable[i][j] - mean, 2.0);
1384 }
1385
1386 return var/patch_size;
1387}

References _phenoTable, StatHandlerBase::_pop, getMeanPatchFitness(), Metapop::getPatchPtr(), and Patch::size().

Referenced by addVarPerPatch().

+ Here is the caller graph for this function:

◆ setAdultTable()

void LCE_SelectionSH::setAdultTable ( )
inline
void setDataTable(age_t AGE)
Definition: LCEselection.cc:1271

References ADULTS, and setDataTable().

Referenced by addMeanPerPatch(), and addVarPerPatch().

+ Here is the caller graph for this function:

◆ setDataTable()

void LCE_SelectionSH::setDataTable ( age_t  AGE)
1272{
1273 if(_table_set_age == AGE
1276 ) return;
1277
1278 unsigned int patchNbr = _pop->getPatchNbr();
1279
1280 if(_phenoTable.size() != patchNbr) {
1281 if(_phenoTable.size() < patchNbr) {
1282 while (_phenoTable.size() < patchNbr)
1283 _phenoTable.push_back(vector<double>());
1284 } else {
1285 while (_phenoTable.size() > patchNbr) {
1286 _phenoTable.pop_back();
1287 }
1288 }
1289 }
1290
1291 for(unsigned int i = 0; i < patchNbr; ++i) {
1292 _phenoTable[i].assign(_pop->size(AGE, i),0);
1293 }
1294
1295 Patch* patch;
1296
1297 age_idx age = (AGE == ADULTS ? ADLTx : OFFSx);
1298
1299 for(unsigned int i = 0, n; i < patchNbr; i++) {
1300
1301
1302 patch = _pop->getPatch(i);
1303
1304
1308 else
1310 }
1311
1312 n = 0;
1313
1314 for(unsigned int j = 0, size = patch->size(FEM, age);
1315 j < size && n < _phenoTable[i].size();
1316 j++)
1317 {
1318 _phenoTable[i][n++] = _SHLinkedEvent->getFitness( patch->get(FEM, age, j), i);
1319 }
1320
1321 for(unsigned int j = 0, size = patch->size(MAL, age);
1322 j < size && n < _phenoTable[i].size();
1323 j++)
1324 {
1325 _phenoTable[i][n++] = _SHLinkedEvent->getFitness( patch->get(MAL, age, j), i);
1326 }
1327
1328
1329 if (n != _phenoTable[i].size()) {
1330 fatal("problem while recording fitness trait values; size counter doesn't match table size.\n");
1331 }
1332 }
1333
1334 _table_set_age = AGE;
1337
1338}
bool _is_absolute
Definition: LCEselection.h:90
bool _is_local
Definition: LCEselection.h:90
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:190
void setScalingFactorGlobal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the mean population fitness.
Definition: LCEselection.cc:869
void setScalingFactorLocal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the mean local patch fitness.
Definition: LCEselection.cc:861
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:310
unsigned int getCurrentReplicate()
Definition: metapop.h:293
unsigned int getCurrentGeneration()
Definition: metapop.h:294
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:532
void fatal(const char *str,...)
Definition: output.cc:96
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37

References LCE_Selection_base::_is_absolute, LCE_Selection_base::_is_local, _phenoTable, StatHandlerBase::_pop, EventStatHandler< LCE_Selection_base, LCE_SelectionSH >::_SHLinkedEvent, _table_set_age, _table_set_gen, _table_set_repl, ADLTx, ADULTS, fatal(), FEM, Patch::get(), Metapop::getCurrentGeneration(), Metapop::getCurrentReplicate(), LCE_Selection_base::getFitness(), Metapop::getPatch(), Metapop::getPatchNbr(), MAL, OFFSx, LCE_Selection_base::setScalingFactorGlobal(), LCE_Selection_base::setScalingFactorLocal(), Metapop::size(), and Patch::size().

Referenced by setAdultTable(), and setOffsprgTable().

+ Here is the caller graph for this function:

◆ setOffsprgTable()

void LCE_SelectionSH::setOffsprgTable ( )
inline

References OFFSPRG, and setDataTable().

Referenced by addMeanPerPatch(), and addVarPerPatch().

+ Here is the caller graph for this function:

◆ setStatRecorders()

bool LCE_SelectionSH::setStatRecorders ( string &  token)
virtual

Implements StatHandlerBase.

1146{
1147 string age_tag = token.substr(0,token.find_first_of("."));
1148 string sub_token;
1149 age_t AGE = ALL;
1150
1151 if (age_tag.size() != 0 && age_tag.size() != string::npos) {
1152
1153 if (age_tag == "adlt") AGE = ADULTS;
1154
1155 else if (age_tag == "off") AGE = OFFSPRG;
1156
1157 else age_tag = "";
1158
1159 } else {
1160 age_tag = "";
1161 }
1162
1163 if (age_tag.size() != 0)
1164 sub_token = token.substr(token.find_first_of(".") + 1, string::npos);
1165 else
1166 sub_token = token;
1167
1168 if(sub_token == "fitness") {
1169 add("Mean population fitness","fitness.mean",ALL,0,0,&LCE_SelectionSH::getMeanFitness,0,0,0);
1170 add("Mean population fitness","fitness.outb",ALL,0,0,0,&LCE_SelectionSH::getFitness,0,0);
1171 add("Mean population fitness","fitness.outw",ALL,1,0,0,&LCE_SelectionSH::getFitness,0,0);
1172 add("Mean population fitness","fitness.hsib",ALL,2,0,0,&LCE_SelectionSH::getFitness,0,0);
1173 add("Mean population fitness","fitness.fsib",ALL,3,0,0,&LCE_SelectionSH::getFitness,0,0);
1174 add("Mean population fitness","fitness.self",ALL,4,0,0,&LCE_SelectionSH::getFitness,0,0);
1175 } else if(sub_token == "survival") {
1176 add("Mean offspring survival","survival.outb",ALL,0,0,0,&LCE_SelectionSH::getSurvival,0,0);
1177 add("Mean offspring survival","survival.outw",ALL,1,0,0,&LCE_SelectionSH::getSurvival,0,0);
1178 add("Mean offspring survival","survival.hsib",ALL,2,0,0,&LCE_SelectionSH::getSurvival,0,0);
1179 add("Mean offspring survival","survival.fsib",ALL,3,0,0,&LCE_SelectionSH::getSurvival,0,0);
1180 add("Mean offspring survival","survival.self",ALL,4,0,0,&LCE_SelectionSH::getSurvival,0,0);
1181 } else if(sub_token == "fitness.prop") {
1182 add("Proportion of b/n demes outbreds","prop.outb",ALL,0,0,0,&LCE_SelectionSH::getPedProp,0,0);
1183 add("Proportion of w/n demes outbreds","prop.outw",ALL,1,0,0,&LCE_SelectionSH::getPedProp,0,0);
1184 add("Proportion of half-sib crossings","prop.hsib",ALL,2,0,0,&LCE_SelectionSH::getPedProp,0,0);
1185 add("Proportion of full-sib crossings","prop.fsib",ALL,3,0,0,&LCE_SelectionSH::getPedProp,0,0);
1186 add("Proportion of selfed progeny","prop.self",ALL,4,0,0,&LCE_SelectionSH::getPedProp,0,0);
1187
1188 } else if(sub_token == "fitness.patch") {
1189
1190 addMeanPerPatch(AGE);
1191
1192 } else if(sub_token == "fitness.var.patch") {
1193
1194 addVarPerPatch(AGE);
1195
1196 } else return false;
1197
1198 return true;
1199}
double getSurvival(unsigned int i)
Definition: LCEselection.h:320
double getMeanFitness()
Definition: LCEselection.h:318
double getPedProp(unsigned int i)
Definition: LCEselection.h:321
double getFitness(unsigned int i)
Definition: LCEselection.h:319
unsigned int age_t
Age class flags.
Definition: types.h:46

References StatHandler< SH >::add(), addMeanPerPatch(), addVarPerPatch(), ADULTS, ALL, getFitness(), getMeanFitness(), getPedProp(), getSurvival(), and OFFSPRG.

Member Data Documentation

◆ _phenoTable

vector< vector< double > > LCE_SelectionSH::_phenoTable
private

◆ _table_set_age

unsigned int LCE_SelectionSH::_table_set_age
private

Referenced by setDataTable().

◆ _table_set_gen

unsigned int LCE_SelectionSH::_table_set_gen
private

Referenced by setDataTable().

◆ _table_set_repl

unsigned int LCE_SelectionSH::_table_set_repl
private

Referenced by setDataTable().


The documentation for this class was generated from the following files:

Generated for Nemo v2.3.56 by  doxygen 1.9.0 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR