Nemo  2.4.2
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
362  :
364  _table_set_gen(999999), _table_set_age(999999), _table_set_repl(999999)
365  {}
unsigned int _table_set_age
Definition: LCEselection.h:358
unsigned int _table_set_repl
Definition: LCEselection.h:358
unsigned int _table_set_gen
Definition: LCEselection.h:358

◆ ~LCE_SelectionSH()

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

Member Function Documentation

◆ addMeanPerPatch()

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

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

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
379 {return _SHLinkedEvent->_fitness[i];}
LCE_Selection_base * _SHLinkedEvent
Pointer to the linked LCE.
Definition: stathandler.h:191
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:116

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

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

References _phenoTable.

◆ getMeanPatchFitness() [2/2]

double LCE_SelectionSH::getMeanPatchFitness ( unsigned int  i,
unsigned int  int_agex 
)
1779 {
1780  age_idx age = static_cast<age_idx> (int_agex);
1781  unsigned int patch_size = _pop->getPatchPtr(i)->size(age);
1782 
1783  assert(patch_size == _phenoTable[i].size());
1784 
1785  if(patch_size == 0) return (nanf("NULL"));
1786 
1787  return getMeanPatchFitness(i);
1788 }
Patch * getPatchPtr(unsigned int patch)
A secure version of the getPatch() method.
Definition: metapop.h:258
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, 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
381 {return _SHLinkedEvent->_ind_cntr[i];}
double _ind_cntr[5]
Definition: LCEselection.h:116

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

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

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

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)
1708 {
1709  if(_table_set_age == AGE
1712  ) return;
1713 
1714  unsigned int patchNbr = _pop->getPatchNbr();
1715 
1716  if(_phenoTable.size() != patchNbr) {
1717  if(_phenoTable.size() < patchNbr) {
1718  while (_phenoTable.size() < patchNbr)
1719  _phenoTable.push_back(vector<double>());
1720  } else {
1721  while (_phenoTable.size() > patchNbr) {
1722  _phenoTable.pop_back();
1723  }
1724  }
1725  }
1726 
1727  for(unsigned int i = 0; i < patchNbr; ++i) {
1728  _phenoTable[i].assign(_pop->size(AGE, i),0);
1729  }
1730 
1731  Patch* patch;
1732 
1733  age_idx age = (AGE == ADULTS ? ADLTx : OFFSx);
1734 
1735  for(unsigned int i = 0, n; i < patchNbr; i++) {
1736 
1737 
1738  patch = _pop->getPatch(i);
1739 
1740 
1741  if( !_SHLinkedEvent->_is_absolute ) {
1744  else
1746  }
1747 
1748  n = 0;
1749 
1750  for(unsigned int j = 0, size = patch->size(FEM, age);
1751  j < size && n < _phenoTable[i].size();
1752  j++)
1753  {
1754  _phenoTable[i][n++] = _SHLinkedEvent->getFitness( patch->get(FEM, age, j), i);
1755  }
1756 
1757  for(unsigned int j = 0, size = patch->size(MAL, age);
1758  j < size && n < _phenoTable[i].size();
1759  j++)
1760  {
1761  _phenoTable[i][n++] = _SHLinkedEvent->getFitness( patch->get(MAL, age, j), i);
1762  }
1763 
1764 
1765  if (n != _phenoTable[i].size()) {
1766  fatal("problem while recording fitness trait values; size counter doesn't match table size.\n");
1767  }
1768  }
1769 
1770  _table_set_age = AGE;
1773 
1774 }
bool _is_absolute
Definition: LCEselection.h:113
bool _is_local
Definition: LCEselection.h:112
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:228
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:1240
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:1232
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
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:255
unsigned int getCurrentGeneration()
Definition: metapop.h:294
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:98
@ FEM
Definition: types.h:35
@ MAL
Definition: types.h:35

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.

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

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.2 by  doxygen 1.9.1

Catalogued on GSR