Nemo  2.3.46
LCEselection.h
Go to the documentation of this file.
1 
30 #ifndef LCE_SELECTION_H
31 #define LCE_SELECTION_H
32 
33 #include <cmath>
34 #include "lifecycleevent.h"
35 #include "filehandler.h"
36 #ifdef HAS_GSL
37 #include <gsl/gsl_vector.h>
38 #include <gsl/gsl_matrix.h>
39 #endif
40 
41 class LCE_SelectionSH;
42 class LCE_SelectionFH;
43 //CLASS LCE_Selection_base
44 //
50 class LCE_Selection_base : public virtual LifeCycleEvent
51 {
54 
55  vector< TMatrix* > _selection_matrix;
56  vector< gsl_matrix* > _gsl_selection_matrix;
57  gsl_vector *_diffs, *_res1;
64  double *_phe;
65 
67 
70 
72  double _Fpedigree[5];
73 
76  double _FitnessFixModel[5];
77 
79 
80 
82  friend class LCE_SelectionSH;
83  friend class LCE_SelectionFH;
84  friend class LCE_Breed_Selection;
85 
86 protected:
87 
92  double _fitness[5], _survival[5], _ind_cntr[5];
93 
96 
99 
101  vector< double > _selection_variance;
102 
104  double _eVariance;
106 
108  vector< unsigned int > _TraitIndices;
109 
111  vector< string > _SelectionModels;
112 
115 
116  vector< double (LCE_Selection_base::* ) (Individual*, unsigned int, unsigned int) > _getRawFitness;
117 
120  double (LCE_Selection_base::* _getFitness) (Individual*, unsigned int);
121 
126 
131 
134 
135 public:
136 
137  LCE_Selection_base ( );
138 
139  virtual ~LCE_Selection_base ( );
140 
141  bool setSelectionMatrix();
142  bool setLocalOptima ();
143  bool set_sel_model ();
144  bool set_fit_model ();
145  bool set_local_optima ();
147 
148  void set_std_rate_of_change();
149  void addPhenotypicSD (unsigned int deme, double *stDev);
150  void changeLocalOptima ();
151 
154  {
155  for(unsigned int i = 0; i < 5; i++) {
156  _fitness[i] = 0;
157  _survival[i] = 0;
158  _ind_cntr[i] = 0;
159  }
160  }
164  void setMeans (unsigned int tot_ind)
165  {
166  _mean_fitness = 0;
167  for(unsigned int i = 0; i < 5; i++) {
168  _mean_fitness += _fitness[i];
169  _fitness[i] /= _ind_cntr[i];
170  _survival[i] /= _ind_cntr[i];
171  _ind_cntr[i] /= tot_ind;
172  }
173  _mean_fitness /= tot_ind;
174  }
175 
176 
179  double getMeanFitness (age_idx age);
180 
184  double getMeanPatchFitness (age_idx age, unsigned int p);
185 
188  double getMaxFitness (age_idx age);
189 
193  double getMaxPatchFitness (age_idx age, unsigned int p);
194 
195 
198  double setMeanFitness (age_idx age) { return (_mean_fitness = getMeanFitness(age));}
199 
204  double getFitness (Individual* ind, unsigned int patch)
205  {
206  return (this->*_getFitness)(ind, patch);
207  }
208 
210  double getFitnessFixedEffect (Individual* offsprg, unsigned int patch, unsigned int trait)
211  {
212  return _FitnessFixModel[ offsprg->getPedigreeClass() ];
213  }
214 
216  double getFitnessDirect (Individual* offsprg, unsigned int patch, unsigned int trait)
217  {
218  return *(double*)offsprg->getTraitValue(trait);
219  }
221  double getFitnessUnivariateQuadratic ( Individual* ind, unsigned int patch, unsigned int trait);
222 
224  double getFitnessMultivariateGaussian (Individual* offsprg, unsigned int patch, unsigned int trait);
225 
227  double getFitnessUnivariateGaussian (Individual* offsprg, unsigned int patch, unsigned int trait);
228 
230  double getFitnessMultivariateGaussian_VE (Individual* offsprg, unsigned int patch, unsigned int trait);
231 
233  double getFitnessUnivariateGaussian_VE (Individual* offsprg, unsigned int patch, unsigned int trait);
234 
235 
240  double getFitnessAbsolute (Individual* ind, unsigned int patch);
241 
249  double getFitnessRelative (Individual* ind, unsigned int patch)
250  {
251  return getFitnessAbsolute(ind, patch) * _scaling_factor;
252  }
253 
257  void setScalingFactorLocal (age_idx age, unsigned int p);
258 
264  void setScalingFactorGlobal (age_idx age, unsigned int p);
265 
269  void setScalingFactorMaxLocal (age_idx age, unsigned int p);
270 
276  void setScalingFactorMaxGlobal (age_idx age, unsigned int p);
277 
281  void setScalingFactorAbsolute (age_idx age, unsigned int p)
282  { _scaling_factor = 1; }
283 
291  void doViabilitySelection (sex_t SEX, age_idx AGE, Patch* patch, unsigned int p);
292 
295  virtual bool setParameters ();
296  virtual void execute ();
297  virtual void loadStatServices (StatServices* loader);
298  virtual void loadFileServices (FileServices* loader);
299  virtual LifeCycleEvent* clone () {return new LCE_Selection_base();}
300  virtual age_t removeAgeClass () {return NONE;}
301  virtual age_t addAgeClass () {return NONE;}
302  virtual age_t requiredAgeClass () {return OFFSPRG;}
304 };
305 
306 
308 class LCE_SelectionSH : public EventStatHandler< LCE_Selection_base, LCE_SelectionSH >
309 {
310 
311  vector< vector< double > > _phenoTable;
313 
314 public:
315 
318  _table_set_gen(999999), _table_set_age(999999), _table_set_repl(999999)
319  {}
320 
321  virtual ~LCE_SelectionSH() {}
322 
323  virtual bool setStatRecorders (string& token);
324 
325  void addMeanPerPatch (age_t AGE);
326  void addVarPerPatch (age_t AGE);
327  void setDataTable (age_t AGE);
330 
331 
333  double getFitness (unsigned int i) {return _SHLinkedEvent->_fitness[i];}
334  double getSurvival (unsigned int i) {return _SHLinkedEvent->_survival[i];}
335  double getPedProp (unsigned int i) {return _SHLinkedEvent->_ind_cntr[i];}
336  double getMeanPatchFitness (unsigned int i, unsigned int int_agex);
337  double getMeanPatchFitness (unsigned int i);
338  double getVarPatchFitness (unsigned int i, unsigned int int_agex);
339 };
340 
341 class LCE_SelectionFH : public virtual EventFileHandler< LCE_Selection_base >
342 {
343 
344  public:
345 
347 
348  virtual ~LCE_SelectionFH() {}
349 
350  virtual void FHwrite();
351 
352  virtual void FHread(string& filename) {}
353 
354  void print(ofstream& FH, sex_t SEX, age_idx AGE, unsigned int i, Patch* patch, unsigned int ntraits);
355 };
356 
357 
358 #endif
359 
Template class for the LCEs StatHandler classes.
Definition: filehandler.h:247
double _ind_cntr[5]
Definition: LCEselection.h:92
void setDataTable(age_t AGE)
Definition: LCEselection.cc:1180
unsigned int _table_set_repl
Definition: LCEselection.h:312
gsl_vector * _diffs
Definition: LCEselection.h:57
bool setSelectionMatrix()
Definition: LCEselection.cc:396
double _max_fitness
Definition: LCEselection.h:89
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:693
double * _phe
Array to temporarily hold the phenotypic values of an individual, is never allocated.
Definition: LCEselection.h:64
The Service class used to manage the StatHandler objects.
Definition: statservices.h:50
void addPhenotypicSD(unsigned int deme, double *stDev)
Definition: LCEselection.cc:992
#define ADULTS
Adults age class flag (breeders).
Definition: types.h:54
double getMeanPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1251
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:271
void setMeans(unsigned int tot_ind)
Computes the average fitness of each pedigree class.
Definition: LCEselection.h:164
StatHandler class for the LCE_Selection class.
Definition: LCEselection.h:308
Template class for the LCEs StatHandler classes.
Definition: stathandler.h:189
LCE_SelectionFH * _writer
Definition: LCEselection.h:133
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
virtual void loadStatServices(StatServices *loader)
Definition: LCEselection.cc:106
TMatrix _rate_of_change_local_optima
Definition: LCEselection.h:59
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:792
vector< string > _SelectionModels
The selection models associated with each trait under selection.
Definition: LCEselection.h:111
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:92
LCE_SelectionSH(LCE_Selection_base *event)
Definition: LCEselection.h:316
unsigned int age_t
Age class flags.
Definition: types.h:46
void addMeanPerPatch(age_t AGE)
Definition: LCEselection.cc:1112
unsigned int _table_set_age
Definition: LCEselection.h:312
virtual LifeCycleEvent * clone()
Definition: LCEselection.h:299
void setAdultTable()
Definition: LCEselection.h:328
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:838
virtual ~LCE_SelectionFH()
Definition: LCEselection.h:348
virtual bool setParameters()
Definition: LCEselection.cc:150
virtual age_t requiredAgeClass()
Definition: LCEselection.h:302
double getFitnessAbsolute(Individual *ind, unsigned int patch)
Returns the raw fitness of the individual, without adjustment (absolute fitness). ...
Definition: LCEselection.cc:730
TMatrix * _local_optima
Definition: LCEselection.h:58
LCE_SelectionFH(LCE_Selection_base *event)
Definition: LCEselection.h:346
bool set_sel_model()
Definition: LCEselection.cc:261
virtual void FHwrite()
Definition: LCEselection.cc:1300
LCE_Selection_base * _SHLinkedEvent
Pointer to the linked LCE.
Definition: stathandler.h:192
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
virtual void FHread(string &filename)
Definition: LCEselection.h:352
double getMaxFitness(age_idx age)
Computes the maximum fitness value of the whole population for a given age class. ...
Definition: LCEselection.cc:776
#define NONE
No age flag.
Definition: types.h:48
vector< vector< double > > _phenoTable
Definition: LCEselection.h:311
void setScalingFactorAbsolute(age_idx age, unsigned int p)
Resets the fitness scaling factor equal to one.
Definition: LCEselection.h:281
void changeLocalOptima()
Definition: LCEselection.cc:1044
void print(ofstream &FH, sex_t SEX, age_idx AGE, unsigned int i, Patch *patch, unsigned int ntraits)
Definition: LCEselection.cc:1339
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:108
bool set_local_optima()
Definition: LCEselection.cc:528
Composite LCE implementing breeding and viability selection on a given trait type.
Definition: LCEcomposite.h:209
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:129
virtual ~LCE_Selection_base()
Definition: LCEselection.cc:87
double getSurvival(unsigned int i)
Definition: LCEselection.h:334
double getPedProp(unsigned int i)
Definition: LCEselection.h:335
double getVarPatchFitness(unsigned int i, unsigned int int_agex)
Definition: LCEselection.cc:1278
bool _rate_of_change_is_std
Definition: LCEselection.h:60
virtual age_t addAgeClass()
Definition: LCEselection.h:301
LCE_Selection_base()
Definition: LCEselection.cc:45
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:882
int _std_rate_reference_patch
Definition: LCEselection.h:62
void setOffsprgTable()
Definition: LCEselection.h:329
double _Fpedigree[5]
Array of pedigree values used in the fixed-selection model.
Definition: LCEselection.h:72
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:641
double _mean_fitness
Definition: LCEselection.h:89
virtual ~LCE_SelectionSH()
Definition: LCEselection.h:321
sex_t
Sex types, males are always 0 and females 1!!
Definition: types.h:36
double _base_fitness
Definition: LCEselection.h:88
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.h:153
bool set_fit_model()
Definition: LCEselection.cc:202
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:820
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:116
virtual bool setStatRecorders(string &token)
Definition: LCEselection.cc:1054
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
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:812
bool set_param_rate_of_change()
Definition: LCEselection.cc:558
Base class performing (viability) selection on an arbitrary trait.
Definition: LCEselection.h:50
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
double getMeanPatchFitness(age_idx age, unsigned int p)
Computes the mean fitness in a given patch for a given age class.
Definition: LCEselection.cc:760
vector< TMatrix * > _selection_matrix
Definition: LCEselection.h:55
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:56
virtual age_t removeAgeClass()
Definition: LCEselection.h:300
double _FitnessFixModel[5]
Absolute fitness values of the five pedigree class for the fixed selection model (lethal equivalents ...
Definition: LCEselection.h:76
double(LCE_Selection_base::* _getFitness)(Individual *, unsigned int)
Pointer to the function returning the individual fitness.
Definition: LCEselection.h:120
double _letheq
Definition: LCEselection.h:88
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
Definition: LCEselection.h:341
double setMeanFitness(age_idx age)
Sets the _mean_fitness variable to the value of the mean population fitness.
Definition: LCEselection.h:198
virtual void loadFileServices(FileServices *loader)
Definition: LCEselection.cc:114
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
virtual void execute()
Definition: LCEselection.cc:848
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:204
LCE_SelectionSH * _stater
Definition: LCEselection.h:132
double _scaling_factor
Definition: LCEselection.h:89
double _eVariance
Evironmental variance.
Definition: LCEselection.h:104
double _survival[5]
Definition: LCEselection.h:92
gsl_vector * _res1
Definition: LCEselection.h:57
double getMeanFitness()
Definition: LCEselection.h:332
A class to manage the files associated with each components of the simulation.
Definition: fileservices.h:51
unsigned int _table_set_gen
Definition: LCEselection.h:312
vector< double > _selection_variance
Patch-specific selection variance.
Definition: LCEselection.h:101
void addVarPerPatch(age_t AGE)
Definition: LCEselection.cc:1146
double getFitnessRelative(Individual *ind, unsigned int patch)
Returns the relative fitness of the individual, adjusted by a scaling factor.
Definition: LCEselection.h:249
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:671
bool _is_absolute
Definition: LCEselection.h:90
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
double getFitnessDirect(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following the direct selection model.
Definition: LCEselection.h:216
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:125
Base class of the Life Cycle Events, declares the LCE interface.
Definition: lifecycleevent.h:72
void set_std_rate_of_change()
Definition: LCEselection.cc:915
bool _is_local
Definition: LCEselection.h:90
double getMeanFitness(age_idx age)
Computes the mean fitness of the whole population for a given age class.
Definition: LCEselection.cc:742
bool _do_change_local_opt
Definition: LCEselection.h:60
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:656
unsigned int _set_std_rate_at_generation
Definition: LCEselection.h:61
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:709
double getFitness(unsigned int i)
Definition: LCEselection.h:333
double getFitnessFixedEffect(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual in the fixed selection model.
Definition: LCEselection.h:210
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:830

Generated for Nemo v2.3.0 by  doxygen 1.8.8 --
Catalogued on GSR