Nemo  2.4.0b
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 ~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
337  :
339  _table_set_gen(999999), _table_set_age(999999), _table_set_repl(999999)
340  {}
unsigned int _table_set_age
Definition: LCEselection.h:333
unsigned int _table_set_repl
Definition: LCEselection.h:333
unsigned int _table_set_gen
Definition: LCEselection.h:333

◆ ~LCE_SelectionSH()

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

Member Function Documentation

◆ addMeanPerPatch()

void LCE_SelectionSH::addMeanPerPatch ( age_t  AGE)
1424 {
1425  unsigned int patchNbr = _pop->getPatchNbr();
1426 
1427  if (AGE == ALL) {
1430  return;
1431  }
1432 
1433  string suffix = (AGE == ADULTS ? "adlt.":"off."); //at this stage, AGE != ALL
1434  string name = suffix + "W.avg.p";
1435  string long_name = "Mean fitness in patch ";
1436  string patch;
1437 
1438  void (LCE_SelectionSH::* setter) (void) = (AGE == ADULTS ?
1441 
1442  unsigned int int_agex = static_cast<age_idx> ((AGE == ADULTS ? ADLTx : OFFSx));
1443 
1444  //first patch, gets the data table setter:
1445  add(long_name + "1", name + "1", AGE, 0, int_agex,
1447 
1448  for(unsigned int p = 1; p < patchNbr; p++) {
1449  patch = tstring::int2str(p+1);
1450  add(long_name + patch, name + patch, AGE, p, int_agex,
1452  }
1453 }
StatHandler class for the LCE_Selection class.
Definition: LCEselection.h:330
double getMeanPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1562
void setOffsprgTable()
Definition: LCEselection.h:350
void setAdultTable()
Definition: LCEselection.h:349
void addMeanPerPatch(age_t AGE)
Definition: LCEselection.cc:1423
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(), ADLTx, ADULTS, ALL, getMeanPatchFitness(), Metapop::getPatchNbr(), tstring::int2str(), OFFSPRG, OFFSx, setAdultTable(), and setOffsprgTable().

Referenced by setStatRecorders().

◆ addVarPerPatch()

void LCE_SelectionSH::addVarPerPatch ( age_t  AGE)
1458 {
1459  unsigned int patchNbr = _pop->getPatchNbr();
1460 
1461  if (AGE == ALL) {
1464  return;
1465  }
1466 
1467  string suffix = (AGE == ADULTS ? "adlt.":"off."); //at this stage, AGE != ALL
1468  string name = suffix + "W.var.p";
1469  string long_name = "Var fitness in patch ";
1470  string patch;
1471 
1472  void (LCE_SelectionSH::* setter) (void) = (AGE == ADULTS ?
1475 
1476  unsigned int int_agex = static_cast<age_idx> ((AGE == ADULTS ? ADLTx : OFFSx));
1477 
1478  //first patch, gets the data table setter:
1479  add(long_name + "1", name + "1", AGE, 0, int_agex,
1481 
1482  for(unsigned int p = 1; p < patchNbr; p++) {
1483  patch = tstring::int2str(p+1);
1484  add(long_name + patch, name + patch, AGE, p, int_agex,
1486  }
1487 }
double getVarPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1589
void addVarPerPatch(age_t AGE)
Definition: LCEselection.cc:1457

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

Referenced by setStatRecorders().

◆ getFitness()

double LCE_SelectionSH::getFitness ( unsigned int  i)
inline
354 {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:106

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

Referenced by setStatRecorders().

◆ getMeanFitness()

double LCE_SelectionSH::getMeanFitness ( )
inline

◆ getMeanPatchFitness() [1/2]

double LCE_SelectionSH::getMeanPatchFitness ( unsigned int  i)
1577 {
1578  double mean = 0;
1579  unsigned int size = _phenoTable[i].size();
1580 
1581  for(unsigned int j = 0; j < size; j++)
1582  mean += _phenoTable[i][j];
1583 
1584  return mean/size;
1585 }
vector< vector< double > > _phenoTable
Definition: LCEselection.h:332

References _phenoTable.

◆ getMeanPatchFitness() [2/2]

double LCE_SelectionSH::getMeanPatchFitness ( unsigned int  i,
unsigned int  int_agex 
)
1563 {
1564  age_idx age = static_cast<age_idx> (int_agex);
1565  unsigned int patch_size = _pop->getPatchPtr(i)->size(age);
1566 
1567  assert(patch_size == _phenoTable[i].size());
1568 
1569  if(patch_size == 0) return (nanf("NULL"));
1570 
1571  return getMeanPatchFitness(i);
1572 }
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:498

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

Referenced by addMeanPerPatch(), and getVarPatchFitness().

◆ getPedProp()

double LCE_SelectionSH::getPedProp ( unsigned int  i)
inline

◆ getSurvival()

double LCE_SelectionSH::getSurvival ( unsigned int  i)
inline

◆ getVarPatchFitness()

double LCE_SelectionSH::getVarPatchFitness ( unsigned int  i,
unsigned int  int_agex 
)
1590 {
1591  age_idx age = static_cast<age_idx> (int_agex);
1592  unsigned int patch_size = _pop->getPatchPtr(i)->size(age);
1593 
1594  assert(patch_size == _phenoTable[i].size());
1595 
1596  if(patch_size == 0) return nanf("NULL");
1597 
1598  double mean = getMeanPatchFitness(i);
1599  double var = 0;
1600 
1601  for(unsigned int j = 0; j < patch_size; j++) {
1602 
1603  var += pow(_phenoTable[i][j] - mean, 2.0);
1604  }
1605 
1606  return var/patch_size;
1607 }

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

Referenced by addVarPerPatch().

◆ setAdultTable()

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

References ADULTS, and setDataTable().

Referenced by addMeanPerPatch(), and addVarPerPatch().

◆ setDataTable()

void LCE_SelectionSH::setDataTable ( age_t  AGE)
1492 {
1493  if(_table_set_age == AGE
1496  ) return;
1497 
1498  unsigned int patchNbr = _pop->getPatchNbr();
1499 
1500  if(_phenoTable.size() != patchNbr) {
1501  if(_phenoTable.size() < patchNbr) {
1502  while (_phenoTable.size() < patchNbr)
1503  _phenoTable.push_back(vector<double>());
1504  } else {
1505  while (_phenoTable.size() > patchNbr) {
1506  _phenoTable.pop_back();
1507  }
1508  }
1509  }
1510 
1511  for(unsigned int i = 0; i < patchNbr; ++i) {
1512  _phenoTable[i].assign(_pop->size(AGE, i),0);
1513  }
1514 
1515  Patch* patch;
1516 
1517  age_idx age = (AGE == ADULTS ? ADLTx : OFFSx);
1518 
1519  for(unsigned int i = 0, n; i < patchNbr; i++) {
1520 
1521 
1522  patch = _pop->getPatch(i);
1523 
1524 
1525  if( !_SHLinkedEvent->_is_absolute ) {
1528  else
1530  }
1531 
1532  n = 0;
1533 
1534  for(unsigned int j = 0, size = patch->size(FEM, age);
1535  j < size && n < _phenoTable[i].size();
1536  j++)
1537  {
1538  _phenoTable[i][n++] = _SHLinkedEvent->getFitness( patch->get(FEM, age, j), i);
1539  }
1540 
1541  for(unsigned int j = 0, size = patch->size(MAL, age);
1542  j < size && n < _phenoTable[i].size();
1543  j++)
1544  {
1545  _phenoTable[i][n++] = _SHLinkedEvent->getFitness( patch->get(MAL, age, j), i);
1546  }
1547 
1548 
1549  if (n != _phenoTable[i].size()) {
1550  fatal("problem while recording fitness trait values; size counter doesn't match table size.\n");
1551  }
1552  }
1553 
1554  _table_set_age = AGE;
1557 
1558 }
bool _is_absolute
Definition: LCEselection.h:103
bool _is_local
Definition: LCEselection.h:102
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:213
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:1023
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:1015
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:312
unsigned int getCurrentReplicate()
Definition: metapop.h:295
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
unsigned int getCurrentGeneration()
Definition: metapop.h:296
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
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:534
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().

◆ setOffsprgTable()

void LCE_SelectionSH::setOffsprgTable ( )
inline

References OFFSPRG, and setDataTable().

Referenced by addMeanPerPatch(), and addVarPerPatch().

◆ setStatRecorders()

bool LCE_SelectionSH::setStatRecorders ( string &  token)
virtual

Implements StatHandlerBase.

1366 {
1367  string age_tag = token.substr(0,token.find_first_of("."));
1368  string sub_token;
1369  age_t AGE = ALL;
1370 
1371  if (age_tag.size() != 0 && age_tag.size() != string::npos) {
1372 
1373  if (age_tag == "adlt") AGE = ADULTS;
1374 
1375  else if (age_tag == "off") AGE = OFFSPRG;
1376 
1377  else age_tag = "";
1378 
1379  } else {
1380  age_tag = "";
1381  }
1382 
1383  if (age_tag.size() != 0)
1384  sub_token = token.substr(token.find_first_of(".") + 1, string::npos);
1385  else
1386  sub_token = token;
1387 
1388  if(sub_token == "fitness") {
1389  add("Mean population fitness","fitness.mean",ALL,0,0,&LCE_SelectionSH::getMeanFitness,0,0,0);
1390  add("Mean population fitness","fitness.outb",ALL,0,0,0,&LCE_SelectionSH::getFitness,0,0);
1391  add("Mean population fitness","fitness.outw",ALL,1,0,0,&LCE_SelectionSH::getFitness,0,0);
1392  add("Mean population fitness","fitness.hsib",ALL,2,0,0,&LCE_SelectionSH::getFitness,0,0);
1393  add("Mean population fitness","fitness.fsib",ALL,3,0,0,&LCE_SelectionSH::getFitness,0,0);
1394  add("Mean population fitness","fitness.self",ALL,4,0,0,&LCE_SelectionSH::getFitness,0,0);
1395  } else if(sub_token == "survival") {
1396  add("Mean offspring survival","survival.outb",ALL,0,0,0,&LCE_SelectionSH::getSurvival,0,0);
1397  add("Mean offspring survival","survival.outw",ALL,1,0,0,&LCE_SelectionSH::getSurvival,0,0);
1398  add("Mean offspring survival","survival.hsib",ALL,2,0,0,&LCE_SelectionSH::getSurvival,0,0);
1399  add("Mean offspring survival","survival.fsib",ALL,3,0,0,&LCE_SelectionSH::getSurvival,0,0);
1400  add("Mean offspring survival","survival.self",ALL,4,0,0,&LCE_SelectionSH::getSurvival,0,0);
1401  } else if(sub_token == "fitness.prop") {
1402  add("Proportion of b/n demes outbreds","prop.outb",ALL,0,0,0,&LCE_SelectionSH::getPedProp,0,0);
1403  add("Proportion of w/n demes outbreds","prop.outw",ALL,1,0,0,&LCE_SelectionSH::getPedProp,0,0);
1404  add("Proportion of half-sib crossings","prop.hsib",ALL,2,0,0,&LCE_SelectionSH::getPedProp,0,0);
1405  add("Proportion of full-sib crossings","prop.fsib",ALL,3,0,0,&LCE_SelectionSH::getPedProp,0,0);
1406  add("Proportion of selfed progeny","prop.self",ALL,4,0,0,&LCE_SelectionSH::getPedProp,0,0);
1407 
1408  } else if(sub_token == "fitness.patch") {
1409 
1410  addMeanPerPatch(AGE);
1411 
1412  } else if(sub_token == "fitness.var.patch") {
1413 
1414  addVarPerPatch(AGE);
1415 
1416  } else return false;
1417 
1418  return true;
1419 }
double getSurvival(unsigned int i)
Definition: LCEselection.h:355
double getMeanFitness()
Definition: LCEselection.h:353
double getPedProp(unsigned int i)
Definition: LCEselection.h:356
double getFitness(unsigned int i)
Definition: LCEselection.h:354
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.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR