Nemo  2.3.46
LCE_Selection_base Class Reference

Base class performing (viability) selection on an arbitrary trait. More...

#include <LCEselection.h>

+ Inheritance diagram for LCE_Selection_base:
+ Collaboration diagram for LCE_Selection_base:

Public Member Functions

 LCE_Selection_base ()
 
virtual ~LCE_Selection_base ()
 
bool setSelectionMatrix ()
 
bool setLocalOptima ()
 
bool set_sel_model ()
 
bool set_fit_model ()
 
bool set_local_optima ()
 
bool set_param_rate_of_change ()
 
void set_std_rate_of_change ()
 
void addPhenotypicSD (unsigned int deme, double *stDev)
 
void changeLocalOptima ()
 
void resetCounters ()
 Resets the fitness counters. More...
 
void setMeans (unsigned int tot_ind)
 Computes the average fitness of each pedigree class. More...
 
double getMeanFitness (age_idx age)
 Computes the mean fitness of the whole population for a given age class. More...
 
double getMeanPatchFitness (age_idx age, unsigned int p)
 Computes the mean fitness in a given patch for a given age class. More...
 
double getMaxFitness (age_idx age)
 Computes the maximum fitness value of the whole population for a given age class. More...
 
double getMaxPatchFitness (age_idx age, unsigned int p)
 Computes the maximum fitness value in a given patch for a given age class. More...
 
double setMeanFitness (age_idx age)
 Sets the _mean_fitness variable to the value of the mean population fitness. More...
 
double getFitness (Individual *ind, unsigned int patch)
 Calls the fitness function according to the fitness model. More...
 
double getFitnessFixedEffect (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual in the fixed selection model. More...
 
double getFitnessDirect (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following the direct selection model. More...
 
double getFitnessUnivariateQuadratic (Individual *ind, unsigned int patch, unsigned int trait)
 Quadratic fitness surface, approximates the Gaussian model for weak selection and/or small deviation from the optimum. More...
 
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 selection. More...
 
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 selection. More...
 
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 selection and environmental variance. More...
 
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 selection and environmental variance. More...
 
double getFitnessAbsolute (Individual *ind, unsigned int patch)
 Returns the raw fitness of the individual, without adjustment (absolute fitness). More...
 
double getFitnessRelative (Individual *ind, unsigned int patch)
 Returns the relative fitness of the individual, adjusted by a scaling factor. More...
 
void setScalingFactorLocal (age_idx age, unsigned int p)
 Sets the fitness scaling factor equal to the inverse of the mean local patch fitness. More...
 
void setScalingFactorGlobal (age_idx age, unsigned int p)
 Sets the fitness scaling factor equal to the inverse of the mean population fitness. More...
 
void setScalingFactorMaxLocal (age_idx age, unsigned int p)
 Sets the fitness scaling factor equal to the inverse of the maximum local patch fitness value. More...
 
void setScalingFactorMaxGlobal (age_idx age, unsigned int p)
 Sets the fitness scaling factor equal to the inverse of the maximum population fitness value. More...
 
void setScalingFactorAbsolute (age_idx age, unsigned int p)
 Resets the fitness scaling factor equal to one. More...
 
void doViabilitySelection (sex_t SEX, age_idx AGE, Patch *patch, unsigned int p)
 Selectively removes individuals in the population depending on their fitness. More...
 
Implementations
virtual bool setParameters ()
 
virtual void execute ()
 
virtual void loadStatServices (StatServices *loader)
 
virtual void loadFileServices (FileServices *loader)
 
virtual LifeCycleEventclone ()
 
virtual age_t removeAgeClass ()
 
virtual age_t addAgeClass ()
 
virtual age_t requiredAgeClass ()
 
- Public Member Functions inherited from LifeCycleEvent
 LifeCycleEvent (const char *name, const char *trait_link)
 Cstor. More...
 
virtual ~LifeCycleEvent ()
 
virtual void init (Metapop *popPtr)
 Sets the pointer to the current Metapop and the trait link if applicable. More...
 
virtual bool attach_trait (string trait)
 
virtual void set_paramset (std::string name, bool required, SimComponent *owner)
 
virtual void set_event_name (std::string &name)
 Set the name of the event (name of the ParamSet) and add the corresponding parameter to the set. More...
 
virtual void set_event_name (const char *name)
 
virtual string & get_event_name ()
 Accessor to the LCE's name. More...
 
virtual int get_rank ()
 Accessor to the LCE rank in the life cycle. More...
 
virtual void set_pop_ptr (Metapop *popPtr)
 Accessors for the population pointer. More...
 
virtual Metapopget_pop_ptr ()
 
- Public Member Functions inherited from SimComponent
 SimComponent ()
 
virtual ~SimComponent ()
 
virtual void loadUpdaters (UpdaterServices *loader)
 Loads the parameters and component updater onto the updater manager. More...
 
virtual void set_paramset (ParamSet *paramset)
 Sets the ParamSet member. More...
 
virtual void set_paramsetFromCopy (const ParamSet &PSet)
 Reset the set of parameters from a another set. More...
 
virtual ParamSetget_paramset ()
 ParamSet accessor. More...
 
virtual void add_parameter (Param *param)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd)
 Interface to add a parameter to the set. More...
 
virtual void add_parameter (std::string Name, param_t Type, bool isRequired, bool isBounded, double low_bnd, double up_bnd, ParamUpdaterBase *updater)
 Interface to add a parameter and its updater to the set. More...
 
virtual Paramget_parameter (std::string name)
 Param getter. More...
 
virtual double get_parameter_value (std::string name)
 Param value getter. More...
 
virtual string get_name ()
 Returnd the name of the ParamSet, i.e. More...
 

Protected Attributes

double _letheq
 
double _base_fitness
 
double _mean_fitness
 
double _max_fitness
 
double _scaling_factor
 
bool _is_local
 
bool _is_absolute
 
double _fitness [5]
 Fitness counters, one for each pedigree class. More...
 
double _survival [5]
 
double _ind_cntr [5]
 
vector< unsigned int_TraitIndices
 The indices of the traits under selection. More...
 
vector< string > _SelectionModels
 The selection models associated with each trait under selection. More...
 
LCE_SelectionSH_stater
 
LCE_SelectionFH_writer
 
Quantitative traits parameters
int _selectTraitDimension
 Number of quantitative traits under selection. More...
 
vector< double > _selection_variance
 Patch-specific selection variance. More...
 
double _eVariance
 Evironmental variance. More...
 
Pointers to functions, set in LCE_Selection_base::setParameters
vector< double(LCE_Selection_base::*)(Individual
*, unsigned int, unsigned int) > 
_getRawFitness
 A vector containing pointers to fitness function related to each trait under selection. More...
 
double(LCE_Selection_base::* _getFitness )(Individual *, unsigned int)
 Pointer to the function returning the individual fitness. More...
 
void(LCE_Selection_base::* _setScalingFactor )(age_idx, unsigned int)
 Pointer to the function used to set the fitness scaling factor when fitness is relative. More...
 
void(LCE_Selection_base::* _setNewLocalOptima )(void)
 Pointer to the function used to change the local phenotypic optima or its rate of change. More...
 
- Protected Attributes inherited from LifeCycleEvent
std::string _event_name
 The param name to be read in the init file. More...
 
Metapop_popPtr
 The ptr to the current Metapop. More...
 
std::string _LCELinkedTraitType
 The name of the linked trait. More...
 
int _LCELinkedTraitIndex
 The index in the individual's trait table of the linked trait. More...
 
- Protected Attributes inherited from SimComponent
ParamSet_paramSet
 The parameters container. More...
 

Private Attributes

Gaussian selection variables
vector< TMatrix * > _selection_matrix
 
vector< gsl_matrix * > _gsl_selection_matrix
 
gsl_vector * _diffs
 
gsl_vector * _res1
 
TMatrix_local_optima
 
TMatrix _rate_of_change_local_optima
 
bool _do_change_local_opt
 
bool _rate_of_change_is_std
 
unsigned int _set_std_rate_at_generation
 
int _std_rate_reference_patch
 
double * _phe
 Array to temporarily hold the phenotypic values of an individual, is never allocated. More...
 
Fixed selection (lethal-equivalents-based) parameters
double _Fpedigree [5]
 Array of pedigree values used in the fixed-selection model. More...
 
double _FitnessFixModel [5]
 Absolute fitness values of the five pedigree class for the fixed selection model (lethal equivalents model). More...
 

Friends

class LCE_SelectionSH
 The StatHandler associated class is a friend. More...
 
class LCE_SelectionFH
 
class LCE_Breed_Selection
 

Detailed Description

Base class performing (viability) selection on an arbitrary trait.

Implements several types of selection models, from fixed inbreeding depression-type model to Gaussian stabilizing selection on an adaptive landscape. This class is the base-class for the composite LCEs breed_selection and breed_selection_disperse.

Constructor & Destructor Documentation

LCE_Selection_base::LCE_Selection_base ( )

References SimComponent::add_parameter(), BOOL, DBL, INT, MAT, set_fit_model(), set_local_optima(), set_param_rate_of_change(), set_sel_model(), and STR.

Referenced by clone().

45  : LifeCycleEvent("viability_selection", ""),
49 {
50  add_parameter("selection_trait",STR,false,false,0,0); //no updaters here, to keep it safe...
51 
54 
55  add_parameter("selection_fitness_model",STR,false,false,0,0, updater);
56 
58 
59  add_parameter("selection_model",STR,false,false,0,0, updater);
60  add_parameter("selection_matrix",MAT,false,false,0,0, updater);
61  add_parameter("selection_variance",DBL,false,false,0,0, updater);
62  add_parameter("selection_correlation",DBL,false,false,0,0, updater);
63  add_parameter("selection_trait_dimension",INT,false,false,0,0, updater);
64  add_parameter("selection_base_fitness",DBL,false,true,0,1, updater);
65  add_parameter("selection_lethal_equivalents",DBL,false,false,0,0, updater);
66  add_parameter("selection_pedigree_F",MAT,false,false,0,0, updater);
67  add_parameter("selection_randomize",BOOL,false,false,0,0, updater);
68  add_parameter("selection_environmental_variance", DBL, false, false, 0, 0, updater);
69 
71  add_parameter("selection_local_optima",DBL,false,false,0,0, updater);
72 
74  add_parameter("selection_rate_environmental_change", DBL, false, false, 0, 0, updater);
75  add_parameter("selection_std_rate_environmental_change", DBL, false, false, 0, 0, updater);
76  add_parameter("selection_std_rate_set_at_generation", INT, false, false, 0, 0, updater);
77  add_parameter("selection_std_rate_reference_patch", INT, false, false, 0, 0, updater);
78 
79 
80  add_parameter("selection_output", BOOL, false, false, 0, 0, 0);
81  add_parameter("selection_output_logtime", INT, false, false, 0, 0, 0);
82  add_parameter("selection_output_dir", STR, false, false, 0, 0, 0);
83 }
gsl_vector * _diffs
Definition: LCEselection.h:57
double _max_fitness
Definition: LCEselection.h:89
double * _phe
Array to temporarily hold the phenotypic values of an individual, is never allocated.
Definition: LCEselection.h:64
Implementation of the ParamUpdaterBase interface.
Definition: param.h:348
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
LCE_SelectionFH * _writer
Definition: LCEselection.h:133
Definition: types.h:78
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
TMatrix * _local_optima
Definition: LCEselection.h:58
bool set_sel_model()
Definition: LCEselection.cc:261
Definition: types.h:78
bool set_local_optima()
Definition: LCEselection.cc:528
double _mean_fitness
Definition: LCEselection.h:89
double _base_fitness
Definition: LCEselection.h:88
bool set_fit_model()
Definition: LCEselection.cc:202
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
bool set_param_rate_of_change()
Definition: LCEselection.cc:558
vector< TMatrix * > _selection_matrix
Definition: LCEselection.h:55
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:56
double(LCE_Selection_base::* _getFitness)(Individual *, unsigned int)
Pointer to the function returning the individual fitness.
Definition: LCEselection.h:120
Definition: types.h:78
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
LCE_SelectionSH * _stater
Definition: LCEselection.h:132
double _scaling_factor
Definition: LCEselection.h:89
double _eVariance
Evironmental variance.
Definition: LCEselection.h:104
Definition: types.h:78
gsl_vector * _res1
Definition: LCEselection.h:57
bool _is_absolute
Definition: LCEselection.h:90
bool _is_local
Definition: LCEselection.h:90
Definition: types.h:78
LCE_Selection_base::~LCE_Selection_base ( )
virtual

References _diffs, _gsl_selection_matrix, _local_optima, _res1, _selection_matrix, and _stater.

88 {
89  vector< TMatrix* >::iterator selIT = _selection_matrix.begin();
90  for(; selIT != _selection_matrix.end(); ++selIT)
91  if((*selIT)) delete (*selIT);
92  _selection_matrix.clear();
93 
94  for(unsigned int i = 0; i < _gsl_selection_matrix.size(); ++i)
95  if(_gsl_selection_matrix[i]) gsl_matrix_free(_gsl_selection_matrix[i]);
96  _gsl_selection_matrix.clear();
97 
98  if(_local_optima) delete _local_optima;
99  if(_diffs) gsl_vector_free(_diffs);
100  if(_res1) gsl_vector_free(_res1);
101  if(_stater) delete _stater;
102 }
gsl_vector * _diffs
Definition: LCEselection.h:57
TMatrix * _local_optima
Definition: LCEselection.h:58
vector< TMatrix * > _selection_matrix
Definition: LCEselection.h:55
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:56
LCE_SelectionSH * _stater
Definition: LCEselection.h:132
gsl_vector * _res1
Definition: LCEselection.h:57

Member Function Documentation

virtual age_t LCE_Selection_base::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

References NONE.

301 {return NONE;}
#define NONE
No age flag.
Definition: types.h:48
void LCE_Selection_base::addPhenotypicSD ( unsigned int  deme,
double *  stDev 
)

References LifeCycleEvent::_LCELinkedTraitIndex, _phe, LifeCycleEvent::_popPtr, _selectTraitDimension, FEM, Patch::get(), Metapop::getPatch(), Individual::getTraitValue(), MAL, my_mean(), my_variance_with_fixed_mean(), OFFSx, and Patch::size().

Referenced by set_std_rate_of_change().

993 {
994  Patch *patch = _popPtr->getPatch(deme);
995  Individual* ind;
996  unsigned int table_size = patch->size(OFFSx);
997 
998  double **phenot = new double* [_selectTraitDimension];
999 
1000  for (int i = 0; i < _selectTraitDimension; ++i) {
1001 
1002  phenot[i] = new double [table_size];
1003 
1004  }
1005 
1006  unsigned int pos = 0;
1007 
1008  for (unsigned int j = 0; j < patch->size(FEM, OFFSx) && pos < table_size; ++j) {
1009 
1010  ind = patch->get(FEM, OFFSx, j);
1011  _phe = (double*)ind->getTraitValue(_LCELinkedTraitIndex);
1012 
1013  for (int i = 0; i < _selectTraitDimension; ++i)
1014  phenot[i][pos] = _phe[i];
1015 
1016  pos++;
1017 
1018  }
1019 
1020  for (unsigned int j = 0; j < patch->size(MAL, OFFSx) && pos < table_size; ++j) {
1021 
1022  ind = patch->get(MAL, OFFSx, j);
1023  _phe = (double*)ind->getTraitValue(_LCELinkedTraitIndex);
1024 
1025  for (int i = 0; i < _selectTraitDimension; ++i)
1026  phenot[i][pos] = _phe[i];
1027 
1028  pos++;
1029 
1030  }
1031 
1032  assert(pos == table_size);
1033 
1034  for (int i = 0; i < _selectTraitDimension; ++i) {
1035  stDev[i] += sqrt( my_variance_with_fixed_mean( phenot[i], table_size, my_mean(phenot[i], table_size) ) );
1036  delete [] phenot[i];
1037  }
1038 
1039  delete [] phenot;
1040 }
double * _phe
Array to temporarily hold the phenotypic values of an individual, is never allocated.
Definition: LCEselection.h:64
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:271
double my_mean(double *data, unsigned int size)
Definition: utils.cc:37
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
double my_variance_with_fixed_mean(double *data, unsigned int size, double mean)
Definition: utils.cc:62
Definition: types.h:37
Definition: types.h:42
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:523
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:89
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
Definition: types.h:37
void LCE_Selection_base::changeLocalOptima ( )

References _local_optima, _rate_of_change_local_optima, _selectTraitDimension, TMatrix::get(), TMatrix::nrows(), and TMatrix::plus().

Referenced by set_param_rate_of_change(), and set_std_rate_of_change().

1045 {
1046  for (int i = 0; i < _selectTraitDimension; ++i)
1047  for (unsigned int j = 0; j < _local_optima->nrows(); ++j) {
1049  }
1050 }
void plus(unsigned int i, unsigned int j, double value)
Adds a value to an element of the matrix.
Definition: tmatrix.h:183
TMatrix _rate_of_change_local_optima
Definition: LCEselection.h:59
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
TMatrix * _local_optima
Definition: LCEselection.h:58
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
unsigned int nrows()
Definition: tmatrix.h:140
virtual LifeCycleEvent* LCE_Selection_base::clone ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

References LCE_Selection_base().

299 {return new LCE_Selection_base();}
LCE_Selection_base()
Definition: LCEselection.cc:45
void LCE_Selection_base::doViabilitySelection ( sex_t  SEX,
age_idx  AGE,
Patch patch,
unsigned int  p 
)

Selectively removes individuals in the population depending on their fitness.

Calls the fitness function for each individual. Updates the fitness counters. The fitness scaling factor is set outside this function, in the execute() procedure.

Parameters
SEXthe sex class
AGEthe age-class index
patchthe focal patch
pthe focal patch index

References _fitness, _ind_cntr, LifeCycleEvent::_popPtr, _survival, Patch::get(), getFitness(), Individual::getPedigreeClass(), IndFactory::recycle(), Patch::remove(), Patch::size(), and RAND::Uniform().

Referenced by execute().

883 {
884  register Individual* ind;
885  register double fitness;
886  register unsigned int cat;
887 
888  for(unsigned int i = 0; i < patch->size(SEX, AGE); i++) {
889 
890  ind = patch->get(SEX, AGE, i);
891  cat = ind->getPedigreeClass();
892  fitness = getFitness( ind, p);
893 
894  _fitness[cat] += fitness;
895  _ind_cntr[cat]++;
896 
897  if(RAND::Uniform() > fitness ) {
898  //this individual dies
899  patch->remove(SEX, AGE, i);
900 
901  _popPtr->recycle(ind);
902 
903  i--;
904 
905  } //else; this individual stays in the patch
906  else {
907  _survival[cat]++;
908  }
909 
910  }
911 }
double _ind_cntr[5]
Definition: LCEselection.h:92
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:62
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:92
Individual * remove(sex_t SEX, age_idx AGE, unsigned int at)
Removes the individual sitting at the given index in the appropriate container.
Definition: metapop.h:564
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:101
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:523
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:204
double _survival[5]
Definition: LCEselection.h:92
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
This class contains traits along with other individual information (sex, pedigree, etc. ).
Definition: individual.h:49
void LCE_Selection_base::execute ( )
virtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

References _do_change_local_opt, LifeCycleEvent::_popPtr, _rate_of_change_is_std, _setNewLocalOptima, _setScalingFactor, doViabilitySelection(), FEM, Metapop::getCurrentGeneration(), Metapop::getPatch(), Metapop::getPatchNbr(), MAL, OFFSPRG, OFFSx, resetCounters(), set_local_optima(), set_std_rate_of_change(), setMeans(), and Metapop::size().

849 {
850  Patch * patch;
851  unsigned int popSize = _popPtr->size(OFFSPRG);
852 
853  resetCounters();
854 
856 
857  if(_popPtr->getCurrentGeneration() == 1) {
858  set_local_optima(); //reset local optima to initial values
859  if(_rate_of_change_is_std) //reset rate of change relative to SD of that replicate
861  }
862 
863  (this->*_setNewLocalOptima)();
864  }
865 
866  for(unsigned int p = 0; p < _popPtr->getPatchNbr(); p++) {
867 
868  (this->*_setScalingFactor)(OFFSx, p);
869 
870  patch = _popPtr->getPatch(p);
871 
872  doViabilitySelection(FEM, OFFSx, patch, p);
873 
874  doViabilitySelection(MAL, OFFSx, patch, p);
875  }
876 
877  setMeans(popSize);
878 }
void setMeans(unsigned int tot_ind)
Computes the average fitness of each pedigree class.
Definition: LCEselection.h:164
unsigned int getCurrentGeneration()
Definition: metapop.h:286
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
unsigned int getPatchNbr()
Definition: metapop.h:270
bool set_local_optima()
Definition: LCEselection.cc:528
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
bool _rate_of_change_is_std
Definition: LCEselection.h:60
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
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.h:153
Definition: types.h:37
Definition: types.h:42
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37
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
void set_std_rate_of_change()
Definition: LCEselection.cc:915
bool _do_change_local_opt
Definition: LCEselection.h:60
double LCE_Selection_base::getFitness ( Individual ind,
unsigned int  patch 
)
inline

Calls the fitness function according to the fitness model.

The fitness model can be "absolute", "relative_local" or "relative_global".

Parameters
indthe focal indvidual, we want to know its fitness
patchthe index of the patch of the focal individual

References _getFitness.

Referenced by LCE_Breed_Selection::do_breed_selection_FecFitness(), doViabilitySelection(), getMaxPatchFitness(), getMeanFitness(), getMeanPatchFitness(), LCE_Breed_Selection::makeOffspringWithSelection(), and LCE_SelectionSH::setDataTable().

205  {
206  return (this->*_getFitness)(ind, patch);
207  }
double(LCE_Selection_base::* _getFitness)(Individual *, unsigned int)
Pointer to the function returning the individual fitness.
Definition: LCEselection.h:120
double LCE_Selection_base::getFitnessAbsolute ( Individual ind,
unsigned int  patch 
)

Returns the raw fitness of the individual, without adjustment (absolute fitness).

Calls the fitness function according to the right selection model.

Parameters
indthe focal indvidual, we want to know its fitness
patchthe index of the patch of the focal individual

References _getRawFitness, and _TraitIndices.

Referenced by getFitnessRelative(), and set_fit_model().

731 {
732  double fitness = 1;
733  //at this point, _getRawFitness.size() == _TraitIndices.size()
734  //and we assume that the functions are "aligned" with the traits
735  for(unsigned int i = 0; i < _getRawFitness.size(); i++)
736  fitness *= (this->*_getRawFitness[i])(ind, patch, _TraitIndices[i]);
737  return fitness;
738 }
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:108
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
double LCE_Selection_base::getFitnessDirect ( Individual offsprg,
unsigned int  patch,
unsigned int  trait 
)
inline

Returns the fitness of an individual following the direct selection model.

References Individual::getTraitValue().

Referenced by set_sel_model().

217  {
218  return *(double*)offsprg->getTraitValue(trait);
219  }
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:271
double LCE_Selection_base::getFitnessFixedEffect ( Individual offsprg,
unsigned int  patch,
unsigned int  trait 
)
inline

Returns the fitness of an individual in the fixed selection model.

References Individual::getPedigreeClass().

Referenced by set_sel_model().

211  {
212  return _FitnessFixModel[ offsprg->getPedigreeClass() ];
213  }
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:179
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::getFitnessMultivariateGaussian ( Individual offsprg,
unsigned int  patch,
unsigned int  trait 
)

Returns the fitness of an individual following the Gaussian selection model with one trait under selection.

References _diffs, _gsl_selection_matrix, _local_optima, _phe, _res1, _selectTraitDimension, TMatrix::get(), and Individual::getTraitValue().

Referenced by set_sel_model().

672 {
673  register double res2;
674 
675 // if(!ind) fatal("passing NULL ind ptr to LCE_Selection_base::getFitnessMultivariateGaussian!!!\n");
676 
677  _phe = (double*)ind->getTraitValue(trait);
678 
679  for( int i = 0; i < _selectTraitDimension; i++)
680  gsl_vector_set(_diffs, i, _phe[i] - _local_optima->get(patch, i));
681 
682  //(diff)T * W * diff:
683  //right partial product:
684  gsl_blas_dsymv(CblasUpper, 1.0, _gsl_selection_matrix[patch], _diffs, 0.0, _res1);
685  //left product:
686  gsl_blas_ddot(_diffs, _res1, &res2);
687 
688  return exp( -0.5 * res2 );
689 }
gsl_vector * _diffs
Definition: LCEselection.h:57
double * _phe
Array to temporarily hold the phenotypic values of an individual, is never allocated.
Definition: LCEselection.h:64
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
TMatrix * _local_optima
Definition: LCEselection.h:58
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:56
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
gsl_vector * _res1
Definition: LCEselection.h:57
double LCE_Selection_base::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 selection and environmental variance.

References _diffs, _eVariance, _gsl_selection_matrix, _local_optima, _phe, _res1, _selectTraitDimension, RAND::Gaussian(), TMatrix::get(), and Individual::getTraitValue().

Referenced by set_sel_model().

710 {
711  register double res2;
712 
713  _phe = (double*)ind->getTraitValue(trait);
714 
715  //add the environmental variance here:
716  for( int i = 0; i < _selectTraitDimension; i++)
717  gsl_vector_set(_diffs, i, _phe[i] + RAND::Gaussian(_eVariance) - _local_optima->get(patch, i));
718 
719  //(diff)T * W * diff:
720  //right partial product:
721  gsl_blas_dsymv(CblasUpper, 1.0, _gsl_selection_matrix[patch], _diffs, 0.0, _res1);
722  //left product:
723  gsl_blas_ddot(_diffs, _res1, &res2);
724 
725  return exp( -0.5 * res2 );
726 }
gsl_vector * _diffs
Definition: LCEselection.h:57
double * _phe
Array to temporarily hold the phenotypic values of an individual, is never allocated.
Definition: LCEselection.h:64
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
TMatrix * _local_optima
Definition: LCEselection.h:58
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:56
static double Gaussian(double sigma)
Definition: Uniform.h:238
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
double _eVariance
Evironmental variance.
Definition: LCEselection.h:104
gsl_vector * _res1
Definition: LCEselection.h:57
double LCE_Selection_base::getFitnessRelative ( Individual ind,
unsigned int  patch 
)
inline

Returns the relative fitness of the individual, adjusted by a scaling factor.

The scaling factor is set according to the relative fitness model (local or global) outside of this function. If the scaling factor is one, this is the absolute fitness of the individual. Calls the fitness function according to the right selection model.

Parameters
indthe focal indvidual, we want to know its fitness
patchthe index of the patch of the focal individual

References _scaling_factor, and getFitnessAbsolute().

Referenced by set_fit_model().

250  {
251  return getFitnessAbsolute(ind, patch) * _scaling_factor;
252  }
double getFitnessAbsolute(Individual *ind, unsigned int patch)
Returns the raw fitness of the individual, without adjustment (absolute fitness). ...
Definition: LCEselection.cc:730
double _scaling_factor
Definition: LCEselection.h:89
double LCE_Selection_base::getFitnessUnivariateGaussian ( Individual offsprg,
unsigned int  patch,
unsigned int  trait 
)

Returns the fitness of an individual following the Gaussian selection model with several traits under selection.

References _local_optima, _phe, _selection_variance, TMatrix::get(), and Individual::getTraitValue().

Referenced by set_sel_model().

657 {
658  register double res2, diff;
659 
660  _phe = (double*)ind->getTraitValue(trait);
661 
662  diff = _phe[0] - _local_optima->get(patch, 0);
663 
664  res2 = diff*diff / _selection_variance[patch];
665 
666  return exp( -0.5 * res2 );
667 }
double * _phe
Array to temporarily hold the phenotypic values of an individual, is never allocated.
Definition: LCEselection.h:64
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
TMatrix * _local_optima
Definition: LCEselection.h:58
vector< double > _selection_variance
Patch-specific selection variance.
Definition: LCEselection.h:101
double LCE_Selection_base::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 selection and environmental variance.

References _eVariance, _local_optima, _phe, _selection_variance, RAND::Gaussian(), TMatrix::get(), and Individual::getTraitValue().

Referenced by set_sel_model().

694 {
695  register double res2, diff;
696 
697  _phe = (double*)ind->getTraitValue(trait);
698 
699  //add the environmental variance here:
700  diff = _phe[0] + RAND::Gaussian(_eVariance) - _local_optima->get(patch, 0);
701 
702  res2 = diff*diff / _selection_variance[patch];
703 
704  return exp( -0.5 * res2 );
705 }
double * _phe
Array to temporarily hold the phenotypic values of an individual, is never allocated.
Definition: LCEselection.h:64
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
TMatrix * _local_optima
Definition: LCEselection.h:58
static double Gaussian(double sigma)
Definition: Uniform.h:238
double _eVariance
Evironmental variance.
Definition: LCEselection.h:104
vector< double > _selection_variance
Patch-specific selection variance.
Definition: LCEselection.h:101
double LCE_Selection_base::getFitnessUnivariateQuadratic ( Individual ind,
unsigned int  patch,
unsigned int  trait 
)

Quadratic fitness surface, approximates the Gaussian model for weak selection and/or small deviation from the optimum.

References _local_optima, _phe, _selection_variance, TMatrix::get(), and Individual::getTraitValue().

Referenced by set_sel_model().

642 {
643  register double res2, diff;
644 
645  _phe = (double*)ind->getTraitValue(trait);
646 
647  diff = _phe[0] - _local_optima->get(patch, 0);
648 
649  res2 = diff*diff / _selection_variance[patch];
650 
651  return 1 - res2;
652 }
double * _phe
Array to temporarily hold the phenotypic values of an individual, is never allocated.
Definition: LCEselection.h:64
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:271
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
TMatrix * _local_optima
Definition: LCEselection.h:58
vector< double > _selection_variance
Patch-specific selection variance.
Definition: LCEselection.h:101
double LCE_Selection_base::getMaxFitness ( age_idx  age)

Computes the maximum fitness value of the whole population for a given age class.

Parameters
agethe age-class index

References LifeCycleEvent::_popPtr, getMaxPatchFitness(), and Metapop::getPatchNbr().

Referenced by setScalingFactorMaxGlobal().

777 {
778  double max = 0, local_max;
779 
780  for(unsigned int i = 0, npatch = _popPtr->getPatchNbr(); i < npatch; i++) {
781 
782  local_max = getMaxPatchFitness(age, i);
783 
784  max = (local_max > max ? local_max : max);
785  }
786 
787  return max;
788 }
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
unsigned int getPatchNbr()
Definition: metapop.h:270
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
double LCE_Selection_base::getMaxPatchFitness ( age_idx  age,
unsigned int  p 
)

Computes the maximum fitness value in a given patch for a given age class.

Parameters
agethe age-class index
pthe patch index

References LifeCycleEvent::_popPtr, FEM, Patch::get(), getFitness(), Metapop::getPatch(), MAL, and Patch::size().

Referenced by getMaxFitness(), and setScalingFactorMaxLocal().

793 {
794  double max = 0, fit;
795  Patch *patch = _popPtr->getPatch(p);
796 
797  for(unsigned int j = 0, size = patch->size(FEM, age); j < size; j++) {
798  fit = getFitness( patch->get(FEM, age, j), p);
799  max = (fit > max ? fit : max);
800  }
801  for(unsigned int j = 0, size = patch->size(MAL, age); j < size; j++){
802  fit = getFitness( patch->get(MAL, age, j), p);
803  max = (fit > max ? fit : max);
804  }
805 
806  return max;
807 }
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
Definition: types.h:37
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:523
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:204
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37
double LCE_Selection_base::getMeanFitness ( age_idx  age)

Computes the mean fitness of the whole population for a given age class.

Parameters
agethe age-class index

References LifeCycleEvent::_popPtr, FEM, Patch::get(), getFitness(), Metapop::getPatch(), Metapop::getPatchNbr(), MAL, Metapop::size(), and Patch::size().

Referenced by LCE_Breed_Selection_Disperse::execute(), setMeanFitness(), and setScalingFactorGlobal().

743 {
744  double mean = 0;
745  Patch *patch;
746 // age_idx age = (AGE == ADULTS ? ADLTx : OFFSx);
747 
748  for(unsigned int i = 0, npatch = _popPtr->getPatchNbr(); i < npatch; i++) {
749  patch = _popPtr->getPatch(i);
750  for(unsigned int j = 0, size = patch->size(FEM, age); j < size; j++)
751  mean += getFitness( patch->get(FEM, age, j), i);
752  for(unsigned int j = 0, size = patch->size(MAL, age); j < size; j++)
753  mean += getFitness( patch->get(MAL, age, j), i);
754  }
755  return mean/_popPtr->size(age);
756 }
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
unsigned int getPatchNbr()
Definition: metapop.h:270
Definition: types.h:37
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:523
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:204
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together...
Definition: metapop.h:302
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37
double LCE_Selection_base::getMeanPatchFitness ( age_idx  age,
unsigned int  p 
)

Computes the mean fitness in a given patch for a given age class.

Parameters
agethe age-class index
pthe patch index

References LifeCycleEvent::_popPtr, FEM, Patch::get(), getFitness(), Metapop::getPatch(), MAL, and Patch::size().

Referenced by LCE_Breed_Selection_Disperse::breed_selection_disperse(), and setScalingFactorLocal().

761 {
762  double mean = 0;
763  Patch *patch = _popPtr->getPatch(p);
764 
765  for(unsigned int j = 0, size = patch->size(FEM, age); j < size; j++)
766  mean += getFitness( patch->get(FEM, age, j), p);
767 
768  for(unsigned int j = 0, size = patch->size(MAL, age); j < size; j++)
769  mean += getFitness( patch->get(MAL, age, j), p);
770 
771  return mean/patch->size(age);
772 }
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
Second class in the metapopulation design structure, between the Metapop and Individual classes...
Definition: metapop.h:421
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
Definition: types.h:37
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:523
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:204
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
Definition: types.h:37
void LCE_Selection_base::loadFileServices ( FileServices loader)
virtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

References SimComponent::_paramSet, _writer, FileServices::attach(), fatal(), SimComponent::get_parameter(), Param::getArg(), Param::getMatrix(), Param::getValue(), Param::isMatrix(), Param::isSet(), ParamSet::isSet(), LCE_SelectionFH, EventFileHandler< LCE >::set(), and FileHandler::set_multi().

115 {
116  if(_paramSet->isSet("selection_output")) {
117 
118  if(_writer == NULL) _writer = new LCE_SelectionFH(this);
119 
120  Param* param = get_parameter("selection_output_logtime");
121 
122  if(!param->isSet()) fatal("parameter \"selection_output_logtime\" is missing\n");
123 
124  if(param->isMatrix()) {
125 
126  TMatrix temp;
127 
128  param->getMatrix(&temp);
129 
130  _writer->set_multi(true, true, 1, &temp, get_parameter("selection_output_dir")->getArg());
131  // rpl_per, gen_per, rpl_occ, gen_occ, rank, path, self-ref
132  } else _writer->set(true, param->isSet(), 1, (param->isSet() ? (int)param->getValue() : 0), 0, get_parameter("selection_output_dir")->getArg(), this);
133 
134 
135  loader->attach(_writer);
136 
137  } else {
138 
139  if(_writer) delete _writer;
140 
141  return;
142  }
143 
144 
145 }
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:57
LCE_SelectionFH * _writer
Definition: LCEselection.h:133
double getValue()
Returns the argument value according to its type.
Definition: param.cc:319
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:329
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path, LCE *event)
Definition: filehandler.h:265
void fatal(const char *str,...)
Definition: output.cc:90
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:170
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
friend class LCE_SelectionFH
Definition: LCEselection.h:83
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
virtual void set_multi(bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path)
Definition: filehandler.h:197
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
string getArg()
Definition: param.h:136
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
bool isSet()
Accessor to the status flag.
Definition: param.h:273
bool isSet()
Definition: param.h:138
void LCE_Selection_base::loadStatServices ( StatServices loader)
virtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

References _stater, StatServices::attach(), and LCE_SelectionSH.

Referenced by LCE_Breed_Selection::loadStatServices(), and LCE_Breed_Selection_Disperse::loadStatServices().

107 {
108  if(_stater == NULL) _stater = new LCE_SelectionSH(this);
109  loader->attach(_stater);
110 }
LCE_SelectionSH * _stater
Definition: LCEselection.h:132
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:177
friend class LCE_SelectionSH
The StatHandler associated class is a friend.
Definition: LCEselection.h:82
virtual age_t LCE_Selection_base::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

References NONE.

300 {return NONE;}
#define NONE
No age flag.
Definition: types.h:48
virtual age_t LCE_Selection_base::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

References OFFSPRG.

302 {return OFFSPRG;}
#define OFFSPRG
Offspring age class flag.
Definition: types.h:50
void LCE_Selection_base::resetCounters ( )
inline

Resets the fitness counters.

Referenced by LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), execute(), and setParameters().

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  }
double _ind_cntr[5]
Definition: LCEselection.h:92
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:92
double _survival[5]
Definition: LCEselection.h:92
bool LCE_Selection_base::set_fit_model ( )

References _getFitness, _is_absolute, _is_local, SimComponent::_paramSet, _setScalingFactor, error(), ParamSet::getArg(), getFitnessAbsolute(), getFitnessRelative(), ParamSet::isSet(), setScalingFactorAbsolute(), setScalingFactorGlobal(), setScalingFactorLocal(), setScalingFactorMaxGlobal(), and setScalingFactorMaxLocal().

Referenced by LCE_Selection_base(), and setParameters().

203 {
204 
205  if(_paramSet->isSet("selection_fitness_model")) {
206 
207  string fit_model = _paramSet->getArg("selection_fitness_model");
208 
209  if(fit_model.compare("absolute") == 0) {
210 
211  _is_local = false;
212  _is_absolute = true;
215 
216  } else if(fit_model.compare("relative_local") == 0) {
217 
218  _is_local = true;
219  _is_absolute = false;
222 
223  } else if(fit_model.compare("relative_global") == 0) {
224 
225  _is_local = false;
226  _is_absolute = false;
229 
230  } else if(fit_model.compare("relative_max_local") == 0) {
231 
232  _is_local = true;
233  _is_absolute = false;
236 
237  } else if(fit_model.compare("relative_max_global") == 0) {
238 
239  _is_local = false;
240  _is_absolute = false;
243 
244  } else {
245  error("Unknown fitness model \"%s\"", fit_model.c_str());
246  return false;
247  }
248  } //default case:
249  else {
250  _is_local = false;
251  _is_absolute = true;
254  }
255 
256  return true;
257 }
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
double getFitnessAbsolute(Individual *ind, unsigned int patch)
Returns the raw fitness of the individual, without adjustment (absolute fitness). ...
Definition: LCEselection.cc:730
void setScalingFactorAbsolute(age_idx age, unsigned int p)
Resets the fitness scaling factor equal to one.
Definition: LCEselection.h:281
int error(const char *str,...)
Definition: output.cc:73
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
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
double(LCE_Selection_base::* _getFitness)(Individual *, unsigned int)
Pointer to the function returning the individual fitness.
Definition: LCEselection.h:120
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:285
bool isSet()
Accessor to the status flag.
Definition: param.h:273
double getFitnessRelative(Individual *ind, unsigned int patch)
Returns the relative fitness of the individual, adjusted by a scaling factor.
Definition: LCEselection.h:249
bool _is_absolute
Definition: LCEselection.h:90
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
bool _is_local
Definition: LCEselection.h:90
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
bool LCE_Selection_base::set_local_optima ( )

References _local_optima, SimComponent::_paramSet, LifeCycleEvent::_popPtr, _selectTraitDimension, error(), SimComponent::get_parameter(), ParamSet::getArg(), ParamSet::getMatrix(), Metapop::getPatchNbr(), ParamSet::isSet(), TMatrix::reset(), and setSpatialMatrix().

Referenced by execute(), LCE_Selection_base(), and setParameters().

529 {//set the traits' local optima, _selectTraitDimension must be set before that (= nbr of traits to select on)
530  string model = _paramSet->getArg("selection_model");
531 
532  if( model == "fix" || model == "direct") return true;
533 
534  if( (model == "gaussian" || model == "quadratic")
535  && !get_parameter("selection_local_optima")->isSet()) {
536 
537  return error("parameter \"selection_local_optima\" must be set to have Gaussian or quadratic selection.\n");
538 
539  } else {
540 
541  TMatrix tmp_mat;
542 
543  if(_local_optima == 0) _local_optima = new TMatrix();
544 
546 
547  _paramSet->getMatrix("selection_local_optima", &tmp_mat);
548 
549  return setSpatialMatrix("selection_local_optima", "\"selection_trait_dimension\"", &tmp_mat, _local_optima,
550  _selectTraitDimension, _popPtr->getPatchNbr(), _paramSet->isSet("selection_randomize"));
551  }
552 
553  return true;
554 }
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
Definition: utils.cc:87
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
TMatrix * _local_optima
Definition: LCEselection.h:58
unsigned int getPatchNbr()
Definition: metapop.h:270
int error(const char *str,...)
Definition: output.cc:73
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:285
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
bool isSet()
Accessor to the status flag.
Definition: param.h:273
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
bool LCE_Selection_base::set_param_rate_of_change ( )

References _do_change_local_opt, _rate_of_change_is_std, _rate_of_change_local_optima, _selectTraitDimension, _set_std_rate_at_generation, _setNewLocalOptima, _std_rate_reference_patch, TMatrix::assign(), changeLocalOptima(), error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), Param::getMatrix(), TMatrix::ncols(), TMatrix::nrows(), TMatrix::reset(), TMatrix::set(), and set_std_rate_of_change().

Referenced by LCE_Selection_base(), and setParameters().

559 {
560  _rate_of_change_is_std = false;
561  _do_change_local_opt = false;
562  _setNewLocalOptima = 0;
564 
565 
566  if (!get_parameter("selection_rate_environmental_change")->isSet()
567  && !get_parameter("selection_std_rate_environmental_change")->isSet() )
568  return true;
569 
570  if (get_parameter("selection_rate_environmental_change")->isSet()
571  && get_parameter("selection_std_rate_environmental_change")->isSet() ) {
572  return error("both \"selection_rate_environmental_change\" and \"selection_std_rate_environmental_change\" are set, need only one.\n");
573  }
574 
575  TMatrix tmpMat;
576 
577  if (get_parameter("selection_rate_environmental_change")->isSet()) {
578 
579  if(!get_parameter("selection_rate_environmental_change")->isMatrix()) {
580 
581  double val = get_parameter_value("selection_rate_environmental_change");
582 
583  tmpMat.reset(1, _selectTraitDimension);
584  tmpMat.assign(val);
585 
586  } else {
587  get_parameter("selection_rate_environmental_change")->getMatrix(&tmpMat);
588  }
589 
591 
592  } else if (get_parameter("selection_std_rate_environmental_change")->isSet()){
593 
594  if(!get_parameter("selection_std_rate_environmental_change")->isMatrix()) {
595 
596  double val = get_parameter_value("selection_std_rate_environmental_change");
597 
598  tmpMat.reset(1, _selectTraitDimension);
599  tmpMat.assign(val);
600 
601  } else {
602  get_parameter("selection_std_rate_environmental_change")->getMatrix(&tmpMat);
603  }
604 
605  _rate_of_change_is_std = true;
606 
607  if(get_parameter("selection_std_rate_set_at_generation")->isSet())
608  _set_std_rate_at_generation = (unsigned int)get_parameter_value("selection_std_rate_set_at_generation");
609  else
611 
612  //check if phenotypic SD is to be computed in a single reference patch
613  //is -1 if parameter not set, which corresponds to the whole population then
614  _std_rate_reference_patch = get_parameter_value("selection_std_rate_reference_patch");
615 
617  }
618 
619  if(tmpMat.nrows() != 1)
620  return error("The matrix of rate of change in local optima must be an array (nrows=1)\n");
621 
622  if((int)tmpMat.ncols() > _selectTraitDimension)
623  return error("The matrix of rate of change in local optima must have at most as many columns as dimensions of the trait(s) under selection\n");
624 
625  _do_change_local_opt = true;
626 
628 
629  unsigned int nVal = tmpMat.ncols();
630 
631  //copy values, with pattern propagation
632  for (int i = 0; i < _selectTraitDimension; ++i) {
633  _rate_of_change_local_optima.set(0, i, tmpMat.get(0, i % nVal));
634  }
635 
636  return true;
637 }
unsigned int ncols()
Definition: tmatrix.h:143
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
void assign(double val)
Assigns a value to all element of the matrix.
Definition: tmatrix.h:92
TMatrix _rate_of_change_local_optima
Definition: LCEselection.h:59
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:329
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void changeLocalOptima()
Definition: LCEselection.cc:1044
int error(const char *str,...)
Definition: output.cc:73
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
bool _rate_of_change_is_std
Definition: LCEselection.h:60
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
int _std_rate_reference_patch
Definition: LCEselection.h:62
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
void set_std_rate_of_change()
Definition: LCEselection.cc:915
unsigned int nrows()
Definition: tmatrix.h:140
bool _do_change_local_opt
Definition: LCEselection.h:60
unsigned int _set_std_rate_at_generation
Definition: LCEselection.h:61
bool LCE_Selection_base::set_sel_model ( )

References _base_fitness, _eVariance, _FitnessFixModel, _Fpedigree, _getRawFitness, _letheq, SimComponent::_paramSet, _SelectionModels, _selectTraitDimension, _TraitIndices, error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), getFitnessDirect(), getFitnessFixedEffect(), getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), getFitnessUnivariateGaussian(), getFitnessUnivariateGaussian_VE(), getFitnessUnivariateQuadratic(), Param::getMatrix(), Param::getMultiArgs(), TMatrix::getNbCols(), Param::isSet(), ParamSet::isSet(), setSelectionMatrix(), and warning().

Referenced by LCE_Selection_base(), and setParameters().

262 {
263 
264  _selectTraitDimension = (int)get_parameter_value("selection_trait_dimension");
265 
266  _base_fitness = get_parameter_value("selection_base_fitness");
267 
268 
269  // ENVIRONMENTAL VARIANCE
270  if(get_parameter("selection_environmental_variance")->isSet())
271  //the variable actually holds the standard dev...
272  _eVariance = sqrt(get_parameter_value("selection_environmental_variance"));
273  else
274  _eVariance = 0;
275 
276 
277  // SELECTION MODELS
278  _SelectionModels.clear();
279 
280  if(!_paramSet->isSet("selection_model")) {
281 
283 
284  _SelectionModels.push_back("direct");
285 
286  } else {
287 
288  _SelectionModels = get_parameter("selection_model")->getMultiArgs();
289  } //end_if isSet()
290 
291  if (_SelectionModels.size() != _TraitIndices.size()) {
292  error("\"selection_trait\" and \"selection_model\" must have the same number of arguments.");
293  return false;
294  }
295 
296 
297  // SET FUNCTION POINTERS TO FITNESS FUNCTIONS
298 
299  string sel_model;
300 
301  _getRawFitness.clear();
302 
303  for(unsigned int t = 0; t < _SelectionModels.size(); t++) {
304 
305  sel_model = _SelectionModels[t];
306 
307 
308  // FIX -----------------------------------------------------------------------
309  if(sel_model == "fix") {
310 
311  if(!get_parameter("selection_lethal_equivalents")->isSet()) {
312  error("\"selection_lethal_equivalents\" parameter is missing with \"fix\" selection!\n");
313  return false;
314  } else
315  _letheq = get_parameter_value("selection_lethal_equivalents");
316 
317  if(!get_parameter("selection_base_fitness")->isSet()) {
318  warning("\"selection_base_fitness\" parameter is missing under fix selection model, setting it to 1.\n");
319  _base_fitness = 1.0;
320  }
321 
322  if(!get_parameter("selection_pedigree_F")->isSet()) {
323 
324  return error("\"selection_pedigree_F\" parameter is missing with \"fix\" selection!\n");
325 
326  } else {
327 
328  TMatrix tmp_mat;
329 
330  get_parameter("selection_pedigree_F")->getMatrix(&tmp_mat);
331 
332  if(tmp_mat.getNbCols() != 5) {
333  return error("\"selection_pedigree_F\" must be an array of size 5.\n");
334  }
335 
336  for(unsigned int i = 0; i < 5; i++)
337  _Fpedigree[i] = tmp_mat.get(0,i);
338  }
339 
340  for(unsigned int i = 0; i < 5; i++)
341  _FitnessFixModel[i] = _base_fitness * exp( -_letheq * _Fpedigree[i] );
342 
344 
345  // DIRECT -----------------------------------------------------------------------
346  } else if(sel_model == "direct") {
347 
349 
350  // QUADRATIC --------------------------------------------------------------------
351  } else if(sel_model == "quadratic") {
352 
353  if(_selectTraitDimension == 1){
354 
355  if(!setSelectionMatrix()) return false; //this to set the selection variance params
356 
357  //now add the fitness function:
359 
360  } else return error("\"quadratic\" fitness model implemented for a single trait only.\n");
361 
362 
363  // GAUSSIAN --------------------------------------------------------------------
364  } else if(sel_model == "gaussian") {
365 
366  if(!setSelectionMatrix()) return false;
367 
368  if(_selectTraitDimension > 1) {
369 
370  if(_eVariance > 0)
372  else
374 
375  } else {
376 
377  if(_eVariance > 0)
379  else
381 
382  }
383 
384  } else return error("wrong selection model, must be either \"fix\", \"direct\", \"quadratic\", or \"gaussian\".\n");
385 
386  }
387 
388  if(sel_model != "fix" && !_paramSet->isSet("selection_trait"))
389  return error("trait under selection is not set, please add parameter \"selection_trait\"\n");
390 
391  return true;
392 }
bool setSelectionMatrix()
Definition: LCEselection.cc:396
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
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
vector< string > _SelectionModels
The selection models associated with each trait under selection.
Definition: LCEselection.h:111
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:329
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
int error(const char *str,...)
Definition: output.cc:73
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:108
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
void warning(const char *str,...)
Definition: output.cc:56
double _base_fitness
Definition: LCEselection.h:88
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
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
double _FitnessFixModel[5]
Absolute fitness values of the five pedigree class for the fixed selection model (lethal equivalents ...
Definition: LCEselection.h:76
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
double _letheq
Definition: LCEselection.h:88
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
double _eVariance
Evironmental variance.
Definition: LCEselection.h:104
bool isSet()
Accessor to the status flag.
Definition: param.h:273
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
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
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
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 getFitnessFixedEffect(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual in the fixed selection model.
Definition: LCEselection.h:210
vector< string > getMultiArgs()
Definition: param.cc:110
bool isSet()
Definition: param.h:138
void LCE_Selection_base::set_std_rate_of_change ( )

References SimRunner::_FileServices, LifeCycleEvent::_popPtr, _rate_of_change_local_optima, _selectTraitDimension, _set_std_rate_at_generation, _setNewLocalOptima, _std_rate_reference_patch, addPhenotypicSD(), TMatrix::assign(), changeLocalOptima(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), Metapop::getCurrentGeneration(), Param::getMatrix(), Metapop::getPatch(), Metapop::getPatchNbr(), Param::isMatrix(), FileServices::log(), SIMenv::MainSim, TMatrix::multi(), TMatrix::ncols(), OFFSx, TMatrix::reset(), TMatrix::set(), Patch::size(), and TMatrix::to_string().

Referenced by execute(), and set_param_rate_of_change().

916 {
918 
919  //reset rate_of_change matrix in each new replicate:
920  TMatrix tmpMat;
921 
922  if(!get_parameter("selection_std_rate_environmental_change")->isMatrix()) {
923 
924  double val = get_parameter_value("selection_std_rate_environmental_change");
925 
926  tmpMat.reset(1, _selectTraitDimension);
927  tmpMat.assign(val);
928 
929  } else {
930  get_parameter("selection_std_rate_environmental_change")->getMatrix(&tmpMat);
931  }
932 
933  unsigned int nVal = tmpMat.ncols();
934 
935  for (int i = 0; i < _selectTraitDimension; ++i) {
936  _rate_of_change_local_optima.set(0, i, tmpMat.get(0, i % nVal));
937  }
938 
939  double* SD = new double [_selectTraitDimension];
940 
941  for (int i = 0; i < _selectTraitDimension; ++i) {
942  SD[i] = 0;
943  }
944 
945  // check if SD is taken in a reference patch instead of the whole pop
946  if (_std_rate_reference_patch > -1) {
947 
950 
951  } else {
952  // compute SD as the mean within-patch SD
953 
954  unsigned int cnt = 0;
955 
956  //get SD only in extant demes, to avoid nans
957  for(unsigned int i = 0; i < _popPtr->getPatchNbr(); ++i) {
958  if (_popPtr->getPatch(i)->size(OFFSx) != 0 ) {
959  cnt++;
960  addPhenotypicSD(i, SD);
961  }
962  }
963 
964  //compute mean within-patch phenotypic standard deviation:
965  for (int i = 0; i < _selectTraitDimension; ++i) {
966  SD[i]/= cnt;
967 
968  }
969  } //end if
970 
971  //multiply the per-trait rates of change by SD:
972  for (int i = 0; i < _selectTraitDimension; ++i){
973  _rate_of_change_local_optima.multi(0, i, SD[i]);
974  }
975 
976  //log the rates in the simulation log file:
977  SIMenv::MainSim->_FileServices.log("#selection_rate_environmental_change " +
979 
980  //compute the change of local optima for current generation:
982 
983  //now reset the function pointer to changeLocalOptima() for next generation:
985 
986  delete [] SD;
987  }
988 }
void addPhenotypicSD(unsigned int deme, double *stDev)
Definition: LCEselection.cc:992
unsigned int ncols()
Definition: tmatrix.h:143
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
void assign(double val)
Assigns a value to all element of the matrix.
Definition: tmatrix.h:92
TMatrix _rate_of_change_local_optima
Definition: LCEselection.h:59
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:487
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:329
unsigned int getCurrentGeneration()
Definition: metapop.h:286
static SimRunner * MainSim
Definition: simenv.h:42
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:170
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:251
FileServices _FileServices
Definition: simulation.h:98
void changeLocalOptima()
Definition: LCEselection.cc:1044
unsigned int getPatchNbr()
Definition: metapop.h:270
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
void multi(unsigned int i, unsigned int j, double value)
Multiply an element of the matrix by a value.
Definition: tmatrix.h:199
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
int _std_rate_reference_patch
Definition: LCEselection.h:62
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
void log(string message)
Write to the parameter logfile.
Definition: fileservices.cc:187
Definition: types.h:42
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
string to_string()
Writes the matrix into a string in Nemo's matrix input format.
Definition: tmatrix.h:256
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
unsigned int _set_std_rate_at_generation
Definition: LCEselection.h:61
bool LCE_Selection_base::setLocalOptima ( )
double LCE_Selection_base::setMeanFitness ( age_idx  age)
inline

Sets the _mean_fitness variable to the value of the mean population fitness.

Parameters
agethe age-class index

References getMeanFitness().

198 { return (_mean_fitness = getMeanFitness(age));}
double _mean_fitness
Definition: LCEselection.h:89
double getMeanFitness(age_idx age)
Computes the mean fitness of the whole population for a given age class.
Definition: LCEselection.cc:742
void LCE_Selection_base::setMeans ( unsigned int  tot_ind)
inline

Computes the average fitness of each pedigree class.

Called after selection has been done in the whole population.

Parameters
tot_indcount of the total number of individuals produced

Referenced by LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), and execute().

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  }
double _ind_cntr[5]
Definition: LCEselection.h:92
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:92
double _mean_fitness
Definition: LCEselection.h:89
double _survival[5]
Definition: LCEselection.h:92
bool LCE_Selection_base::setParameters ( )
virtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

References LifeCycleEvent::_event_name, _getRawFitness, _max_fitness, _mean_fitness, LifeCycleEvent::_popPtr, _scaling_factor, _TraitIndices, error(), SimComponent::get_parameter(), Param::getMultiArgs(), IndFactory::getTraitIndex(), resetCounters(), set_fit_model(), set_local_optima(), set_param_rate_of_change(), and set_sel_model().

Referenced by LCE_Breed_Selection::setParameters(), and LCE_Breed_Selection_Disperse::setParameters().

151 {
152  //selection may on more than on trait at a time
153  vector< string > traits = get_parameter("selection_trait")->getMultiArgs();
154 
155  _TraitIndices.clear();
156 
157  for(unsigned int i = 0; i < traits.size(); i++) {
158 
159  if(_popPtr->getTraitIndex(traits[i].c_str()) == -1) {
160 
161  return error("cannot attach trait \"%s\" to life cycle event \"%s\", trait has not been initiated.\n",
162  traits[i].c_str(), _event_name.c_str());
163 
164  } else {
165  _TraitIndices.push_back(_popPtr->getTraitIndex(traits[i].c_str()));
166 
167 
168 #ifdef _DEBUG_
169  cout<<"#### attaching trait \""<<traits[i].c_str()<<"\" to selection LCE, index = "<<_TraitIndices[i]<<endl;
170 #endif
171 
172  }
173 
174  }
175 
176 
177  if(!set_fit_model()) return false;
178 
179  if(!set_sel_model()) return false;
180 
181  if(!set_local_optima()) return false;
182 
183  if(!set_param_rate_of_change()) return false;
184 
186  _scaling_factor = 1;
187  resetCounters();
188 
189  assert(_TraitIndices.size() == _getRawFitness.size());
190 
191 #ifdef _DEBUG_
192  cout<<"#### selection is acting on "<<_TraitIndices.size()<<" traits\n";
193  cout<<"#### selection is using "<< _getRawFitness.size() <<" fitness functions\n";
194 #endif
195 
196 
197  return true;
198 }
double _max_fitness
Definition: LCEselection.h:89
bool set_sel_model()
Definition: LCEselection.cc:261
int error(const char *str,...)
Definition: output.cc:73
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:108
bool set_local_optima()
Definition: LCEselection.cc:528
std::string _event_name
The param name to be read in the init file.
Definition: lifecycleevent.h:77
double _mean_fitness
Definition: LCEselection.h:89
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.h:153
bool set_fit_model()
Definition: LCEselection.cc:202
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
bool set_param_rate_of_change()
Definition: LCEselection.cc:558
int getTraitIndex(trait_t type)
Gives the index of trait with type.
Definition: indfactory.cc:128
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
double _scaling_factor
Definition: LCEselection.h:89
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
vector< string > getMultiArgs()
Definition: param.cc:110
void LCE_Selection_base::setScalingFactorAbsolute ( age_idx  age,
unsigned int  p 
)
inline

Resets the fitness scaling factor equal to one.

Parameters
agethe age-class index
pthe focal patch index

Referenced by set_fit_model().

282  { _scaling_factor = 1; }
double _scaling_factor
Definition: LCEselection.h:89
void LCE_Selection_base::setScalingFactorGlobal ( age_idx  age,
unsigned int  p 
)

Sets the fitness scaling factor equal to the inverse of the mean population fitness.

Function exits on p != 0; the mean population fitness is computed only once in the execute() procedure, at the beginning of the patch loop.

Parameters
agethe age-class index
pthe focal patch index

References _scaling_factor, and getMeanFitness().

Referenced by set_fit_model(), and LCE_SelectionSH::setDataTable().

821 {
822  if(p != 0) return; //we compupte the mean fitness only once
823  _scaling_factor = 1;
824  _scaling_factor = 1.0/getMeanFitness(age);
825 }
double _scaling_factor
Definition: LCEselection.h:89
double getMeanFitness(age_idx age)
Computes the mean fitness of the whole population for a given age class.
Definition: LCEselection.cc:742
void LCE_Selection_base::setScalingFactorLocal ( age_idx  age,
unsigned int  p 
)

Sets the fitness scaling factor equal to the inverse of the mean local patch fitness.

Parameters
agethe age-class index
pthe focal patch index

References _scaling_factor, and getMeanPatchFitness().

Referenced by set_fit_model(), and LCE_SelectionSH::setDataTable().

813 {
814  _scaling_factor = 1; //this to have the raw mean fitness below
815  _scaling_factor = 1.0/getMeanPatchFitness(age, p);
816 }
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
double _scaling_factor
Definition: LCEselection.h:89
void LCE_Selection_base::setScalingFactorMaxGlobal ( age_idx  age,
unsigned int  p 
)

Sets the fitness scaling factor equal to the inverse of the maximum population fitness value.

Function exits on p != 0; the mean population fitness is computed only once in the execute() procedure, at the beginning of the patch loop.

Parameters
agethe age-class index
pthe focal patch index

References _scaling_factor, and getMaxFitness().

Referenced by set_fit_model().

839 {
840  if(p != 0) return; //we compute the max fitness only once
841  _scaling_factor = 1;
842  _scaling_factor = 1.0/getMaxFitness(age);
843 }
double getMaxFitness(age_idx age)
Computes the maximum fitness value of the whole population for a given age class. ...
Definition: LCEselection.cc:776
double _scaling_factor
Definition: LCEselection.h:89
void LCE_Selection_base::setScalingFactorMaxLocal ( age_idx  age,
unsigned int  p 
)

Sets the fitness scaling factor equal to the inverse of the maximum local patch fitness value.

Parameters
agethe age-class index
pthe focal patch index

References _scaling_factor, and getMaxPatchFitness().

Referenced by set_fit_model().

831 {
832  _scaling_factor = 1; //this to have the raw fitness when computing fitnesses below
833  _scaling_factor = 1.0/getMaxPatchFitness(age, p);
834 }
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
double _scaling_factor
Definition: LCEselection.h:89
bool LCE_Selection_base::setSelectionMatrix ( )

References _diffs, _gsl_selection_matrix, SimComponent::_paramSet, LifeCycleEvent::_popPtr, _res1, _selection_matrix, _selection_variance, _selectTraitDimension, TMatrix::assign(), error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), ParamSet::getMatrix(), TMatrix::getNbCols(), TMatrix::getNbRows(), Metapop::getPatchNbr(), ParamSet::isSet(), TMatrix::reset(), TMatrix::set(), and setSpatialMatrix().

Referenced by set_sel_model().

397 {
398  TMatrix tmp_mat;
399  unsigned int patchNbr = _popPtr->getPatchNbr();
400 
401  if(!get_parameter("selection_matrix")->isSet() && !get_parameter("selection_variance")->isSet())
402  return error("\"selection_matrix\" or \"selection_variance\" must be set with selection model = \"gaussian\".\n");
403 
404 
405  if(get_parameter("selection_variance")->isSet() && !get_parameter("selection_trait_dimension")->isSet())
406  return error("parameter \"selection_trait_dimension\" is missing!\n");
407 
408 
409  //clear the selection matrix container
410  vector< TMatrix* >::iterator selIT = _selection_matrix.begin();
411 
412  for(; selIT != _selection_matrix.end(); ++selIT) if((*selIT)) delete (*selIT);
413 
414  _selection_matrix.clear();
415 
416 
417  if(get_parameter("selection_matrix")->isSet()) {
418 
419  //selection matrix provided, same selection surface in each patch
420  _paramSet->getMatrix("selection_matrix", &tmp_mat);
421 
422  if(tmp_mat.getNbCols() != tmp_mat.getNbRows())
423  return error("\"selection_matrix\" must be a square matrix!\n");
424 
425  _selectTraitDimension = tmp_mat.getNbCols();
426 
427  //we have one selection matrix per patch, copy it in the container for each patch
428  for(unsigned int i = 0; i < patchNbr; ++i)
429  _selection_matrix.push_back( new TMatrix(tmp_mat) );
430 
431  } else {
432  //we have to check for spatial variation in variance and covariances
433  _selectTraitDimension = (unsigned int)get_parameter_value("selection_trait_dimension");
434 
435  TMatrix var_spatmat, corr_spatmat;
436 
437  //setting variance spatial matrix:
438  var_spatmat.reset(patchNbr, (unsigned)_selectTraitDimension);
439 
440  if(get_parameter("selection_variance")->isMatrix()) {
441 
442  _paramSet->getMatrix("selection_variance", &tmp_mat);
443 
444  if( !setSpatialMatrix("selection_variance","\"selection_trait_dimension\"", &tmp_mat, &var_spatmat,
445  (unsigned)_selectTraitDimension, patchNbr, _paramSet->isSet("selection_randomize") ) )
446  return false;
447 
448  } else {
449 
450  var_spatmat.assign(get_parameter_value("selection_variance"));
451  }
452 
453  //setting correlation spatial matrix:
454  corr_spatmat.reset(patchNbr, (unsigned)_selectTraitDimension*(_selectTraitDimension-1)/2);
455 
456  if(get_parameter("selection_correlation")->isMatrix()) {
457 
458  _paramSet->getMatrix("selection_correlation", &tmp_mat);
459 
460  if( !setSpatialMatrix("selection_correlation","the num of correlation coefficients", &tmp_mat, &corr_spatmat,
461  (unsigned)_selectTraitDimension*(_selectTraitDimension-1)/2, patchNbr, _paramSet->isSet("selection_randomize") ) )
462  return false;
463 
464  } else {
465 
466  corr_spatmat.assign((get_parameter("selection_correlation")->isSet() ?
467  get_parameter_value("selection_correlation") : 0.0 ));
468  }
469 
470  //set the selection matrix:
471  tmp_mat.reset(_selectTraitDimension, _selectTraitDimension);
472  double covar;
473  unsigned int col;
474  for( unsigned int p = 0; p < patchNbr; p++) {
475  col = 0;
476  for( int i = 0; i < _selectTraitDimension; i++) {
477  tmp_mat.set(i, i, var_spatmat.get(p, i));
478  for( int j = i+1; j < _selectTraitDimension; j++) {
479  covar = corr_spatmat.get(p, col) * sqrt( var_spatmat.get(p, i) * var_spatmat.get(p, j) );
480  tmp_mat.set(i, j, covar);
481  tmp_mat.set(j, i, covar);
482  col++;
483  }
484  }
485  _selection_matrix.push_back(new TMatrix(tmp_mat));
486  }
487  }
488 
489  if(_selectTraitDimension > 1) {
490 
491  //selection on more than one trait
492 
493  //inversing the selection matrices:
494  if(_gsl_selection_matrix.size() != 0)
495  for(unsigned int i = 0; i < _gsl_selection_matrix.size(); ++i)
496  if(_gsl_selection_matrix[i] != NULL) gsl_matrix_free( _gsl_selection_matrix[i] );
497 
498  _gsl_selection_matrix.clear();
499 
500  for( unsigned int p = 0; p < patchNbr; p++) {
501  _selection_matrix[p]->inverse();
502 
503  _gsl_selection_matrix.push_back( gsl_matrix_alloc(_selectTraitDimension, _selectTraitDimension) );
504 
505  _selection_matrix[p]->get_gsl_matrix(_gsl_selection_matrix[p]);
506  }
507 
508  //allocate the vectors used by the fitness function:
509  if(_diffs != NULL) gsl_vector_free(_diffs);
510  _diffs = gsl_vector_alloc( _selectTraitDimension );
511 
512  if(_res1 != NULL) gsl_vector_free(_res1);
513  _res1 = gsl_vector_alloc( _selectTraitDimension );
514 
515  } else {
516 
517  //selection on one trait only
518  _selection_variance.clear();
519 
520  for(unsigned int p = 0; p < patchNbr; p++)
521  _selection_variance.push_back( _selection_matrix[p]->get(0, 0) );
522  }
523 
524 
525  return true;
526 }
gsl_vector * _diffs
Definition: LCEselection.h:57
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
void assign(double val)
Assigns a value to all element of the matrix.
Definition: tmatrix.h:92
unsigned int getNbCols()
Gives the number of columns.
Definition: tmatrix.h:142
unsigned int getNbRows()
Gives the number of rows.
Definition: tmatrix.h:139
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
Definition: utils.cc:87
double get(unsigned int i, unsigned int j)
Accessor to element at row i and column j.
Definition: tmatrix.h:120
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:289
unsigned int getPatchNbr()
Definition: metapop.h:270
int error(const char *str,...)
Definition: output.cc:73
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:85
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
vector< TMatrix * > _selection_matrix
Definition: LCEselection.h:55
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:56
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:98
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions.
Definition: tmatrix.h:97
bool isSet()
Accessor to the status flag.
Definition: param.h:273
gsl_vector * _res1
Definition: LCEselection.h:57
vector< double > _selection_variance
Patch-specific selection variance.
Definition: LCEselection.h:101
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81

Friends And Related Function Documentation

friend class LCE_Breed_Selection
friend
friend class LCE_SelectionFH
friend

Referenced by loadFileServices().

friend class LCE_SelectionSH
friend

The StatHandler associated class is a friend.

Referenced by loadStatServices().

Member Data Documentation

gsl_vector* LCE_Selection_base::_diffs
private
bool LCE_Selection_base::_do_change_local_opt
private
double LCE_Selection_base::_eVariance
protected
double LCE_Selection_base::_fitness[5]
protected
double LCE_Selection_base::_FitnessFixModel[5]
private

Absolute fitness values of the five pedigree class for the fixed selection model (lethal equivalents model).

Fitness is computed as: _FitnessFixModel[i] = _base_fitness * exp( -_letheq * _Fpedigree[i] );

Referenced by set_sel_model().

double LCE_Selection_base::_Fpedigree[5]
private

Array of pedigree values used in the fixed-selection model.

Referenced by set_sel_model().

double(LCE_Selection_base::* LCE_Selection_base::_getFitness)(Individual *, unsigned int)
protected

Pointer to the function returning the individual fitness.

May point to LCE_Selection_base::getFitnessAbsolute or LCE_Selection_base::getFitnessRelative.

Referenced by getFitness(), and set_fit_model().

vector< double (LCE_Selection_base::* ) (Individual*, unsigned int, unsigned int) > LCE_Selection_base::_getRawFitness
protected

A vector containing pointers to fitness function related to each trait under selection.

Referenced by getFitnessAbsolute(), LCE_SelectionFH::print(), set_sel_model(), and setParameters().

vector< gsl_matrix* > LCE_Selection_base::_gsl_selection_matrix
private
bool LCE_Selection_base::_is_absolute
protected
bool LCE_Selection_base::_is_local
protected
double LCE_Selection_base::_letheq
protected

Referenced by set_sel_model().

double LCE_Selection_base::_max_fitness
protected

Referenced by setParameters().

double* LCE_Selection_base::_phe
private
bool LCE_Selection_base::_rate_of_change_is_std
private
TMatrix LCE_Selection_base::_rate_of_change_local_optima
private
gsl_vector * LCE_Selection_base::_res1
private
vector< TMatrix* > LCE_Selection_base::_selection_matrix
private
vector< double > LCE_Selection_base::_selection_variance
protected
vector< string > LCE_Selection_base::_SelectionModels
protected

The selection models associated with each trait under selection.

Referenced by set_sel_model().

unsigned int LCE_Selection_base::_set_std_rate_at_generation
private
void(LCE_Selection_base::* LCE_Selection_base::_setNewLocalOptima)(void)
protected

Pointer to the function used to change the local phenotypic optima or its rate of change.

May point to LCE_Selection_base::changeLocalOptima or LCE_Selection_base::set_std_rate_of_change.

Referenced by execute(), set_param_rate_of_change(), and set_std_rate_of_change().

void(LCE_Selection_base::* LCE_Selection_base::_setScalingFactor)(age_idx, unsigned int)
protected

Pointer to the function used to set the fitness scaling factor when fitness is relative.

May point to LCE_Selection_base::setScalingFactorGlobal, LCE_Selection_base::setScalingFactorLocal, or LCE_Selection_base::setScalingFactorAbsolute (returns 1).

Referenced by LCE_Breed_Selection::do_breed_selection_FecFitness(), execute(), and set_fit_model().

LCE_SelectionSH* LCE_Selection_base::_stater
protected
int LCE_Selection_base::_std_rate_reference_patch
private
vector< unsigned int > LCE_Selection_base::_TraitIndices
protected
LCE_SelectionFH* LCE_Selection_base::_writer
protected

Referenced by loadFileServices().


The documentation for this class was generated from the following files:

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