Nemo  2.4.0
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
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 setSelectTraitMapping (unsigned int num_quanti_traits)
 
bool setSelectionOffset (double default_val, double min_val)
 
bool setLocalOptima ()
 
const TMatrixgetLocalOptima () const
 
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...
 
void updateFitnessCounters (double fitness, unsigned int ped_class, bool survived)
 Updates the fitness and survival mean counters. 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 getFitnessUnivariateLinear (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following a Linear selection model with a single trait under selection. More...
 
double getFitnessUnivariateDisruptive (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with one trait under selection. More...
 
double getFitnessMultivariateDisruptive (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with several traits under selection. More...
 
double getFitnessTruncation (Individual *offsprg, unsigned int patch, unsigned int trait)
 Returns the fitness of an individual following a Truncation selection model. 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 setScalingFactorForLinearSelection (age_idx age, unsigned int p)
 Sets the fitness scaling factor as the mean trait value in the patch to compute the fitness value in the linear selection model. 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...
 
void checkChangeLocalOptima ()
 Check is rate of change in local optima has been set and must be applied. More...
 
Implementations
virtual bool setParameters ()
 
virtual void execute ()
 
virtual void loadStatServices (StatServices *loader)
 
virtual void loadFileServices (FileServices *loader)
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
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...
 
virtual bool has_parameter (std::string name)
 Param getter. More...
 

Protected Attributes

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< string > _Traits
 The list of trait types under selection. More...
 
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< unsigned int > _selectTraitMapping
 Mapping from selection dimension index to quanti trait index (0-based). 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
 
Linear selection parameters

Array to temporarily hold the phenotypic values of an individual, is never allocated.

TMatrix _linear_selection_strength
 
vector< double > _mean_trait_value
 
unsigned int _linearSelTraitIndex
 
age_idx _linearSelAgeClass
 
Shared selection offset (used by linear, disruptive, and truncation models)
TMatrix _selection_offset
 
Truncation selection parameters
TMatrix _truncation_threshold
 
bool _truncation_upper
 
Fixed selection (lethal-equivalents-based) parameters
double _letheq
 
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::LCE_Selection_base ( )
45  : LifeCycleEvent("viability_selection", ""),
48 _diffs(0),
49 _res1(0),
57 _truncation_upper(true),
58 _letheq(0),
59 _base_fitness(1),
60 _mean_fitness(0),
61 _max_fitness(0),
63 _is_local(0),
64 _is_absolute(1),
65 _eVariance(0),
67 _getFitness(0),
70 _stater(0),
71 _writer(0)
72 {
73  // mandatory parameter (no default):
74  add_parameter("selection_trait", STR, true, false, 0, 0); //no updaters here, to keep it safe...
75 
78 
79  add_parameter("selection_fitness_model",STR,false,false,0,0, updater);
80 
82 
83  add_parameter("selection_model",STR,true,false,0,0, updater); //mandatory, depends on trait
84  add_parameter("selection_matrix",MAT,false,false,0,0, updater);
85  add_parameter("selection_variance",DBL,false,false,0,0, updater);
86  add_parameter("selection_correlation",DBL,false,false,0,0, updater);
87  add_parameter("selection_trait_dimension",INT,false,false,0,0, updater);
88  add_parameter("selection_base_fitness",DBL,false,true,0,1, updater);
89  add_parameter("selection_lethal_equivalents",DBL,false,false,0,0, updater);
90  add_parameter("selection_pedigree_F",MAT,false,false,0,0, updater);
91  add_parameter("selection_randomize",BOOL,false,false,0,0, updater);
92  add_parameter("selection_environmental_variance", DBL, false, false, 0, 0, updater);
93 
94  // linear selection:
95  add_parameter("selection_linear_strength", DBL, false, false, 0, 0, updater);
96  add_parameter("selection_offset", DBL, false, false, 0, 0, updater);
97  add_parameter("selection_at_stage", STR, false, false, 0, 0, updater);
98 
99  // truncation selection:
100  add_parameter("selection_truncation_threshold", DBL, false, false, 0, 0, updater);
101  add_parameter("selection_truncation_direction", STR, false, false, 0, 0, updater);
102 
104  add_parameter("selection_local_optima",DBL,false,false,0,0, updater);
105 
107  //renaming parameters:
108  add_parameter("selection_local_optima_rate_change", DBL, false, false, 0, 0, updater);
109  add_parameter("selection_local_optima_std_rate_change", DBL, false, false, 0, 0, updater);
110  add_parameter("selection_local_optima_std_rate_set_at_generation", INT, false, false, 0, 0, updater);
111  add_parameter("selection_local_optima_std_rate_reference_patch", INT, false, false, 0, 0, updater);
112 
113 // add_parameter("selection_rate_environmental_change", DBL, false, false, 0, 0, updater);
114 // add_parameter("selection_std_rate_environmental_change", DBL, false, false, 0, 0, updater);
115 // add_parameter("selection_std_rate_set_at_generation", INT, false, false, 0, 0, updater);
116 // add_parameter("selection_std_rate_reference_patch", INT, false, false, 0, 0, updater);
117 
118 
119  add_parameter("selection_output", BOOL, false, false, 0, 0, 0);
120  add_parameter("selection_output_logtime", INT, false, false, 0, 0, 0);
121  add_parameter("selection_output_dir", STR, false, false, 0, 0, 0);
122 }
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:123
double _base_fitness
Definition: LCEselection.h:111
double(LCE_Selection_base::* _getFitness)(Individual *, unsigned int)
Pointer to the function returning the individual fitness.
Definition: LCEselection.h:151
double _max_fitness
Definition: LCEselection.h:112
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:55
LCE_SelectionFH * _writer
Definition: LCEselection.h:165
unsigned int _linearSelTraitIndex
Definition: LCEselection.h:74
gsl_vector * _diffs
Definition: LCEselection.h:56
bool set_param_rate_of_change()
Definition: LCEselection.cc:904
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:156
bool _is_absolute
Definition: LCEselection.h:114
double _eVariance
Evironmental variance.
Definition: LCEselection.h:132
double _scaling_factor
Definition: LCEselection.h:112
bool _do_change_local_opt
Definition: LCEselection.h:60
bool _is_local
Definition: LCEselection.h:113
gsl_vector * _res1
Definition: LCEselection.h:57
bool set_sel_model()
Definition: LCEselection.cc:317
unsigned int _set_std_rate_at_generation
Definition: LCEselection.h:62
double _mean_fitness
Definition: LCEselection.h:112
bool set_fit_model()
Definition: LCEselection.cc:259
LCE_SelectionSH * _stater
Definition: LCEselection.h:164
int _std_rate_reference_patch
Definition: LCEselection.h:63
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:160
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:147
bool _truncation_upper
Definition: LCEselection.h:86
bool set_local_optima()
Definition: LCEselection.cc:865
double _letheq
Definition: LCEselection.h:92
vector< TMatrix * > _selection_matrix
Definition: LCEselection.h:54
bool _rate_of_change_is_std
Definition: LCEselection.h:61
age_idx _linearSelAgeClass
Definition: LCEselection.h:75
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:97
Implementation of the ParamUpdaterBase interface.
Definition: param.h:362
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:111
@ DBL
Definition: types.h:77
@ MAT
Definition: types.h:77
@ BOOL
Definition: types.h:77
@ STR
Definition: types.h:77
@ INT
Definition: types.h:77
@ OFFSx
Definition: types.h:41

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().

+ Here is the caller graph for this function:

◆ ~LCE_Selection_base()

LCE_Selection_base::~LCE_Selection_base ( )
virtual
127 {
128  vector< TMatrix* >::iterator selIT = _selection_matrix.begin();
129  for(; selIT != _selection_matrix.end(); ++selIT)
130  if((*selIT)) delete (*selIT);
131  _selection_matrix.clear();
132 
133  for(unsigned int i = 0; i < _gsl_selection_matrix.size(); ++i)
134  if(_gsl_selection_matrix[i]) gsl_matrix_free(_gsl_selection_matrix[i]);
135  _gsl_selection_matrix.clear();
136 
137  if(_diffs) gsl_vector_free(_diffs);
138  if(_res1) gsl_vector_free(_res1);
139  if(_stater) delete _stater;
140 }

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_Selection_base::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

348 {return NONE;}
#define NONE
No age flag.
Definition: types.h:47

References NONE.

◆ addPhenotypicSD()

void LCE_Selection_base::addPhenotypicSD ( unsigned int  deme,
double *  stDev 
)
1530 {
1531  Patch *patch = _popPtr->getPatch(deme);
1532  Individual* ind;
1533  unsigned int table_size = patch->size(OFFSx);
1534  double* _phe;
1535 
1536  double **phenot = new double* [_selectTraitDimension];
1537 
1538  for (int i = 0; i < _selectTraitDimension; ++i) {
1539 
1540  phenot[i] = new double [table_size];
1541 
1542  }
1543 
1544  unsigned int pos = 0;
1545 
1546  for (unsigned int j = 0; j < patch->size(FEM, OFFSx) && pos < table_size; ++j) {
1547 
1548  ind = patch->get(FEM, OFFSx, j);
1549  _phe = (double*)ind->getTraitValue(_LCELinkedTraitIndex);
1550 
1551  for (int i = 0; i < _selectTraitDimension; ++i)
1552  phenot[i][pos] = _phe[_selectTraitMapping[i]];
1553 
1554  pos++;
1555 
1556  }
1557 
1558  for (unsigned int j = 0; j < patch->size(MAL, OFFSx) && pos < table_size; ++j) {
1559 
1560  ind = patch->get(MAL, OFFSx, j);
1561  _phe = (double*)ind->getTraitValue(_LCELinkedTraitIndex);
1562 
1563  for (int i = 0; i < _selectTraitDimension; ++i)
1564  phenot[i][pos] = _phe[_selectTraitMapping[i]];
1565 
1566  pos++;
1567 
1568  }
1569 
1570  assert(pos == table_size);
1571 
1572  for (int i = 0; i < _selectTraitDimension; ++i) {
1573  stDev[i] += sqrt( my_variance_with_fixed_mean( phenot[i], table_size, my_mean(phenot[i], table_size) ) );
1574  delete [] phenot[i];
1575  }
1576 
1577  delete [] phenot;
1578 }
This class contains traits along with other individual information (sex, pedigree,...
Definition: individual.h:48
void * getTraitValue(IDX T)
Accessor to the value (phenotype) of a particular trait.
Definition: individual.h:270
vector< unsigned int > _selectTraitMapping
Mapping from selection dimension index to quanti trait index (0-based).
Definition: LCEselection.h:126
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:88
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:80
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:256
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:431
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:497
Individual * get(sex_t SEX, age_idx AGE, unsigned int at)
Returns a pointer to the individual sitting at the index passed.
Definition: metapop.h:533
@ FEM
Definition: types.h:36
@ MAL
Definition: types.h:36
double my_mean(double *data, unsigned int size)
Definition: utils.cc:37
double my_variance_with_fixed_mean(double *data, unsigned int size, double mean)
Definition: utils.cc:62

References LifeCycleEvent::_LCELinkedTraitIndex, LifeCycleEvent::_popPtr, _selectTraitDimension, _selectTraitMapping, 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().

+ Here is the caller graph for this function:

◆ changeLocalOptima()

void LCE_Selection_base::changeLocalOptima ( )
1313 {
1314  for (int i = 0; i < _selectTraitDimension; ++i)
1315  for (unsigned int j = 0; j < _local_optima.nrows(); ++j) {
1317  }
1318 }
TMatrix _rate_of_change_local_optima
Definition: LCEselection.h:59
TMatrix _local_optima
Definition: LCEselection.h:58
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:192
void plus(unsigned int i, unsigned int j, double value)
Adds a value to an element of the matrix.
Definition: tmatrix.h:255
unsigned int nrows() const
Definition: tmatrix.h:212

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().

+ Here is the caller graph for this function:

◆ checkChangeLocalOptima()

void LCE_Selection_base::checkChangeLocalOptima ( )

Check is rate of change in local optima has been set and must be applied.

1323 {
1324  // check if change in local optima for quantitative traits
1325  if(_do_change_local_opt) {
1326 
1327  if(_popPtr->getCurrentGeneration() == 1) {
1328 
1329  set_local_optima(); //reset local optima to initial values
1330 
1331  if(_rate_of_change_is_std) //reset rate of change relative to SD of that replicate
1333  }
1334 
1335  (this->*_setNewLocalOptima)();
1336  }
1337 }
void set_std_rate_of_change()
Definition: LCEselection.cc:1445
unsigned int getCurrentGeneration()
Definition: metapop.h:295

References _do_change_local_opt, LifeCycleEvent::_popPtr, _rate_of_change_is_std, _setNewLocalOptima, Metapop::getCurrentGeneration(), set_local_optima(), and set_std_rate_of_change().

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

+ Here is the caller graph for this function:

◆ clone()

virtual LifeCycleEvent* LCE_Selection_base::clone ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

346 {return new LCE_Selection_base();}
LCE_Selection_base()
Definition: LCEselection.cc:45

References LCE_Selection_base().

◆ doViabilitySelection()

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
1376 {
1377  Individual* ind;
1378  double fitness;
1379  bool not_survived;
1380 
1381  for(unsigned int i = 0; i < patch->size(SEX, AGE); i++) {
1382 
1383  ind = patch->get(SEX, AGE, i);
1384 
1385  fitness = getFitness( ind, p);
1386 
1387  not_survived = ( RAND::Uniform() > fitness );
1388 
1389  if( not_survived ) {
1390 
1391  //this individual dies
1392  patch->remove(SEX, AGE, i);
1393 
1394  _popPtr->recycle(ind);
1395 
1396  i--;
1397 
1398  } //else; this individual stays in the patch
1399 
1400  updateFitnessCounters(fitness, ind->getPedigreeClass(), !not_survived);
1401  }
1402 }
void recycle(Individual *ind)
Put an individual in the recycling pool.
Definition: indfactory.h:61
unsigned int getPedigreeClass()
Returns the pedigree class of the individual, as set during offspring creation.
Definition: individual.h:178
double getFitness(Individual *ind, unsigned int patch)
Calls the fitness function according to the fitness model.
Definition: LCEselection.h:229
void updateFitnessCounters(double fitness, unsigned int ped_class, bool survived)
Updates the fitness and survival mean counters.
Definition: LCEselection.cc:1433
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:587
static double Uniform()
Generates a random number from [0.0, 1.0[ uniformly distributed.
Definition: Uniform.h:126

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

Referenced by execute().

+ Here is the caller graph for this function:

◆ execute()

void LCE_Selection_base::execute ( )
virtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

1342 {
1343  Patch * patch;
1344  unsigned int popSize = _popPtr->size(OFFSPRG);
1345 
1346 #ifdef _DEBUG_
1347  message("LCE_Selection_base::execute (tot offsprg nb: %i", popSize);
1348 #endif
1349 
1350  resetCounters();
1351 
1352  // check if change in local optima for quantitative traits
1354 
1355  for(unsigned int p = 0; p < _popPtr->getPatchNbr(); p++) {
1356 
1357  (this->*_setScalingFactor)(OFFSx, p);
1358 
1359  patch = _popPtr->getPatch(p);
1360 
1361  doViabilitySelection(FEM, OFFSx, patch, p);
1362 
1363  doViabilitySelection(MAL, OFFSx, patch, p);
1364  }
1365 
1366  setMeans(popSize);
1367 
1368 #ifdef _DEBUG_
1369  message(", after selection: %i, mean fitness offspring=%f)\n",_popPtr->size(OFFSPRG), _mean_fitness);
1370 #endif
1371 }
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:1375
void checkChangeLocalOptima()
Check is rate of change in local optima has been set and must be applied.
Definition: LCEselection.cc:1322
void setMeans(unsigned int tot_ind)
Computes the average fitness of each pedigree class.
Definition: LCEselection.cc:1417
void resetCounters()
Resets the fitness counters.
Definition: LCEselection.cc:1406
unsigned int size()
Get the total number of individuals present in the population, all sex and age classes together.
Definition: metapop.h:311
unsigned int getPatchNbr()
Definition: metapop.h:275
void message(const char *message,...)
Definition: output.cc:39
#define OFFSPRG
Offspring age class flag.
Definition: types.h:49

References _mean_fitness, LifeCycleEvent::_popPtr, _setScalingFactor, checkChangeLocalOptima(), doViabilitySelection(), FEM, Metapop::getPatch(), Metapop::getPatchNbr(), MAL, message(), OFFSPRG, OFFSx, resetCounters(), setMeans(), and Metapop::size().

◆ getFitness()

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
230  {
231  return (this->*_getFitness)(ind, patch);
232  }

References _getFitness.

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

+ Here is the caller graph for this function:

◆ getFitnessAbsolute()

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
1152 {
1153  double fitness = 1;
1154  //at this point, _getRawFitness.size() == _TraitIndices.size()
1155  //and we assume that the functions are "aligned" with the traits
1156  for(unsigned int i = 0; i < _getRawFitness.size(); i++)
1157  fitness *= (this->*_getRawFitness[i])(ind, patch, _TraitIndices[i]);
1158  return fitness;
1159 }
vector< unsigned int > _TraitIndices
The indices of the traits under selection.
Definition: LCEselection.h:139

References _getRawFitness, and _TraitIndices.

Referenced by getFitnessRelative(), and set_fit_model().

+ Here is the caller graph for this function:

◆ getFitnessDirect()

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.

242  {
243  return *(double*)offsprg->getTraitValue(trait);
244  }

References Individual::getTraitValue().

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessFixedEffect()

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.

236  {
237  return _FitnessFixModel[ offsprg->getPedigreeClass() ];
238  }
double _FitnessFixModel[5]
Absolute fitness values of the five pedigree class for the fixed selection model (lethal equivalents ...
Definition: LCEselection.h:99

References _FitnessFixModel, and Individual::getPedigreeClass().

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessMultivariateDisruptive()

double LCE_Selection_base::getFitnessMultivariateDisruptive ( Individual offsprg,
unsigned int  patch,
unsigned int  trait 
)

Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with several traits under selection.

1020 {
1021  double res2;
1022 
1023  double *_phe = (double*)ind->getTraitValue(trait);
1024 
1025  // W = offset * (1 - exp(-0.5 * dT * Sigma^-1 * d)) inverted multivariate Gaussian
1026  for( int i = 0; i < _selectTraitDimension; i++)
1027  gsl_vector_set(_diffs, i, _phe[_selectTraitMapping[i]] - _local_optima.get(patch, i));
1028 
1029  // (diff)T * W * diff:
1030  gsl_blas_dsymv(CblasUpper, 1.0, _gsl_selection_matrix[patch], _diffs, 0.0, _res1);
1031  gsl_blas_ddot(_diffs, _res1, &res2);
1032 
1033  return _selection_offset.get(patch, 0) * (1.0 - exp( -0.5 * res2 ));
1034 }
TMatrix _selection_offset
Definition: LCEselection.h:80

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

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessMultivariateGaussian()

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.

1095 {
1096  double res2;
1097 
1098  double *_phe = (double*)ind->getTraitValue(trait);
1099 
1100  for( int i = 0; i < _selectTraitDimension; i++)
1101  gsl_vector_set(_diffs, i, _phe[_selectTraitMapping[i]] - _local_optima.get(patch, i));
1102 
1103  //(diff)T * W * diff:
1104  //right partial product:
1105  gsl_blas_dsymv(CblasUpper, 1.0, _gsl_selection_matrix[patch], _diffs, 0.0, _res1);
1106  //left product:
1107  gsl_blas_ddot(_diffs, _res1, &res2);
1108 
1109  return exp( -0.5 * res2 );
1110 }

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

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessMultivariateGaussian_VE()

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.

1131 {
1132  double res2;
1133 
1134  double *_phe = (double*)ind->getTraitValue(trait);
1135 
1136  //add the environmental variance here:
1137  for( int i = 0; i < _selectTraitDimension; i++)
1138  gsl_vector_set(_diffs, i, _phe[_selectTraitMapping[i]] + RAND::Gaussian(_eVariance) - _local_optima.get(patch, i));
1139 
1140  //(diff)T * W * diff:
1141  //right partial product:
1142  gsl_blas_dsymv(CblasUpper, 1.0, _gsl_selection_matrix[patch], _diffs, 0.0, _res1);
1143  //left product:
1144  gsl_blas_ddot(_diffs, _res1, &res2);
1145 
1146  return exp( -0.5 * res2 );
1147 }
static double Gaussian(double sigma)
Definition: Uniform.h:261

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

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessRelative()

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
288  {
289  return getFitnessAbsolute(ind, patch) * _scaling_factor;
290  }
double getFitnessAbsolute(Individual *ind, unsigned int patch)
Returns the raw fitness of the individual, without adjustment (absolute fitness).
Definition: LCEselection.cc:1151

References _scaling_factor, and getFitnessAbsolute().

Referenced by set_fit_model().

+ Here is the caller graph for this function:

◆ getFitnessTruncation()

double LCE_Selection_base::getFitnessTruncation ( Individual offsprg,
unsigned int  patch,
unsigned int  trait 
)

Returns the fitness of an individual following a Truncation selection model.

Fitness = 1 + offset if phenotype passes the threshold test, offset otherwise.

1039 {
1040  double *_phe = (double*)ind->getTraitValue(trait);
1041 
1042  double w = 1.0;
1043 
1044  // W = prod_t [ (1 + offset) if z passes threshold, offset otherwise ]
1045  for(int t = 0; t < _selectTraitDimension; ++t) {
1046 
1047  bool passes = _truncation_upper
1048  ? (_phe[_selectTraitMapping[t]] >= _truncation_threshold.get(patch, t))
1049  : (_phe[_selectTraitMapping[t]] <= _truncation_threshold.get(patch, t));
1050 
1051  w *= passes ? (1.0 + _selection_offset.get(patch, t)) : _selection_offset.get(patch, t);
1052  }
1053 
1054  return w;
1055 }
TMatrix _truncation_threshold
Definition: LCEselection.h:85

References _selection_offset, _selectTraitDimension, _selectTraitMapping, _truncation_threshold, _truncation_upper, TMatrix::get(), and Individual::getTraitValue().

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessUnivariateDisruptive()

double LCE_Selection_base::getFitnessUnivariateDisruptive ( Individual offsprg,
unsigned int  patch,
unsigned int  trait 
)

Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with one trait under selection.

1008 {
1009  double *_phe = (double*)ind->getTraitValue(trait);
1010 
1011  // W = offset * (1 - exp(-d^2 / (2*Vs))) inverted Gaussian, single trait
1012  double diff = _phe[_selectTraitMapping[0]] - _local_optima.get(patch, 0);
1013 
1014  return _selection_offset.get(patch, 0) * (1.0 - exp( -0.5 * diff * diff / _selection_variance[patch] ));
1015 }
vector< double > _selection_variance
Patch-specific selection variance.
Definition: LCEselection.h:129

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

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessUnivariateGaussian()

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.

1080 {
1081  double res2, diff;
1082 
1083  double *_phe = (double*)ind->getTraitValue(trait);
1084 
1085  diff = _phe[_selectTraitMapping[0]] - _local_optima.get(patch, 0);
1086 
1087  res2 = diff*diff / _selection_variance[patch];
1088 
1089  return exp( -0.5 * res2 );
1090 }

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

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessUnivariateGaussian_VE()

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.

1115 {
1116  double res2, diff;
1117 
1118  double *_phe = (double*)ind->getTraitValue(trait);
1119 
1120  //add the environmental variance here:
1121  diff = _phe[_selectTraitMapping[0]] + RAND::Gaussian(_eVariance) - _local_optima.get(patch, 0);
1122 
1123  res2 = diff*diff / _selection_variance[patch];
1124 
1125  return exp( -0.5 * res2 );
1126 }

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

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessUnivariateLinear()

double LCE_Selection_base::getFitnessUnivariateLinear ( Individual offsprg,
unsigned int  patch,
unsigned int  trait 
)

Returns the fitness of an individual following a Linear selection model with a single trait under selection.

991 {
992  double *_phe = (double*)ind->getTraitValue(trait);
993 
994  double w = 1.0;
995 
996  // W = prod_t [ offset(patch,t) + strength(patch,t) * (z_t - z_bar_t) ]
997  // With defaults: W = prod_t [ 1 + beta * (z_t - z_bar_t) ] (Carter et al. 2005)
998  for(int t = 0; t < _selectTraitDimension; ++t)
999  w *= _selection_offset.get(patch, t)
1001 
1002  return (w < 0 ? 0 : w);
1003 }
vector< double > _mean_trait_value
Definition: LCEselection.h:73
TMatrix _linear_selection_strength
Definition: LCEselection.h:72

References _linear_selection_strength, _mean_trait_value, _selection_offset, _selectTraitDimension, _selectTraitMapping, TMatrix::get(), and Individual::getTraitValue().

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getFitnessUnivariateQuadratic()

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.

1060 {
1061  double res2, diff, w = 1.0;
1062 
1063  double *_phe = (double*)ind->getTraitValue(trait);
1064 
1065  for(unsigned int t = 0; t < _selectTraitDimension; ++t){
1066 
1067  diff = _phe[_selectTraitMapping[t]] - _local_optima.get(patch, t);
1068 
1069  res2 = 1 - diff*diff / _selection_variance[patch];
1070 
1071  w *= (res2 < 0 ? 0 : res2);
1072  }
1073 
1074  return w;
1075 }

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

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ getLocalOptima()

const TMatrix& LCE_Selection_base::getLocalOptima ( ) const
inline
177 {return _local_optima;}

References _local_optima.

◆ getMaxFitness()

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
1198 {
1199  double max = 0, local_max;
1200 
1201  for(unsigned int i = 0, npatch = _popPtr->getPatchNbr(); i < npatch; i++) {
1202 
1203  local_max = getMaxPatchFitness(age, i);
1204 
1205  max = (local_max > max ? local_max : max);
1206  }
1207 
1208  return max;
1209 }
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:1213

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

Referenced by setScalingFactorMaxGlobal().

+ Here is the caller graph for this function:

◆ getMaxPatchFitness()

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
1214 {
1215  double max = 0, fit;
1216  Patch *patch = _popPtr->getPatch(p);
1217 
1218  for(unsigned int j = 0, size = patch->size(FEM, age); j < size; j++) {
1219  fit = getFitness( patch->get(FEM, age, j), p);
1220  max = (fit > max ? fit : max);
1221  }
1222  for(unsigned int j = 0, size = patch->size(MAL, age); j < size; j++){
1223  fit = getFitness( patch->get(MAL, age, j), p);
1224  max = (fit > max ? fit : max);
1225  }
1226 
1227  return max;
1228 }

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

Referenced by getMaxFitness(), and setScalingFactorMaxLocal().

+ Here is the caller graph for this function:

◆ getMeanFitness()

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
1164 {
1165  double mean = 0;
1166  Patch *patch;
1167 // age_idx age = (AGE == ADULTS ? ADLTx : OFFSx);
1168 
1169  for(unsigned int i = 0, npatch = _popPtr->getPatchNbr(); i < npatch; i++) {
1170  patch = _popPtr->getPatch(i);
1171  for(unsigned int j = 0, size = patch->size(FEM, age); j < size; j++)
1172  mean += getFitness( patch->get(FEM, age, j), i);
1173  for(unsigned int j = 0, size = patch->size(MAL, age); j < size; j++)
1174  mean += getFitness( patch->get(MAL, age, j), i);
1175  }
1176  return mean/_popPtr->size(age);
1177 }

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

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

+ Here is the caller graph for this function:

◆ getMeanPatchFitness()

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
1182 {
1183  double mean = 0;
1184  Patch *patch = _popPtr->getPatch(p);
1185 
1186  for(unsigned int j = 0, size = patch->size(FEM, age); j < size; j++)
1187  mean += getFitness( patch->get(FEM, age, j), p);
1188 
1189  for(unsigned int j = 0, size = patch->size(MAL, age); j < size; j++)
1190  mean += getFitness( patch->get(MAL, age, j), p);
1191 
1192  return mean/patch->size(age);
1193 }

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

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

+ Here is the caller graph for this function:

◆ loadFileServices()

void LCE_Selection_base::loadFileServices ( FileServices loader)
virtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

153 {
154  if(_paramSet->isSet("selection_output")) {
155 
156  if(_writer == NULL) _writer = new LCE_SelectionFH(this);
157 
158  Param* param = get_parameter("selection_output_logtime");
159 
160  if(!param->isSet()) fatal("parameter \"selection_output_logtime\" is missing\n");
161 
162  if(param->isMatrix()) {
163 
164  TMatrix temp;
165 
166  param->getMatrix(&temp);
167 
168  _writer->set_multi(true, true, 1, &temp, get_parameter("selection_output_dir")->getArg());
169 
170  } else
171  // rpl_per, gen_per, rpl_occ, gen_occ, rank, path, self-ref
172  _writer->set(true, param->isSet(), 1, (param->isSet() ? (int)param->getValue() : 0), 0,
173  get_parameter("selection_output_dir")->getArg(), this);
174 
175 
176  loader->attach(_writer);
177 
178  } else {
179 
180  if(_writer) delete _writer;
181 
182  return;
183  }
184 
185 
186 }
virtual void set(bool rpl_per, bool gen_per, int rpl_occ, int gen_occ, int rank, string path, LCE *event)
Definition: filehandler.h:275
virtual void set_multi(bool rpl_per, bool gen_per, int rpl_occ, TMatrix *Occ, string path)
Definition: filehandler.h:200
virtual void attach(Handler *FH)
Attaches the FileHandler to the current list (_writers) of the FileServices.
Definition: fileservices.cc:60
friend class LCE_SelectionFH
Definition: LCEselection.h:106
bool isSet()
Accessor to the status flag.
Definition: param.h:287
This structure stores one parameter, its definition and its string argument.
Definition: param.h:53
double getValue()
Returns the argument value according to its type.
Definition: param.cc:367
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:171
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:377
bool isSet()
Definition: param.h:139
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:138
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:47
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:49
void fatal(const char *str,...)
Definition: output.cc:99

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

◆ loadStatServices()

void LCE_Selection_base::loadStatServices ( StatServices loader)
virtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

145 {
146  if(_stater == NULL) _stater = new LCE_SelectionSH(this);
147  loader->attach(_stater);
148 }
friend class LCE_SelectionSH
The StatHandler associated class is a friend.
Definition: LCEselection.h:105
virtual void attach(Handler *H)
attach the StatHandler to the current list (_statHandlers) of the StatServices
Definition: statservices.cc:176

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

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

+ Here is the caller graph for this function:

◆ removeAgeClass()

virtual age_t LCE_Selection_base::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

347 {return NONE;}

References NONE.

◆ requiredAgeClass()

virtual age_t LCE_Selection_base::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

349 {return OFFSPRG;}

References OFFSPRG.

◆ resetCounters()

void LCE_Selection_base::resetCounters ( )

Resets the fitness counters.

1407 {
1408  for(unsigned int i = 0; i < 5; i++) {
1409  _fitness[i] = 0;
1410  _survival[i] = 0;
1411  _ind_cntr[i] = 0;
1412  }
1413 }
double _fitness[5]
Fitness counters, one for each pedigree class.
Definition: LCEselection.h:117
double _ind_cntr[5]
Definition: LCEselection.h:117
double _survival[5]
Definition: LCEselection.h:117

References _fitness, _ind_cntr, and _survival.

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

+ Here is the caller graph for this function:

◆ resetParameterFromSource()

virtual bool LCE_Selection_base::resetParameterFromSource ( std::string  param,
SimComponent cmpt 
)
inlinevirtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

345 {return false;}

◆ set_fit_model()

bool LCE_Selection_base::set_fit_model ( )
260 {
261 
262  if(_paramSet->isSet("selection_fitness_model")) {
263 
264  string fit_model = _paramSet->getArg("selection_fitness_model");
265 
266  if( fit_model == "absolute") {
267 
268  _is_local = false;
269  _is_absolute = true;
272 
273  } else if( fit_model == "relative_local" ) {
274 
275  _is_local = true;
276  _is_absolute = false;
279 
280  } else if(fit_model == "relative_global") {
281 
282  _is_local = false;
283  _is_absolute = false;
286 
287  } else if(fit_model == "relative_max_local") {
288 
289  _is_local = true;
290  _is_absolute = false;
293 
294  } else if(fit_model == "relative_max_global") {
295 
296  _is_local = false;
297  _is_absolute = false;
300 
301  } else {
302  return error("Unknown fitness model \"%s\"", fit_model.c_str());
303  }
304  } //default case:
305  else {
306  _is_local = false;
307  _is_absolute = true;
310  }
311 
312  return true;
313 }
double getFitnessRelative(Individual *ind, unsigned int patch)
Returns the relative fitness of the individual, adjusted by a scaling factor.
Definition: LCEselection.h:287
void setScalingFactorAbsolute(age_idx age, unsigned int p)
Resets the fitness scaling factor equal to one.
Definition: LCEselection.h:325
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:1259
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:1251
void setScalingFactorGlobal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the mean population fitness.
Definition: LCEselection.cc:1241
void setScalingFactorLocal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the mean local patch fitness.
Definition: LCEselection.cc:1233
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:299
int error(const char *str,...)
Definition: output.cc:78

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().

+ Here is the caller graph for this function:

◆ set_local_optima()

bool LCE_Selection_base::set_local_optima ( )
866 {
867  //set the traits' local optima, _selectTraitDimension must be set before that (= nbr of traits to select on)
868  // string model = _paramSet->getArg("selection_model");
869  string model;
870 
871  for(unsigned int t = 0; t < _SelectionModels.size(); t++) {
872 
873  model = _SelectionModels[t];
874 
875  if( model == "fix" || model == "direct" || model == "linear" || model == "truncation") continue;
876 
877  if(model == "gaussian" || model == "quadratic" || model == "disruptive") {
878 
879  if (!get_parameter("selection_local_optima")->isSet()) {
880 
881  return error("parameter \"selection_local_optima\" must be set to have Gaussian, quadratic, or disruptive selection.\n");
882 
883  } else {
884 
885  // this will run only once, irrespective of the number of different models selected
886  // checks on trait type and dimensions have been done before calling this function
887  TMatrix tmp_mat;
888 
890 
891  _paramSet->getMatrix("selection_local_optima", &tmp_mat);
892 
893  return setSpatialMatrix("selection_local_optima", "\"selection_trait_dimension\"", &tmp_mat, &_local_optima,
894  _selectTraitDimension, _popPtr->getPatchNbr(), _paramSet->isSet("selection_randomize"));
895  }
896  }
897  }
898 
899  return true;
900 }
vector< string > _SelectionModels
The selection models associated with each trait under selection.
Definition: LCEselection.h:142
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:303
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:160
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
Definition: utils.cc:114

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

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

+ Here is the caller graph for this function:

◆ set_param_rate_of_change()

bool LCE_Selection_base::set_param_rate_of_change ( )
905 {
906  _rate_of_change_is_std = false;
907  _do_change_local_opt = false;
908  _setNewLocalOptima = 0;
910  // renamed parameters
911 
912  if (!get_parameter("selection_local_optima_rate_change")->isSet()
913  && !get_parameter("selection_local_optima_std_rate_change")->isSet() ) {
914  return true;
915  }
916 
917  if (get_parameter("selection_local_optima_rate_change")->isSet()
918  && get_parameter("selection_local_optima_std_rate_change")->isSet() ) {
919  return error("both \"selection_local_optima_rate_change\" and \"selection_local_optima_std_rate_change\" are set, need only one.\n");
920  }
921 
922  TMatrix tmpMat;
923 
924  if (get_parameter("selection_local_optima_rate_change")->isSet()) {
925 
926  if(!get_parameter("selection_local_optima_rate_change")->isMatrix()) {
927 
928  double val = get_parameter_value("selection_local_optima_rate_change");
929 
930  tmpMat.reset(1, _selectTraitDimension);
931  tmpMat.assign(val);
932 
933  } else {
934  get_parameter("selection_local_optima_rate_change")->getMatrix(&tmpMat);
935  }
936 
938 
939  } else if (get_parameter("selection_local_optima_std_rate_change")->isSet()){
940 
941  if(!get_parameter("selection_local_optima_std_rate_change")->isMatrix()) {
942 
943  double val = get_parameter_value("selection_local_optima_std_rate_change");
944 
945  tmpMat.reset(1, _selectTraitDimension);
946  tmpMat.assign(val);
947 
948  } else {
949  get_parameter("selection_local_optima_std_rate_change")->getMatrix(&tmpMat);
950  }
951 
952  _rate_of_change_is_std = true;
953 
954  if(get_parameter("selection_local_optima_std_rate_set_at_generation")->isSet())
955  _set_std_rate_at_generation = (unsigned int)get_parameter_value("selection_local_optima_std_rate_set_at_generation");
956  else
958 
959  //check if phenotypic SD is to be computed in a single reference patch
960  //is -1 if parameter not set, which corresponds to the whole population then
961  _std_rate_reference_patch = get_parameter_value("selection_local_optima_std_rate_reference_patch");
962 
964  }
965 
966  if(tmpMat.nrows() > _popPtr->getPatchNbr())
967  return error("The matrix of rate of change in local optima has more rows than the number of patches\n");
968 
969  if((int)tmpMat.ncols() > _selectTraitDimension)
970  return error("The matrix of rate of change in local optima has more columns than the number of quantitative traits\n");
971 
972  _do_change_local_opt = true;
973 
975 
976  unsigned int nCol = tmpMat.ncols(), nRow = tmpMat.nrows();
977 
978  //copy values, with pattern propagation
979  for (int p = 0; p < _popPtr->getPatchNbr(); ++p) {
980  for (int i = 0; i < _selectTraitDimension; ++i) {
981  _rate_of_change_local_optima.set(p, i, tmpMat.get(p % nRow, i % nCol));
982  }
983  }
984 
985  return true;
986 }
void changeLocalOptima()
Definition: LCEselection.cc:1312
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:142
unsigned int ncols() const
Definition: tmatrix.h:215
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:102
void assign(double val)
Assigns a value to all element of the matrix.
Definition: tmatrix.h:154

References _do_change_local_opt, LifeCycleEvent::_popPtr, _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(), Metapop::getPatchNbr(), TMatrix::ncols(), TMatrix::nrows(), TMatrix::reset(), TMatrix::set(), and set_std_rate_of_change().

Referenced by LCE_Selection_base(), and setParameters().

+ Here is the caller graph for this function:

◆ set_sel_model()

bool LCE_Selection_base::set_sel_model ( )
318 {
319 
320  // _selectTraitDimension is set per-model in gaussian/quadratic via setSelectTraitMapping()
322  _selectTraitMapping.clear();
323  _selectTraitMapping.push_back(0);
324 
325  // -------------------------------------------------------------------------------------
326  // ENVIRONMENTAL VARIANCE
327 
328  if(get_parameter("selection_environmental_variance")->isSet())
329  //the variable actually holds the standard dev...
330  _eVariance = sqrt(get_parameter_value("selection_environmental_variance"));
331  else
332  _eVariance = 0;
333 
334  // -------------------------------------------------------------------------------------
335  // SELECTION MODELS
336 
337  // empty containers:
338  _SelectionModels.clear();
339  _getRawFitness.clear();
340 
341  // default case: direct fitness model
342  if(!_paramSet->isSet("selection_model")) {
343 
345 
346  _SelectionModels.push_back("direct");
347 
348  } else {
349 
350  _SelectionModels = get_parameter("selection_model")->getMultiArgs();
351  } //end_if isSet()
352 
353  // check consistency with selection_trait info
354  if (_SelectionModels.size() != _TraitIndices.size())
355  return error("\"selection_trait\" and \"selection_model\" must have the same number of arguments.");
356 
357  // -------------------------------------------------------------------------------------
358  // SET FUNCTION POINTERS TO FITNESS FUNCTIONS
359 
360  string sel_model;
361 
362  for(unsigned int t = 0; t < _SelectionModels.size(); t++) {
363 
364  sel_model = _SelectionModels[t];
365 
366 
367  // FIX -----------------------------------------------------------------------
368  if(sel_model == "fix") {
369 
370  //check if the trait type in the trait table is correct
371  if(_Traits[t] != "fix")
372  return error("the selection model \"fix\" does not match with the trait type \"%s\"\n", _Traits[t].c_str());
373 
374  if(!get_parameter("selection_lethal_equivalents")->isSet()) {
375 
376  return error("\"selection_lethal_equivalents\" parameter is missing with \"fix\" selection!\n");
377 
378  } else
379  _letheq = get_parameter_value("selection_lethal_equivalents");
380 
381  if(!get_parameter("selection_base_fitness")->isSet()) {
382 
383  warning("\"selection_base_fitness\" parameter is missing under fix selection model, setting it to 1.\n");
384 
385  _base_fitness = 1.0;
386 
387  } else {
388 
389  _base_fitness = get_parameter_value("selection_base_fitness");
390 
391  }
392 
393  if(!get_parameter("selection_pedigree_F")->isSet()) {
394 
395  return error("\"selection_pedigree_F\" parameter is missing with \"fix\" selection!\n");
396 
397  } else {
398 
399  TMatrix tmp_mat;
400 
401  get_parameter("selection_pedigree_F")->getMatrix(&tmp_mat);
402 
403  if(tmp_mat.getNbCols() != 5) {
404  return error("\"selection_pedigree_F\" must be an array of size 5.\n");
405  }
406 
407  for(unsigned int i = 0; i < 5; i++) _Fpedigree[i] = tmp_mat.get(0,i);
408  }
409 
410  for(unsigned int i = 0; i < 5; i++)
411  _FitnessFixModel[i] = _base_fitness * exp( -_letheq * _Fpedigree[i] );
412 
413  //everything has been set correctly, add function pointer to container
415 
416  // DIRECT -----------------------------------------------------------------------
417  } else if(sel_model == "direct") {
418 
419  //check if the trait type in the trait table is correct
420  if(_Traits[t] != "delet" && _Traits[t] != "dmi")
421  return error("the selection model \"direct\" does not match with the trait type \"%s\"\n", _Traits[t].c_str());
422 
424 
425  // QUADRATIC --------------------------------------------------------------------
426  } else if(sel_model == "quadratic") {
427 
428  //check if the trait type in the trait table is correct
429  if(_Traits[t] != "quant")
430  return error("the selection model \"quadratic\" works only with the \"quant\" trait, your trait %i has type \"%s\"\n",
431  t, _Traits[t].c_str());
432 
433  if(!setSelectTraitMapping((unsigned int)_popPtr->getTraitPrototype("quant")->get_parameter_value("quanti_traits")))
434  return false;
435 
436  //set the selection variance params
437  if(!setSelectionMatrix()) return error("LCE selection::failed to set the selection matrix\n");
438 
439  //now add the pointer to fitness function:
441 
442  // GAUSSIAN --------------------------------------------------------------------
443  } else if(sel_model == "gaussian") {
444 
445  //check if the trait type in the trait table is correct
446  if(_Traits[t] != "quant")
447  return error("the selection model \"gaussian\" works only with the \"quant\" trait, your trait type is \"%s\"\n", _Traits[t].c_str());
448 
449  if(!setSelectTraitMapping((unsigned int)_popPtr->getTraitPrototype("quant")->get_parameter_value("quanti_traits")))
450  return false;
451 
452  // set the selection matrices for multi-stage or spatially variable cases
453  if( !setSelectionMatrix() ) return error("LCE selection::failed to set the selection matrix\n");
454 
455  if(_selectTraitDimension > 1) {
456 
457  if(_eVariance > 0)
459  else
461 
462  } else {
463 
464  if(_eVariance > 0)
466  else
468 
469  }
470 
471 
472  // LINEAR --------------------------------------------------------------------
473 
474  } else if(sel_model == "linear") {
475 
476  //check if the trait type in the trait table is correct
477  if(_Traits[t] != "quant")
478  return error("the selection model \"linear\" works only with the \"quant\" trait, your trait type is \"%s\"\n", _Traits[t].c_str());
479 
480  if(!setSelectTraitMapping((unsigned int)_popPtr->getTraitPrototype("quant")->get_parameter_value("quanti_traits")))
481  return false;
482 
483  unsigned int patchNbr = _popPtr->getPatchNbr();
484  TMatrix tmp_matx;
485 
486  // store the quanti trait index for mean phenotype computation
488 
489  // selection gradient beta, default 1.0 (Carter et al. 2005)
491 
492  if(get_parameter("selection_linear_strength")->isSet()) {
493 
494  if(get_parameter("selection_linear_strength")->isMatrix()) {
495  get_parameter("selection_linear_strength")->getMatrix(&tmp_matx);
496 
497  if(tmp_matx.getNbRows() > patchNbr)
498  return error("\"selection_linear_strength\" must have at max as many rows as the number of patches.\n");
499 
500  if(tmp_matx.ncols() > (unsigned)_selectTraitDimension)
501  return error("\"selection_linear_strength\" must have at max as many columns as the number of selected traits.\n");
502 
504  } else {
505  // scalar value: uniform strength across patches and traits
506  _linear_selection_strength.assign(get_parameter_value("selection_linear_strength"));
507  }
508  }
509 
510  // offset defaults to 1.0, giving W = 1 + beta*(z - z_bar) (Carter et al. 2005)
511  if(!setSelectionOffset(1.0, 0.0)) return false;
512 
514 
515  // age class for computing mean phenotype: offspring (default) or adults
517  if(get_parameter("selection_at_stage")->isSet()) {
518  string age_str = get_parameter("selection_at_stage")->getArg();
519  if(age_str == "adults")
521  else if(age_str == "offspring")
523  else
524  return error("\"selection_at_stage\" must be \"offspring\" or \"adults\".\n");
525  }
526 
527  // override scaling factor to compute per-patch mean phenotypes before fitness evaluation
529 
531 
532  // DISRUPTIVE ----------------------------------------------------------------
533 
534  } else if(sel_model == "disruptive") {
535 
536  //check if the trait type in the trait table is correct
537  if(_Traits[t] != "quant")
538  return error("the selection model \"disruptive\" works only with the \"quant\" trait, your trait type is \"%s\"\n", _Traits[t].c_str());
539 
540  if(!setSelectTraitMapping((unsigned int)_popPtr->getTraitPrototype("quant")->get_parameter_value("quanti_traits")))
541  return false;
542 
543  // reuse the selection matrix/variance infrastructure (same as Gaussian)
544  if(!setSelectionMatrix()) return error("LCE selection::failed to set the selection matrix\n");
545 
546  unsigned int patchNbr = _popPtr->getPatchNbr();
547  TMatrix tmp_matx;
548 
549  // offset = asymptotic fitness far from optimum, default 1.0
550  // W = offset * (1 - exp(-d^2 / (2*Vs)))
551  if(!setSelectionOffset(1.0, 0.0)) return false;
552 
553  if(_selectTraitDimension > 1)
555  else
557 
558  // TRUNCATION ----------------------------------------------------------------
559 
560  } else if(sel_model == "truncation") {
561 
562  if(_Traits[t] != "quant")
563  return error("the selection model \"truncation\" works only with the \"quant\" trait, your trait type is \"%s\"\n", _Traits[t].c_str());
564 
565  if(!setSelectTraitMapping((unsigned int)_popPtr->getTraitPrototype("quant")->get_parameter_value("quanti_traits")))
566  return false;
567 
568  unsigned int patchNbr = _popPtr->getPatchNbr();
569  TMatrix tmp_matx;
570 
571  // threshold is mandatory
572  if(!get_parameter("selection_truncation_threshold")->isSet())
573  return error("\"selection_truncation_threshold\" must be set with selection model \"truncation\".\n");
574 
576 
577  if(get_parameter("selection_truncation_threshold")->isMatrix()) {
578  get_parameter("selection_truncation_threshold")->getMatrix(&tmp_matx);
579 
580  if(tmp_matx.getNbRows() > patchNbr)
581  return error("\"selection_truncation_threshold\" must have at max as many rows as the number of patches.\n");
582 
583  if(tmp_matx.ncols() > (unsigned)_selectTraitDimension)
584  return error("\"selection_truncation_threshold\" must have at max as many columns as the number of selected traits.\n");
585 
587  } else {
588  _truncation_threshold.assign(get_parameter_value("selection_truncation_threshold"));
589  }
590 
591  // direction: "upper" (default) selects for z >= threshold; "lower" selects for z <= threshold
592  _truncation_upper = true;
593  if(get_parameter("selection_truncation_direction")->isSet()) {
594  string dir_str = get_parameter("selection_truncation_direction")->getArg();
595  if(dir_str == "lower")
596  _truncation_upper = false;
597  else if(dir_str == "upper")
598  _truncation_upper = true;
599  else
600  return error("\"selection_truncation_direction\" must be \"upper\" or \"lower\".\n");
601  }
602 
603  // offset: default 0 (hard truncation: W=0 below, W=1 above)
604  if(!setSelectionOffset(0.0, 0.0)) return false;
605 
607 
608  } else return error("wrong selection model, must be either \"fix\", \"direct\", \"quadratic\", \"gaussian\", \"linear\", \"disruptive\", or \"truncation\".\n");
609 
610  }
611 
612  if(sel_model != "fix" && !_paramSet->isSet("selection_trait"))
613  return error("trait under selection is not set, please add parameter \"selection_trait\"\n");
614 
615  return true;
616 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:139
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:1114
double getFitnessMultivariateDisruptive(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with ...
Definition: LCEselection.cc:1019
bool setSelectionMatrix()
Definition: LCEselection.cc:666
double getFitnessFixedEffect(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual in the fixed selection model.
Definition: LCEselection.h:235
double getFitnessDirect(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following the direct selection model.
Definition: LCEselection.h:241
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:1059
double getFitnessTruncation(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following a Truncation selection model.
Definition: LCEselection.cc:1038
bool setSelectionOffset(double default_val, double min_val)
Definition: LCEselection.cc:829
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:1130
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:1094
void setScalingFactorForLinearSelection(age_idx age, unsigned int p)
Sets the fitness scaling factor as the mean trait value in the patch to compute the fitness value in ...
Definition: LCEselection.cc:1268
double _Fpedigree[5]
Array of pedigree values used in the fixed-selection model.
Definition: LCEselection.h:95
bool setSelectTraitMapping(unsigned int num_quanti_traits)
Definition: LCEselection.cc:620
double getFitnessUnivariateLinear(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following a Linear selection model with a single trait under sel...
Definition: LCEselection.cc:990
vector< string > _Traits
The list of trait types under selection.
Definition: LCEselection.h:136
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:1079
double getFitnessUnivariateDisruptive(Individual *offsprg, unsigned int patch, unsigned int trait)
Returns the fitness of an individual following a Disruptive (inverted Gaussian) selection model with ...
Definition: LCEselection.cc:1007
string getArg()
Definition: param.h:137
vector< string > getMultiArgs()
Definition: param.cc:119
unsigned int getNbRows() const
Gives the number of rows.
Definition: tmatrix.h:211
unsigned int getNbCols() const
Gives the number of columns.
Definition: tmatrix.h:214
void copy_recycle(const TMatrix &mat)
Copy elements of 'mat', recycling elements of 'mat' if its size is smaller than current matrix.
Definition: tmatrix.h:89
void warning(const char *str,...)
Definition: output.cc:57
@ ADLTx
Definition: types.h:41

References _base_fitness, _eVariance, _FitnessFixModel, _Fpedigree, _getRawFitness, _letheq, _linear_selection_strength, _linearSelAgeClass, _linearSelTraitIndex, _mean_trait_value, SimComponent::_paramSet, LifeCycleEvent::_popPtr, _SelectionModels, _selectTraitDimension, _selectTraitMapping, _setScalingFactor, _TraitIndices, _Traits, _truncation_threshold, _truncation_upper, ADLTx, TMatrix::assign(), TMatrix::copy_recycle(), error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), Param::getArg(), getFitnessDirect(), getFitnessFixedEffect(), getFitnessMultivariateDisruptive(), getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), getFitnessTruncation(), getFitnessUnivariateDisruptive(), getFitnessUnivariateGaussian(), getFitnessUnivariateGaussian_VE(), getFitnessUnivariateLinear(), getFitnessUnivariateQuadratic(), Param::getMatrix(), Param::getMultiArgs(), TMatrix::getNbCols(), TMatrix::getNbRows(), Metapop::getPatchNbr(), IndFactory::getTraitPrototype(), ParamSet::isSet(), TMatrix::ncols(), OFFSx, TMatrix::reset(), setScalingFactorForLinearSelection(), setSelectionMatrix(), setSelectionOffset(), setSelectTraitMapping(), and warning().

Referenced by LCE_Selection_base(), and setParameters().

+ Here is the caller graph for this function:

◆ set_std_rate_of_change()

void LCE_Selection_base::set_std_rate_of_change ( )
1446 {
1448 
1449  //reset rate_of_change matrix in each new replicate:
1450  TMatrix tmpMat;
1451 
1452  if(!get_parameter("selection_local_optima_std_rate_change")->isMatrix()) {
1453 
1454  double val = get_parameter_value("selection_local_optima_std_rate_change");
1455 
1457  tmpMat.assign(val);
1458 
1459  } else {
1460  get_parameter("selection_local_optima_std_rate_change")->getMatrix(&tmpMat);
1461  }
1462 
1463  unsigned int nCol = tmpMat.ncols(), nRow = tmpMat.nrows();
1464 
1466 
1467  //copy values, with pattern propagation
1468  for (int p = 0; p < _popPtr->getPatchNbr(); ++p) {
1469  for (int i = 0; i < _selectTraitDimension; ++i) {
1470  _rate_of_change_local_optima.set(p, i, tmpMat.get(p % nRow, i % nCol));
1471  }
1472  }
1473 
1474  double* SD = new double [_selectTraitDimension];
1475 
1476  for (int i = 0; i < _selectTraitDimension; ++i) {
1477  SD[i] = 0;
1478  }
1479 
1480  // check if SD is taken in a reference patch instead of the whole pop
1481  if (_std_rate_reference_patch > -1) {
1482 
1485 
1486  } else {
1487  // compute SD as the mean within-patch SD
1488 
1489  unsigned int cnt = 0;
1490 
1491  //get SD only in extant demes, to avoid nans
1492  for(unsigned int i = 0; i < _popPtr->getPatchNbr(); ++i) {
1493  if (_popPtr->getPatch(i)->size(OFFSx) != 0 ) {
1494  cnt++;
1495  addPhenotypicSD(i, SD);
1496  }
1497  }
1498 
1499  //compute mean within-patch phenotypic standard deviation:
1500  for (int i = 0; i < _selectTraitDimension; ++i) {
1501  SD[i]/= cnt;
1502 
1503  }
1504  } //end if
1505 
1506  //multiply the per-trait rates of change by SD:
1507  for (int p = 0; p < _popPtr->getPatchNbr(); ++p) {
1508  for (int i = 0; i < _selectTraitDimension; ++i){
1509  _rate_of_change_local_optima.multi(p, i, SD[i]);
1510  }
1511 
1512  }
1513  //log the rates in the simulation log file:
1514  SIMenv::MainSim->_FileServices.log("#selection_local_optima_rate_change " +
1516 
1517  //compute the change of local optima for current generation:
1519 
1520  //now reset the function pointer to changeLocalOptima() for next generation:
1522 
1523  delete [] SD;
1524  }
1525 }
void log(string message)
Write to the parameter logfile.
Definition: fileservices.cc:435
void addPhenotypicSD(unsigned int deme, double *stDev)
Definition: LCEselection.cc:1529
static SimRunner * MainSim
Definition: simenv.h:41
FileServices _FileServices
Definition: simulation.h:99
void multi(unsigned int i, unsigned int j, double value)
Multiply an element of the matrix by a value.
Definition: tmatrix.h:298
string to_string()
Writes the matrix into a string in Nemo's matrix input format.
Definition: tmatrix.h:373

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(), FileServices::log(), SIMenv::MainSim, TMatrix::multi(), TMatrix::ncols(), TMatrix::nrows(), OFFSx, TMatrix::reset(), TMatrix::set(), Patch::size(), and TMatrix::to_string().

Referenced by checkChangeLocalOptima(), and set_param_rate_of_change().

+ Here is the caller graph for this function:

◆ setLocalOptima()

bool LCE_Selection_base::setLocalOptima ( )

◆ setMeanFitness()

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
223 { return (_mean_fitness = getMeanFitness(age));}
double getMeanFitness(age_idx age)
Computes the mean fitness of the whole population for a given age class.
Definition: LCEselection.cc:1163

References _mean_fitness, and getMeanFitness().

◆ setMeans()

void LCE_Selection_base::setMeans ( unsigned int  tot_ind)

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
1418 {
1419  _mean_fitness = 0;
1420 
1421  for(unsigned int i = 0; i < 5; i++) {
1422  _mean_fitness += _fitness[i];
1423  _fitness[i] /= _ind_cntr[i];
1424  _survival[i] /= _ind_cntr[i];
1425  _ind_cntr[i] /= tot_ind;
1426  }
1427 
1428  _mean_fitness /= tot_ind;
1429 }

References _fitness, _ind_cntr, _mean_fitness, and _survival.

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

+ Here is the caller graph for this function:

◆ setParameters()

bool LCE_Selection_base::setParameters ( )
virtual

Implements SimComponent.

Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.

192 {
193  //selection may act on more than one trait at a time
194  _Traits.clear();
195  _Traits = get_parameter("selection_trait")->getMultiArgs();
196 
197  _TraitIndices.clear();
198 
199  for(unsigned int i = 0; i < _Traits.size(); i++) {
200 
201  if(_popPtr->getTraitIndex(_Traits[i].c_str()) == -1) {
202 
203  return error("cannot attach trait \"%s\" to life cycle event \"%s\", trait has not been initiated.\n",
204  _Traits[i].c_str(), _event_name.c_str());
205 
206  } else {
207  _TraitIndices.push_back(_popPtr->getTraitIndex(_Traits[i].c_str()));
208 
209 
210 #ifdef _DEBUG_
211  cout<<"#### attaching trait \""<<_Traits[i].c_str()<<"\" to selection LCE, index = "<<_TraitIndices[i]<<endl;
212 #endif
213 
214  }
215 
216  }
217 
218 #ifdef _DEBUG_
219  cout<<"#### setting fitness model "<<endl;
220 #endif
221 
222  if(!set_fit_model()) return false;
223 
224 #ifdef _DEBUG_
225  cout<<"#### setting selection model "<<endl;
226 #endif
227 
228  if(!set_sel_model()) return false;
229 
230 #ifdef _DEBUG_
231  cout<<"#### setting local optima "<<endl;
232 #endif
233 
234  if(!set_local_optima()) return false;
235 
236 #ifdef _DEBUG_
237  cout<<"#### setting rate of environmental change "<<endl;
238 #endif
239 
240  if(!set_param_rate_of_change()) return false;
241 
243  _scaling_factor = 1;
244  resetCounters();
245 
246  assert(_TraitIndices.size() == _getRawFitness.size());
247 
248 #ifdef _DEBUG_
249  cout<<"#### selection is acting on "<<_TraitIndices.size()<<" traits\n";
250  cout<<"#### selection is using "<< _getRawFitness.size() <<" fitness functions\n";
251 #endif
252 
253 
254  return true;
255 }
int getTraitIndex(trait_t type)
Gives the index of trait with type.
Definition: indfactory.cc:127
std::string _event_name
The param name to be read in the init file.
Definition: lifecycleevent.h:76

References LifeCycleEvent::_event_name, _getRawFitness, _max_fitness, _mean_fitness, LifeCycleEvent::_popPtr, _scaling_factor, _TraitIndices, _Traits, 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().

+ Here is the caller graph for this function:

◆ setScalingFactorAbsolute()

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
325 { _scaling_factor = 1; }

References _scaling_factor.

Referenced by set_fit_model().

+ Here is the caller graph for this function:

◆ setScalingFactorForLinearSelection()

void LCE_Selection_base::setScalingFactorForLinearSelection ( age_idx  age,
unsigned int  p 
)

Sets the fitness scaling factor as the mean trait value in the patch to compute the fitness value in the linear selection model.

Parameters
agethe age-class index
pthe focal patch index
1269 {
1270  // use the configured age class (overrides the caller's age argument)
1271  age = _linearSelAgeClass;
1272 
1273  // compute the mean phenotypic value per selected trait dimension from the specified age class
1275 
1276  Patch *patch = _popPtr->getPatch(p);
1277  Individual* ind;
1278  double* phe;
1279 
1280  unsigned int sizeFEM = patch->size(FEM, age),
1281  sizeMAL = patch->size(MAL, age);
1282  unsigned int patchSize = sizeFEM + sizeMAL;
1283 
1284  if(patchSize == 0) {
1285  _scaling_factor = 1;
1286  return;
1287  }
1288 
1289  for(unsigned int j = 0; j < sizeFEM; j++) {
1290  ind = patch->get(FEM, age, j);
1291  phe = (double*)ind->getTraitValue(_linearSelTraitIndex);
1292  for(int i = 0; i < _selectTraitDimension; i++)
1293  _mean_trait_value[i] += phe[_selectTraitMapping[i]];
1294  }
1295 
1296  for(unsigned int j = 0; j < sizeMAL; j++) {
1297  ind = patch->get(MAL, age, j);
1298  phe = (double*)ind->getTraitValue(_linearSelTraitIndex);
1299  for(int i = 0; i < _selectTraitDimension; i++)
1300  _mean_trait_value[i] += phe[_selectTraitMapping[i]];
1301  }
1302 
1303  for(int i = 0; i < _selectTraitDimension; i++)
1304  _mean_trait_value[i] /= patchSize;
1305 
1306  _scaling_factor = 1;
1307 }

References _linearSelAgeClass, _linearSelTraitIndex, _mean_trait_value, LifeCycleEvent::_popPtr, _scaling_factor, _selectTraitDimension, _selectTraitMapping, FEM, Patch::get(), Metapop::getPatch(), Individual::getTraitValue(), MAL, and Patch::size().

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ setScalingFactorGlobal()

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
1242 {
1243  if(p != 0) return; //we compupte the mean fitness only once
1244  _scaling_factor = 1;
1245  _scaling_factor = 1.0/getMeanFitness(age);
1246 }

References _scaling_factor, and getMeanFitness().

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

+ Here is the caller graph for this function:

◆ setScalingFactorLocal()

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
1234 {
1235  _scaling_factor = 1; //this to have the raw mean fitness below
1236  _scaling_factor = 1.0/getMeanPatchFitness(age, p);
1237 }
double getMeanPatchFitness(age_idx age, unsigned int p)
Computes the mean fitness in a given patch for a given age class.
Definition: LCEselection.cc:1181

References _scaling_factor, and getMeanPatchFitness().

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

+ Here is the caller graph for this function:

◆ setScalingFactorMaxGlobal()

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
1260 {
1261  if(p != 0) return; //we compute the max fitness only once
1262  _scaling_factor = 1;
1263  _scaling_factor = 1.0/getMaxFitness(age);
1264 }
double getMaxFitness(age_idx age)
Computes the maximum fitness value of the whole population for a given age class.
Definition: LCEselection.cc:1197

References _scaling_factor, and getMaxFitness().

Referenced by set_fit_model().

+ Here is the caller graph for this function:

◆ setScalingFactorMaxLocal()

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
1252 {
1253  _scaling_factor = 1; //this to have the raw fitness when computing fitnesses below
1254  _scaling_factor = 1.0/getMaxPatchFitness(age, p);
1255 }

References _scaling_factor, and getMaxPatchFitness().

Referenced by set_fit_model().

+ Here is the caller graph for this function:

◆ setSelectionMatrix()

bool LCE_Selection_base::setSelectionMatrix ( )
667 {
668  TMatrix tmp_mat;
669  unsigned int patchNbr = _popPtr->getPatchNbr();
670 
671  if(!get_parameter("selection_matrix")->isSet() && !get_parameter("selection_variance")->isSet())
672  return error("\"selection_matrix\" or \"selection_variance\" must be set with selection model = \"gaussian\".\n");
673 
674 
675  if(get_parameter("selection_variance")->isSet() && !get_parameter("selection_trait_dimension")->isSet())
676  return error("parameter \"selection_trait_dimension\" is missing!\n");
677 
678  //clear the selection matrix container
679  vector< TMatrix* >::iterator selIT = _selection_matrix.begin();
680 
681  for(; selIT != _selection_matrix.end(); ++selIT) if((*selIT)) delete (*selIT);
682 
683  _selection_matrix.clear();
684 
685 
686  if(get_parameter("selection_matrix")->isSet()) {
687 
688  //selection matrix provided, same selection surface in each patch
689  _paramSet->getMatrix("selection_matrix", &tmp_mat);
690 
691  if(tmp_mat.getNbCols() != tmp_mat.getNbRows())
692  return error("\"selection_matrix\" must be a square matrix!\n");
693 
694  if( get_parameter("selection_trait_dimension")->isSet() ) {
695 
696  if( (unsigned int)get_parameter_value("selection_trait_dimension") != tmp_mat.ncols() ) {
697  return error("dimensionality of \"selection_matrix\" does not match with \"selection_trait_dimension\"\n");
698  }
699 
700  } else {
701 
702  //check if the number of quanti traits modeled match with the dimensionality of the selection matrix:
703  if(_popPtr->getTraitPrototype("quant")->get_parameter_value("quanti_traits") < tmp_mat.ncols())
704  return error("The number of quantitative traits set with \"quanti_traits\" does not match with\
705  the dimensionality of the selection matrix set with \"selection_matrix\"\n");
706  else
707  _selectTraitDimension = tmp_mat.ncols();
708 
709  }
710 
711  //we have one selection matrix per patch, copy it in the container for each patch
712  for(unsigned int i = 0; i < patchNbr; ++i)
713  _selection_matrix.push_back( new TMatrix(tmp_mat) );
714 
715  } else {
716  // selection_matrix not set in input, only selection_variance is set
717 
718  // _selectTraitDimension and _selectTraitMapping already set by setSelectTraitMapping()
719  if( get_parameter("selection_trait_dimension")->isSet() ) {
720 
721  //check if the number of quanti traits modeled match with the dimensionality:
722  if((int)_popPtr->getTraitPrototype("quant")->get_parameter_value("quanti_traits") < _selectTraitDimension)
723  return error("The number of quantitative traits set with \"quanti_traits\" does not match with\
724  the selection trait dimensionality set with \"selection_trait_dimension\"\n");
725 
726  } // alternative case already checked at the onset
727 
728  TMatrix var_spatmat, corr_spatmat;
729 
730  //setting variance spatial matrix:
731  var_spatmat.reset(patchNbr, (unsigned)_selectTraitDimension);
732 
733  if(get_parameter("selection_variance")->isMatrix()) {
734 
735  _paramSet->getMatrix("selection_variance", &tmp_mat);
736 
737  if( !setSpatialMatrix("selection_variance","\"selection_trait_dimension\"", &tmp_mat, &var_spatmat,
738  (unsigned)_selectTraitDimension, patchNbr, _paramSet->isSet("selection_randomize") ) )
739  return error("LCE selection::failed to set patch-specific selection matrices from \"selection_variance\"\n");
740 
741  } else {
742 
743  var_spatmat.assign(get_parameter_value("selection_variance"));
744  }
745 
746  //setting correlation spatial matrix:
747  if(get_parameter("selection_correlation")->isSet() && _selectTraitDimension > 1)
748  {
749  corr_spatmat.reset(patchNbr, (unsigned)_selectTraitDimension*(_selectTraitDimension-1)/2);
750 
751  if(get_parameter("selection_correlation")->isMatrix()) {
752 
753  _paramSet->getMatrix("selection_correlation", &tmp_mat);
754 
755  if( !setSpatialMatrix("selection_correlation","the num of correlation coefficients", &tmp_mat, &corr_spatmat,
756  (unsigned)_selectTraitDimension*(_selectTraitDimension-1)/2, patchNbr, _paramSet->isSet("selection_randomize") ) )
757  return error("LCE selection::failed to set patch-specific selection matrices from \"selection_correlation\"\n");;
758 
759  } else {
760 
761  corr_spatmat.assign(get_parameter_value("selection_correlation"));
762  }
763  } else {
764  //a single trait or not set in input; matrix has a single row.
765  corr_spatmat.reset(patchNbr, 1, 0.0);
766  }
767 
768 
769  //set the selection matrix:
771  double covar;
772  unsigned int col;
773  for( unsigned int p = 0; p < patchNbr; p++) {
774  col = 0;
775  for( int i = 0; i < _selectTraitDimension; i++) {
776  tmp_mat.set(i, i, var_spatmat.get(p, i));
777  for( int j = i+1; j < _selectTraitDimension; j++) {
778  covar = corr_spatmat.get(p, col) * sqrt( var_spatmat.get(p, i) * var_spatmat.get(p, j) );
779  tmp_mat.set(i, j, covar);
780  tmp_mat.set(j, i, covar);
781  if(corr_spatmat.ncols() > 1) col++;
782  }
783  }
784  _selection_matrix.push_back(new TMatrix(tmp_mat));
785  }
786  }
787 
788  if(_selectTraitDimension > 1) {
789 
790  //selection on more than one trait
791 
792  //inverting the selection matrices:
793  if(_gsl_selection_matrix.size() != 0)
794  for(unsigned int i = 0; i < _gsl_selection_matrix.size(); ++i)
795  if(_gsl_selection_matrix[i] != NULL) gsl_matrix_free( _gsl_selection_matrix[i] );
796 
797  _gsl_selection_matrix.clear();
798 
799  for( unsigned int p = 0; p < patchNbr; p++) {
800  _selection_matrix[p]->inverse();
801 
802  _gsl_selection_matrix.push_back( gsl_matrix_alloc(_selectTraitDimension, _selectTraitDimension) );
803 
804  _selection_matrix[p]->get_gsl_matrix(_gsl_selection_matrix[p]);
805  }
806 
807  //allocate the vectors used by the fitness function:
808  if(_diffs != NULL) gsl_vector_free(_diffs);
809  _diffs = gsl_vector_alloc( _selectTraitDimension );
810 
811  if(_res1 != NULL) gsl_vector_free(_res1);
812  _res1 = gsl_vector_alloc( _selectTraitDimension );
813 
814  } else {
815 
816  //selection on one trait only
817  _selection_variance.clear();
818 
819  for(unsigned int p = 0; p < patchNbr; p++)
820  _selection_variance.push_back( _selection_matrix[p]->get(0, 0) );
821  }
822 
823 
824  return true;
825 }

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(), IndFactory::getTraitPrototype(), ParamSet::isSet(), TMatrix::ncols(), TMatrix::reset(), TMatrix::set(), and setSpatialMatrix().

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ setSelectionOffset()

bool LCE_Selection_base::setSelectionOffset ( double  default_val,
double  min_val 
)
830 {
831  unsigned int patchNbr = _popPtr->getPatchNbr();
832 
833  _selection_offset.reset(patchNbr, _selectTraitDimension, default_val);
834 
835  if(get_parameter("selection_offset")->isSet()) {
836 
837  if(get_parameter("selection_offset")->isMatrix()) {
838  TMatrix tmp_matx;
839  get_parameter("selection_offset")->getMatrix(&tmp_matx);
840 
841  if(tmp_matx.getNbRows() > patchNbr)
842  return error("\"selection_offset\" must have at max as many rows as the number of patches.\n");
843 
844  if(tmp_matx.ncols() > (unsigned)_selectTraitDimension)
845  return error("\"selection_offset\" must have at max as many columns as the number of selected traits.\n");
846 
848  } else {
849  _selection_offset.assign(get_parameter_value("selection_offset"));
850  }
851  }
852 
853  for(unsigned int i = 0; i < patchNbr; ++i)
854  for(int j = 0; j < _selectTraitDimension; ++j)
855  if(_selection_offset.get(i, j) < min_val)
856  return error("\"selection_offset\" value %g at patch %i, trait %i is below the minimum allowed value (%g).\n",
857  _selection_offset.get(i, j), i+1, j+1, min_val);
858 
859  return true;
860 }

References LifeCycleEvent::_popPtr, _selection_offset, _selectTraitDimension, TMatrix::assign(), TMatrix::copy_recycle(), error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), Param::getMatrix(), TMatrix::getNbRows(), Metapop::getPatchNbr(), TMatrix::ncols(), and TMatrix::reset().

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ setSelectTraitMapping()

bool LCE_Selection_base::setSelectTraitMapping ( unsigned int  num_quanti_traits)
621 {
622  _selectTraitMapping.clear();
623 
624  if(get_parameter("selection_trait_dimension")->isSet()) {
625 
626  if(get_parameter("selection_trait_dimension")->isMatrix()) {
627 
628  // matrix mode: array of 1-based trait indices
629  TMatrix tmp;
630  get_parameter("selection_trait_dimension")->getMatrix(&tmp);
631 
632  if(tmp.nrows() > 1)
633  return error("\"selection_trait_dimension\" must be a single row array when specifying trait indices.\n");
634 
635  for(unsigned int i = 0; i < tmp.ncols(); ++i) {
636  int idx = (int)tmp.get(0, i);
637  if(idx < 1 || idx > (int)num_quanti_traits)
638  return error("\"selection_trait_dimension\" trait index %i is out of range [1, %i].\n", idx, num_quanti_traits);
639  _selectTraitMapping.push_back((unsigned int)idx - 1); // 1-based to 0-based
640  }
641 
642  } else {
643 
644  // integer mode: number of traits, identity mapping
645  unsigned int N = (unsigned int)get_parameter_value("selection_trait_dimension");
646 
647  if(N > num_quanti_traits)
648  return error("\"selection_trait_dimension\" (%i) exceeds the number of quantitative traits (%i).\n", N, num_quanti_traits);
649 
650  for(unsigned int i = 0; i < N; ++i)
651  _selectTraitMapping.push_back(i);
652  }
653 
654  } else {
655  // default: single trait
656  _selectTraitMapping.push_back(0);
657  }
658 
660 
661  return true;
662 }

References _selectTraitDimension, _selectTraitMapping, error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), Param::getMatrix(), TMatrix::ncols(), and TMatrix::nrows().

Referenced by set_sel_model().

+ Here is the caller graph for this function:

◆ updateFitnessCounters()

void LCE_Selection_base::updateFitnessCounters ( double  fitness,
unsigned int  ped_class,
bool  survived 
)

Updates the fitness and survival mean counters.

Parameters
fitnessthe fitness of an individual
ped_classthe pedigree class of the individual
survivedboolean telling whether the individual survived (true) or not (false)
1434 {
1435 
1436  _fitness[ped_class] += fitness;
1437  _ind_cntr[ped_class]++;
1438 
1439  if(survived) _survival[ped_class]++;
1440 
1441 }

References _fitness, _ind_cntr, and _survival.

Referenced by doViabilitySelection(), and LCE_Breed_Selection::makeOffspringWithSelection().

+ Here is the caller graph for this function:

Friends And Related Function Documentation

◆ LCE_Breed_Selection

friend class LCE_Breed_Selection
friend

◆ LCE_SelectionFH

friend class LCE_SelectionFH
friend

Referenced by loadFileServices().

◆ LCE_SelectionSH

friend class LCE_SelectionSH
friend

The StatHandler associated class is a friend.

Referenced by loadStatServices().

Member Data Documentation

◆ _base_fitness

◆ _diffs

◆ _do_change_local_opt

bool LCE_Selection_base::_do_change_local_opt
private

◆ _eVariance

double LCE_Selection_base::_eVariance
protected

◆ _fitness

double LCE_Selection_base::_fitness[5]
protected

◆ _FitnessFixModel

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 getFitnessFixedEffect(), and set_sel_model().

◆ _Fpedigree

double LCE_Selection_base::_Fpedigree[5]
private

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

Referenced by set_sel_model().

◆ _getFitness

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().

◆ _getRawFitness

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().

◆ _gsl_selection_matrix

vector< gsl_matrix* > LCE_Selection_base::_gsl_selection_matrix
private

◆ _ind_cntr

◆ _is_absolute

bool LCE_Selection_base::_is_absolute
protected

◆ _is_local

bool LCE_Selection_base::_is_local
protected

◆ _letheq

double LCE_Selection_base::_letheq
private

Referenced by set_sel_model().

◆ _linear_selection_strength

TMatrix LCE_Selection_base::_linear_selection_strength
private

◆ _linearSelAgeClass

age_idx LCE_Selection_base::_linearSelAgeClass
private

◆ _linearSelTraitIndex

unsigned int LCE_Selection_base::_linearSelTraitIndex
private

◆ _local_optima

◆ _max_fitness

double LCE_Selection_base::_max_fitness
protected

Referenced by setParameters().

◆ _mean_fitness

◆ _mean_trait_value

vector<double> LCE_Selection_base::_mean_trait_value
private

◆ _rate_of_change_is_std

bool LCE_Selection_base::_rate_of_change_is_std
private

◆ _rate_of_change_local_optima

TMatrix LCE_Selection_base::_rate_of_change_local_optima
private

◆ _res1

◆ _scaling_factor

◆ _selection_matrix

vector< TMatrix* > LCE_Selection_base::_selection_matrix
private

◆ _selection_offset

◆ _selection_variance

vector< double > LCE_Selection_base::_selection_variance
protected

◆ _SelectionModels

vector< string > LCE_Selection_base::_SelectionModels
protected

The selection models associated with each trait under selection.

Referenced by set_local_optima(), and set_sel_model().

◆ _selectTraitDimension

◆ _selectTraitMapping

◆ _set_std_rate_at_generation

unsigned int LCE_Selection_base::_set_std_rate_at_generation
private

◆ _setNewLocalOptima

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 checkChangeLocalOptima(), set_param_rate_of_change(), and set_std_rate_of_change().

◆ _setScalingFactor

◆ _stater

LCE_SelectionSH* LCE_Selection_base::_stater
protected

◆ _std_rate_reference_patch

int LCE_Selection_base::_std_rate_reference_patch
private

◆ _survival

◆ _TraitIndices

vector< unsigned int > LCE_Selection_base::_TraitIndices
protected

◆ _Traits

vector< string > LCE_Selection_base::_Traits
protected

The list of trait types under selection.

Referenced by set_sel_model(), and setParameters().

◆ _truncation_threshold

TMatrix LCE_Selection_base::_truncation_threshold
private

◆ _truncation_upper

bool LCE_Selection_base::_truncation_upper
private

◆ _writer

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

Locations of visitors to this page
Catalogued on GSR