Nemo  2.4.0
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
363  :
365  _table_set_gen(999999), _table_set_age(999999), _table_set_repl(999999)
366  {}
unsigned int _table_set_age
Definition: LCEselection.h:359
unsigned int _table_set_repl
Definition: LCEselection.h:359
unsigned int _table_set_gen
Definition: LCEselection.h:359

◆ ~LCE_SelectionSH()

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

Member Function Documentation

◆ addMeanPerPatch()

void LCE_SelectionSH::addMeanPerPatch ( age_t  AGE)
1641 {
1642  unsigned int patchNbr = _pop->getPatchNbr();
1643 
1644  if (AGE == ALL) {
1647  return;
1648  }
1649 
1650  string suffix = (AGE == ADULTS ? "adlt.":"off."); //at this stage, AGE != ALL
1651  string name = suffix + "W.avg.p";
1652  string long_name = "Mean fitness in patch ";
1653  string patch;
1654 
1655  void (LCE_SelectionSH::* setter) (void) = (AGE == ADULTS ?
1658 
1659  unsigned int int_agex = static_cast<age_idx> ((AGE == ADULTS ? ADLTx : OFFSx));
1660 
1661  //first patch, gets the data table setter:
1662  add(long_name + "1", name + "1", AGE, 0, int_agex,
1664 
1665  for(unsigned int p = 1; p < patchNbr; p++) {
1666  patch = tstring::int2str(p+1);
1667  add(long_name + patch, name + patch, AGE, p, int_agex,
1669  }
1670 }
StatHandler class for the LCE_Selection class.
Definition: LCEselection.h:356
double getMeanPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1779
void setOffsprgTable()
Definition: LCEselection.h:376
void setAdultTable()
Definition: LCEselection.h:375
void addMeanPerPatch(age_t AGE)
Definition: LCEselection.cc:1640
unsigned int getPatchNbr()
Definition: metapop.h:275
Metapop * _pop
Link to the current population, set through the link to the StatService.
Definition: stathandler.h:60
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:143
static string int2str(const int i)
Writes an integer value into a string.
Definition: tstring.h:94
#define ALL
All ages age class flag.
Definition: types.h:55
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:53
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:40
@ OFFSx
Definition: types.h:41
@ ADLTx
Definition: types.h:41

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

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ addVarPerPatch()

void LCE_SelectionSH::addVarPerPatch ( age_t  AGE)
1675 {
1676  unsigned int patchNbr = _pop->getPatchNbr();
1677 
1678  if (AGE == ALL) {
1681  return;
1682  }
1683 
1684  string suffix = (AGE == ADULTS ? "adlt.":"off."); //at this stage, AGE != ALL
1685  string name = suffix + "W.var.p";
1686  string long_name = "Var fitness in patch ";
1687  string patch;
1688 
1689  void (LCE_SelectionSH::* setter) (void) = (AGE == ADULTS ?
1692 
1693  unsigned int int_agex = static_cast<age_idx> ((AGE == ADULTS ? ADLTx : OFFSx));
1694 
1695  //first patch, gets the data table setter:
1696  add(long_name + "1", name + "1", AGE, 0, int_agex,
1698 
1699  for(unsigned int p = 1; p < patchNbr; p++) {
1700  patch = tstring::int2str(p+1);
1701  add(long_name + patch, name + patch, AGE, p, int_agex,
1703  }
1704 }
double getVarPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1806
void addVarPerPatch(age_t AGE)
Definition: LCEselection.cc:1674

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

Referenced by setStatRecorders().

+ Here is the caller graph for this function:

◆ getFitness()

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

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
379 {return _SHLinkedEvent->_mean_fitness;}
double _mean_fitness
Definition: LCEselection.h:112

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)
1794 {
1795  double mean = 0;
1796  unsigned int size = _phenoTable[i].size();
1797 
1798  for(unsigned int j = 0; j < size; j++)
1799  mean += _phenoTable[i][j];
1800 
1801  return mean/size;
1802 }
vector< vector< double > > _phenoTable
Definition: LCEselection.h:358

References _phenoTable.

◆ getMeanPatchFitness() [2/2]

double LCE_SelectionSH::getMeanPatchFitness ( unsigned int  i,
unsigned int  int_agex 
)
1780 {
1781  age_idx age = static_cast<age_idx> (int_agex);
1782  unsigned int patch_size = _pop->getPatchPtr(i)->size(age);
1783 
1784  assert(patch_size == _phenoTable[i].size());
1785 
1786  if(patch_size == 0) return (nanf("NULL"));
1787 
1788  return getMeanPatchFitness(i);
1789 }
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:259
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:497

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

Referenced by addMeanPerPatch(), and getVarPatchFitness().

+ Here is the caller graph for this function:

◆ getPedProp()

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

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
381 {return _SHLinkedEvent->_survival[i];}
double _survival[5]
Definition: LCEselection.h:117

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 
)
1807 {
1808  age_idx age = static_cast<age_idx> (int_agex);
1809  unsigned int patch_size = _pop->getPatchPtr(i)->size(age);
1810 
1811  assert(patch_size == _phenoTable[i].size());
1812 
1813  if(patch_size == 0) return nanf("NULL");
1814 
1815  double mean = getMeanPatchFitness(i);
1816  double var = 0;
1817 
1818  for(unsigned int j = 0; j < patch_size; j++) {
1819 
1820  var += pow(_phenoTable[i][j] - mean, 2.0);
1821  }
1822 
1823  return var/patch_size;
1824 }

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:1708

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)
1709 {
1710  if(_table_set_age == AGE
1713  ) return;
1714 
1715  unsigned int patchNbr = _pop->getPatchNbr();
1716 
1717  if(_phenoTable.size() != patchNbr) {
1718  if(_phenoTable.size() < patchNbr) {
1719  while (_phenoTable.size() < patchNbr)
1720  _phenoTable.push_back(vector<double>());
1721  } else {
1722  while (_phenoTable.size() > patchNbr) {
1723  _phenoTable.pop_back();
1724  }
1725  }
1726  }
1727 
1728  for(unsigned int i = 0; i < patchNbr; ++i) {
1729  _phenoTable[i].assign(_pop->size(AGE, i),0);
1730  }
1731 
1732  Patch* patch;
1733 
1734  age_idx age = (AGE == ADULTS ? ADLTx : OFFSx);
1735 
1736  for(unsigned int i = 0, n; i < patchNbr; i++) {
1737 
1738 
1739  patch = _pop->getPatch(i);
1740 
1741 
1742  if( !_SHLinkedEvent->_is_absolute ) {
1745  else
1747  }
1748 
1749  n = 0;
1750 
1751  for(unsigned int j = 0, size = patch->size(FEM, age);
1752  j < size && n < _phenoTable[i].size();
1753  j++)
1754  {
1755  _phenoTable[i][n++] = _SHLinkedEvent->getFitness( patch->get(FEM, age, j), i);
1756  }
1757 
1758  for(unsigned int j = 0, size = patch->size(MAL, age);
1759  j < size && n < _phenoTable[i].size();
1760  j++)
1761  {
1762  _phenoTable[i][n++] = _SHLinkedEvent->getFitness( patch->get(MAL, age, j), i);
1763  }
1764 
1765 
1766  if (n != _phenoTable[i].size()) {
1767  fatal("problem while recording fitness trait values; size counter doesn't match table size.\n");
1768  }
1769  }
1770 
1771  _table_set_age = AGE;
1774 
1775 }
bool _is_absolute
Definition: LCEselection.h:114
bool _is_local
Definition: LCEselection.h:113
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:229
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:1241
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:1233
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311
unsigned int getCurrentReplicate()
Definition: metapop.h:294
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:256
unsigned int getCurrentGeneration()
Definition: metapop.h:295
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
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:533
void fatal(const char *str,...)
Definition: output.cc:99
@ FEM
Definition: types.h:36
@ MAL
Definition: types.h:36

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.

1583 {
1584  string age_tag = token.substr(0,token.find_first_of("."));
1585  string sub_token;
1586  age_t AGE = ALL;
1587 
1588  if (age_tag.size() != 0 && age_tag.size() != string::npos) {
1589 
1590  if (age_tag == "adlt") AGE = ADULTS;
1591 
1592  else if (age_tag == "off") AGE = OFFSPRG;
1593 
1594  else age_tag = "";
1595 
1596  } else {
1597  age_tag = "";
1598  }
1599 
1600  if (age_tag.size() != 0)
1601  sub_token = token.substr(token.find_first_of(".") + 1, string::npos);
1602  else
1603  sub_token = token;
1604 
1605  if(sub_token == "fitness") {
1606  add("Mean population fitness","fitness.mean",ALL,0,0,&LCE_SelectionSH::getMeanFitness,0,0,0);
1607  add("Mean population fitness","fitness.outb",ALL,0,0,0,&LCE_SelectionSH::getFitness,0,0);
1608  add("Mean population fitness","fitness.outw",ALL,1,0,0,&LCE_SelectionSH::getFitness,0,0);
1609  add("Mean population fitness","fitness.hsib",ALL,2,0,0,&LCE_SelectionSH::getFitness,0,0);
1610  add("Mean population fitness","fitness.fsib",ALL,3,0,0,&LCE_SelectionSH::getFitness,0,0);
1611  add("Mean population fitness","fitness.self",ALL,4,0,0,&LCE_SelectionSH::getFitness,0,0);
1612  } else if(sub_token == "survival") {
1613  add("Mean offspring survival","survival.outb",ALL,0,0,0,&LCE_SelectionSH::getSurvival,0,0);
1614  add("Mean offspring survival","survival.outw",ALL,1,0,0,&LCE_SelectionSH::getSurvival,0,0);
1615  add("Mean offspring survival","survival.hsib",ALL,2,0,0,&LCE_SelectionSH::getSurvival,0,0);
1616  add("Mean offspring survival","survival.fsib",ALL,3,0,0,&LCE_SelectionSH::getSurvival,0,0);
1617  add("Mean offspring survival","survival.self",ALL,4,0,0,&LCE_SelectionSH::getSurvival,0,0);
1618  } else if(sub_token == "fitness.prop") {
1619  add("Proportion of b/n demes outbreds","prop.outb",ALL,0,0,0,&LCE_SelectionSH::getPedProp,0,0);
1620  add("Proportion of w/n demes outbreds","prop.outw",ALL,1,0,0,&LCE_SelectionSH::getPedProp,0,0);
1621  add("Proportion of half-sib crossings","prop.hsib",ALL,2,0,0,&LCE_SelectionSH::getPedProp,0,0);
1622  add("Proportion of full-sib crossings","prop.fsib",ALL,3,0,0,&LCE_SelectionSH::getPedProp,0,0);
1623  add("Proportion of selfed progeny","prop.self",ALL,4,0,0,&LCE_SelectionSH::getPedProp,0,0);
1624 
1625  } else if(sub_token == "fitness.patch") {
1626 
1627  addMeanPerPatch(AGE);
1628 
1629  } else if(sub_token == "fitness.var.patch") {
1630 
1631  addVarPerPatch(AGE);
1632 
1633  } else return false;
1634 
1635  return true;
1636 }
double getSurvival(unsigned int i)
Definition: LCEselection.h:381
double getMeanFitness()
Definition: LCEselection.h:379
double getPedProp(unsigned int i)
Definition: LCEselection.h:382
double getFitness(unsigned int i)
Definition: LCEselection.h:380
unsigned int age_t
Age class flags.
Definition: types.h:45

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.0 by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR