Nemo  2.4.2
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCEselection.h
Go to the documentation of this file.
1 
28 #ifndef LCE_SELECTION_H
29 #define LCE_SELECTION_H
30 
31 #include <cmath>
32 #include "lifecycleevent.h"
33 #include "filehandler.h"
34 #ifdef HAS_GSL
35 #include <gsl/gsl_vector.h>
36 #include <gsl/gsl_matrix.h>
37 #endif
38 
39 class LCE_SelectionSH;
40 class LCE_SelectionFH;
41 //CLASS LCE_Selection_base
42 //
48 class LCE_Selection_base : public virtual LifeCycleEvent
49 {
52 
53  vector< TMatrix* > _selection_matrix;
54  vector< gsl_matrix* > _gsl_selection_matrix;
55  gsl_vector *_diffs,
63 
65  //double *_phe; // do we need this here?
66 
68 
72  vector<double> _mean_trait_value;
73  unsigned int _linearSelTraitIndex;
76 
81 
87 
90 
91  double _letheq;
92 
94  double _Fpedigree[5];
95 
98  double _FitnessFixModel[5];
99 
101 
102 
104  friend class LCE_SelectionSH;
105  friend class LCE_SelectionFH;
106  friend class LCE_Breed_Selection;
107 
108 protected:
109 
112  bool _is_local,
114 
116  double _fitness[5], _survival[5], _ind_cntr[5];
117 
120 
123 
125  vector<unsigned int> _selectTraitMapping;
126 
128  vector< double > _selection_variance;
129 
131  double _eVariance;
133 
135  vector< string > _Traits;
136 
138  vector< unsigned int > _TraitIndices;
139 
141  vector< string > _SelectionModels;
142 
145 
146  vector< double (LCE_Selection_base::* ) (Individual*, unsigned int, unsigned int) > _getRawFitness;
147 
150  double (LCE_Selection_base::* _getFitness) (Individual*, unsigned int);
151 
155  void (LCE_Selection_base::* _setScalingFactor) (age_idx, unsigned int);
156 
160 
162 
165 
166 public:
167 
168  LCE_Selection_base ( );
169 
170  virtual ~LCE_Selection_base ( );
171 
172  bool setSelectionMatrix();
173  bool setSelectTraitMapping(unsigned int num_quanti_traits);
174  bool setSelectionOffset(double default_val, double min_val);
175  bool setLocalOptima ();
176  const TMatrix& getLocalOptima () const {return _local_optima;}
177  bool set_sel_model ();
178  bool set_fit_model ();
179  bool set_local_optima ();
181 
182  void set_std_rate_of_change();
183  void addPhenotypicSD (unsigned int deme, double *stDev);
184  void changeLocalOptima ();
185 
187  void resetCounters ();
188 
192  void setMeans (unsigned int tot_ind);
193 
199  void updateFitnessCounters (double fitness, unsigned int ped_class, bool survived);
200 
203  double getMeanFitness (age_idx age);
204 
208  double getMeanPatchFitness (age_idx age, unsigned int p);
209 
212  double getMaxFitness (age_idx age);
213 
217  double getMaxPatchFitness (age_idx age, unsigned int p);
218 
219 
222  double setMeanFitness (age_idx age) { return (_mean_fitness = getMeanFitness(age));}
223 
228  double getFitness (Individual* ind, unsigned int patch)
229  {
230  return (this->*_getFitness)(ind, patch);
231  }
232 
234  double getFitnessFixedEffect (Individual* offsprg, unsigned int patch, unsigned int trait)
235  {
236  return _FitnessFixModel[ offsprg->getPedigreeClass() ];
237  }
238 
240  double getFitnessDirect (Individual* offsprg, unsigned int patch, unsigned int trait)
241  {
242  return *(double*)offsprg->getTraitValue(trait);
243  }
245  double getFitnessUnivariateQuadratic ( Individual* ind, unsigned int patch, unsigned int trait);
246 
248  double getFitnessUnivariateLinear (Individual* offsprg, unsigned int patch, unsigned int trait);
249 
251  double getFitnessUnivariateDisruptive (Individual* offsprg, unsigned int patch, unsigned int trait);
252 
254  double getFitnessMultivariateDisruptive (Individual* offsprg, unsigned int patch, unsigned int trait);
255 
258  double getFitnessTruncation (Individual* offsprg, unsigned int patch, unsigned int trait);
259 
261  double getFitnessMultivariateGaussian (Individual* offsprg, unsigned int patch, unsigned int trait);
262 
264  double getFitnessUnivariateGaussian (Individual* offsprg, unsigned int patch, unsigned int trait);
265 
267  double getFitnessMultivariateGaussian_VE (Individual* offsprg, unsigned int patch, unsigned int trait);
268 
270  double getFitnessUnivariateGaussian_VE (Individual* offsprg, unsigned int patch, unsigned int trait);
271 
272 
277  double getFitnessAbsolute (Individual* ind, unsigned int patch);
278 
286  double getFitnessRelative (Individual* ind, unsigned int patch)
287  {
288  return getFitnessAbsolute(ind, patch) * _scaling_factor;
289  }
290 
294  void setScalingFactorLocal (age_idx age, unsigned int p);
295 
301  void setScalingFactorGlobal (age_idx age, unsigned int p);
302 
306  void setScalingFactorMaxLocal (age_idx age, unsigned int p);
307 
313  void setScalingFactorMaxGlobal (age_idx age, unsigned int p);
314 
319  void setScalingFactorForLinearSelection (age_idx age, unsigned int p);
320 
324  void setScalingFactorAbsolute (age_idx age, unsigned int p) { _scaling_factor = 1; }
325 
333  void doViabilitySelection (sex_t SEX, age_idx AGE, Patch* patch, unsigned int p);
334 
336  void checkChangeLocalOptima();
337 
340  virtual bool setParameters ();
341  virtual void execute ();
342  virtual void loadStatServices (StatServices* loader);
343  virtual void loadFileServices (FileServices* loader);
344  virtual bool resetParameterFromSource (std::string param, SimComponent* cmpt) {return false;}
345  virtual LifeCycleEvent* clone () {return new LCE_Selection_base();}
346  virtual age_t removeAgeClass () {return NONE;}
347  virtual age_t addAgeClass () {return NONE;}
348  virtual age_t requiredAgeClass () {return OFFSPRG;}
350 };
351 
352 
354 class LCE_SelectionSH : public EventStatHandler< LCE_Selection_base, LCE_SelectionSH >
355 {
356 
357  vector< vector< double > > _phenoTable;
359 
360 public:
361 
364  _table_set_gen(999999), _table_set_age(999999), _table_set_repl(999999)
365  {}
366 
367  virtual ~LCE_SelectionSH() {}
368 
369  virtual bool setStatRecorders (string& token);
370 
371  void addMeanPerPatch (age_t AGE);
372  void addVarPerPatch (age_t AGE);
373  void setDataTable (age_t AGE);
376 
377 
379  double getFitness (unsigned int i) {return _SHLinkedEvent->_fitness[i];}
380  double getSurvival (unsigned int i) {return _SHLinkedEvent->_survival[i];}
381  double getPedProp (unsigned int i) {return _SHLinkedEvent->_ind_cntr[i];}
382  double getMeanPatchFitness (unsigned int i, unsigned int int_agex);
383  double getMeanPatchFitness (unsigned int i);
384  double getVarPatchFitness (unsigned int i, unsigned int int_agex);
385 };
386 
387 class LCE_SelectionFH : public virtual EventFileHandler< LCE_Selection_base >
388 {
389 
390  public:
391 
393 
394  virtual ~LCE_SelectionFH() {}
395 
396  virtual void FHwrite();
397 
398  virtual void FHread(string& filename) {}
399 
400  void print(ofstream& FH, sex_t SEX, age_idx AGE, unsigned int i, Patch* patch, unsigned int ntraits);
401 };
402 
403 
404 #endif
405 
Template class for the LCEs StatHandler classes.
Definition: filehandler.h:256
Template class for the LCEs StatHandler classes.
Definition: stathandler.h:188
LCE_Selection_base * _SHLinkedEvent
Pointer to the linked LCE.
Definition: stathandler.h:191
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:50
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:47
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:269
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:177
Composite LCE implementing breeding and viability selection on a given trait type.
Definition: LCEcomposite.h:241
Definition: LCEselection.h:388
virtual void FHwrite()
Definition: LCEselection.cc:1827
LCE_SelectionFH(LCE_Selection_base *event)
Definition: LCEselection.h:392
virtual void FHread(string &filename)
Definition: LCEselection.h:398
void print(ofstream &FH, sex_t SEX, age_idx AGE, unsigned int i, Patch *patch, unsigned int ntraits)
Definition: LCEselection.cc:1866
virtual ~LCE_SelectionFH()
Definition: LCEselection.h:394
StatHandler class for the LCE_Selection class.
Definition: LCEselection.h:355
double getVarPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1805
double getSurvival(unsigned int i)
Definition: LCEselection.h:380
unsigned int _table_set_age
Definition: LCEselection.h:358
double getMeanPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1778
void addVarPerPatch(age_t AGE)
Definition: LCEselection.cc:1673
unsigned int _table_set_repl
Definition: LCEselection.h:358
void setOffsprgTable()
Definition: LCEselection.h:375
double getMeanFitness()
Definition: LCEselection.h:378
void setAdultTable()
Definition: LCEselection.h:374
vector< vector< double > > _phenoTable
Definition: LCEselection.h:357
virtual ~LCE_SelectionSH()
Definition: LCEselection.h:367
virtual bool setStatRecorders(string &token)
Definition: LCEselection.cc:1581
void addMeanPerPatch(age_t AGE)
Definition: LCEselection.cc:1639
double getPedProp(unsigned int i)
Definition: LCEselection.h:381
double getFitness(unsigned int i)
Definition: LCEselection.h:379
unsigned int _table_set_gen
Definition: LCEselection.h:358
LCE_SelectionSH(LCE_Selection_base *event)
Definition: LCEselection.h:362
void setDataTable(age_t AGE)
Definition: LCEselection.cc:1707
Base class performing (viability) selection on an arbitrary trait.
Definition: LCEselection.h:49
double getFitnessUnivariateGaussian_VE(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following the Gaussian selection model with several traits under...
Definition: LCEselection.cc:1113
double getFitnessMultivariateDisruptive(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with ...
Definition: LCEselection.cc:1018
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:122
double getFitnessRelative(Individual *ind, unsigned int patch)
Returns the relative fitness of the individual, adjusted by a scaling factor.
Definition: LCEselection.h:286
bool setSelectionMatrix()
Definition: LCEselection.cc:665
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:116
double _base_fitness
Definition: LCEselection.h:110
double(LCE_Selection_base::* _getFitness)(Individual *, unsigned int)
Pointer to the function returning the individual fitness.
Definition: LCEselection.h:150
const TMatrix & getLocalOptima() const
Definition: LCEselection.h:176
virtual void loadFileServices(FileServices *loader)
Definition: LCEselection.cc:151
double getFitnessFixedEffect(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual in the fixed selection model.
Definition: LCEselection.h:234
double getFitnessDirect(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following the direct selection model.
Definition: LCEselection.h:240
void setScalingFactorAbsolute(age_idx age, unsigned int p)
Resets the fitness scaling factor equal to one.
Definition: LCEselection.h:324
double _max_fitness
Definition: LCEselection.h:111
double _FitnessFixModel[5]
Absolute fitness values of the five pedigree class for the fixed selection model (lethal equivalents ...
Definition: LCEselection.h:98
double getMeanFitness(age_idx age)
Computes the mean fitness of the whole population for a given age class.
Definition: LCEselection.cc:1162
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:54
double getFitnessUnivariateQuadratic(Individual *ind, unsigned int patch, unsigned int trait)
Quadratic fitness surface, approximates the Gaussian model for weak selection and/or small deviation ...
Definition: LCEselection.cc:1058
double getFitnessTruncation(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following a Truncation selection model.
Definition: LCEselection.cc:1037
void addPhenotypicSD(unsigned int deme, double *stDev)
Definition: LCEselection.cc:1528
void setScalingFactorMaxGlobal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the maximum population fitness value.
Definition: LCEselection.cc:1258
TMatrix _selection_offset
Definition: LCEselection.h:79
void doViabilitySelection(sex_t SEX, age_idx AGE, Patch *patch, unsigned int p)
Selectively removes individuals in the population depending on their fitness.
Definition: LCEselection.cc:1374
vector< double > _selection_variance
Patch-specific selection variance.
Definition: LCEselection.h:128
LCE_SelectionFH * _writer
Definition: LCEselection.h:164
unsigned int _linearSelTraitIndex
Definition: LCEselection.h:73
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:138
gsl_vector * _diffs
Definition: LCEselection.h:55
bool set_param_rate_of_change()
Definition: LCEselection.cc:903
void(LCE_Selection_base::* _setScalingFactor)(age_idx, unsigned int)
Pointer to the function used to set the fitness scaling factor when fitness is relative.
Definition: LCEselection.h:155
bool _is_absolute
Definition: LCEselection.h:113
double getMaxFitness(age_idx age)
Computes the maximum fitness value of the whole population for a given age class.
Definition: LCEselection.cc:1196
double _eVariance
Evironmental variance.
Definition: LCEselection.h:131
void setScalingFactorMaxLocal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the maximum local patch fitness value.
Definition: LCEselection.cc:1250
TMatrix _rate_of_change_local_optima
Definition: LCEselection.h:58
vector< double > _mean_trait_value
Definition: LCEselection.h:72
double _scaling_factor
Definition: LCEselection.h:111
bool _do_change_local_opt
Definition: LCEselection.h:59
bool _is_local
Definition: LCEselection.h:112
TMatrix _truncation_threshold
Definition: LCEselection.h:84
double getMeanPatchFitness(age_idx age, unsigned int p)
Computes the mean fitness in a given patch for a given age class.
Definition: LCEselection.cc:1180
void checkChangeLocalOptima()
Check is rate of change in local optima has been set and must be applied.
Definition: LCEselection.cc:1321
virtual age_t addAgeClass()
Definition: LCEselection.h:347
virtual void execute()
Definition: LCEselection.cc:1340
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:228
void setMeans(unsigned int tot_ind)
Computes the average fitness of each pedigree class.
Definition: LCEselection.cc:1416
virtual ~LCE_Selection_base()
Definition: LCEselection.cc:125
bool setSelectionOffset(double default_val, double min_val)
Definition: LCEselection.cc:828
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.cc:1405
double getFitnessMultivariateGaussian_VE(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following the Gaussian selection model with one trait under sele...
Definition: LCEselection.cc:1129
gsl_vector * _res1
Definition: LCEselection.h:56
bool set_sel_model()
Definition: LCEselection.cc:316
double getFitnessMultivariateGaussian(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following the Gaussian selection model with one trait under sele...
Definition: LCEselection.cc:1093
virtual age_t removeAgeClass()
Definition: LCEselection.h:346
double _ind_cntr[5]
Definition: LCEselection.h:116
virtual bool setParameters()
Definition: LCEselection.cc:190
unsigned int _set_std_rate_at_generation
Definition: LCEselection.h:61
double _mean_fitness
Definition: LCEselection.h:111
bool set_fit_model()
Definition: LCEselection.cc:258
virtual bool resetParameterFromSource(std::string param, SimComponent *cmpt)
Definition: LCEselection.h:344
LCE_Selection_base()
Definition: LCEselection.cc:44
LCE_SelectionSH * _stater
Definition: LCEselection.h:163
vector< unsigned int > _selectTraitMapping
Mapping from selection dimension index to quanti trait index (0-based).
Definition: LCEselection.h:125
void setScalingFactorForLinearSelection(age_idx age, unsigned int p)
Sets the fitness scaling factor as the mean trait value in the patch to compute the fitness value in ...
Definition: LCEselection.cc:1267
int _std_rate_reference_patch
Definition: LCEselection.h:62
TMatrix _linear_selection_strength
Definition: LCEselection.h:71
void changeLocalOptima()
Definition: LCEselection.cc:1311
void(LCE_Selection_base::* _setNewLocalOptima)(void)
Pointer to the function used to change the local phenotypic optima or its rate of change.
Definition: LCEselection.h:159
double _Fpedigree[5]
Array of pedigree values used in the fixed-selection model.
Definition: LCEselection.h:94
TMatrix _local_optima
Definition: LCEselection.h:57
bool setSelectTraitMapping(unsigned int num_quanti_traits)
Definition: LCEselection.cc:619
vector< double(LCE_Selection_base::*)(Individual *, unsigned int, unsigned int) > _getRawFitness
A vector containing pointers to fitness function related to each trait under selection.
Definition: LCEselection.h:146
bool _truncation_upper
Definition: LCEselection.h:85
bool set_local_optima()
Definition: LCEselection.cc:864
double _letheq
Definition: LCEselection.h:91
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
double getMaxPatchFitness(age_idx age, unsigned int p)
Computes the maximum fitness value in a given patch for a given age class.
Definition: LCEselection.cc:1212
vector< TMatrix * > _selection_matrix
Definition: LCEselection.h:53
vector< string > _SelectionModels
The selection models associated with each trait under selection.
Definition: LCEselection.h:141
bool _rate_of_change_is_std
Definition: LCEselection.h:60
virtual LifeCycleEvent * clone()
Definition: LCEselection.h:345
double getFitnessUnivariateLinear(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following a Linear selection model with a single trait under sel...
Definition: LCEselection.cc:989
virtual age_t requiredAgeClass()
Definition: LCEselection.h:348
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
double _survival[5]
Definition: LCEselection.h:116
vector< string > _Traits
The list of trait types under selection.
Definition: LCEselection.h:135
double getFitnessAbsolute(Individual *ind, unsigned int patch)
Returns the raw fitness of the individual, without adjustment (absolute fitness).
Definition: LCEselection.cc:1150
age_idx _linearSelAgeClass
Definition: LCEselection.h:74
virtual void loadStatServices(StatServices *loader)
Definition: LCEselection.cc:143
void set_std_rate_of_change()
Definition: LCEselection.cc:1444
double setMeanFitness(age_idx age)
Sets the _mean_fitness variable to the value of the mean population fitness.
Definition: LCEselection.h:222
double getFitnessUnivariateGaussian(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following the Gaussian selection model with several traits under...
Definition: LCEselection.cc:1078
void updateFitnessCounters(double fitness, unsigned int ped_class, bool survived)
Updates the fitness and survival mean counters.
Definition: LCEselection.cc:1432
double getFitnessUnivariateDisruptive(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with ...
Definition: LCEselection.cc:1006
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:71
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:430
Interface to all basic components of a simulation (traits, life cycle events, pop,...
Definition: simcomponent.h:43
The Service class used to manage the StatHandler objects.
Definition: statservices.h:48
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:48
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:34
#define NONE
No age flag.
Definition: types.h:46
unsigned int age_t
Age class flags.
Definition: types.h:44
#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

Generated for Nemo v2.4.2 by  doxygen 1.9.1

Catalogued on GSR