Nemo  2.4.2
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 ( )
44  : LifeCycleEvent("viability_selection", ""),
47 _diffs(0),
48 _res1(0),
56 _truncation_upper(true),
57 _letheq(0),
58 _base_fitness(1),
59 _mean_fitness(0),
60 _max_fitness(0),
62 _is_local(0),
63 _is_absolute(1),
64 _eVariance(0),
66 _getFitness(0),
69 _stater(0),
70 _writer(0)
71 {
72  // mandatory parameter (no default):
73  add_parameter("selection_trait", STR, true, false, 0, 0); //no updaters here, to keep it safe...
74 
77 
78  add_parameter("selection_fitness_model",STR,false,false,0,0, updater);
79 
81 
82  add_parameter("selection_model",STR,true,false,0,0, updater); //mandatory, depends on trait
83  add_parameter("selection_matrix",MAT,false,false,0,0, updater);
84  add_parameter("selection_variance",DBL,false,false,0,0, updater);
85  add_parameter("selection_correlation",DBL,false,false,0,0, updater);
86  add_parameter("selection_trait_dimension",INT,false,false,0,0, updater);
87  add_parameter("selection_base_fitness",DBL,false,true,0,1, updater);
88  add_parameter("selection_lethal_equivalents",DBL,false,false,0,0, updater);
89  add_parameter("selection_pedigree_F",MAT,false,false,0,0, updater);
90  add_parameter("selection_randomize",BOOL,false,false,0,0, updater);
91  add_parameter("selection_environmental_variance", DBL, false, false, 0, 0, updater);
92 
93  // linear selection:
94  add_parameter("selection_linear_strength", DBL, false, false, 0, 0, updater);
95  add_parameter("selection_offset", DBL, false, false, 0, 0, updater);
96  add_parameter("selection_at_stage", STR, false, false, 0, 0, updater);
97 
98  // truncation selection:
99  add_parameter("selection_truncation_threshold", DBL, false, false, 0, 0, updater);
100  add_parameter("selection_truncation_direction", STR, false, false, 0, 0, updater);
101 
103  add_parameter("selection_local_optima",DBL,false,false,0,0, updater);
104 
106  //renaming parameters:
107  add_parameter("selection_local_optima_rate_change", DBL, false, false, 0, 0, updater);
108  add_parameter("selection_local_optima_std_rate_change", DBL, false, false, 0, 0, updater);
109  add_parameter("selection_local_optima_std_rate_set_at_generation", INT, false, false, 0, 0, updater);
110  add_parameter("selection_local_optima_std_rate_reference_patch", INT, false, false, 0, 0, updater);
111 
112 // add_parameter("selection_rate_environmental_change", DBL, false, false, 0, 0, updater);
113 // add_parameter("selection_std_rate_environmental_change", DBL, false, false, 0, 0, updater);
114 // add_parameter("selection_std_rate_set_at_generation", INT, false, false, 0, 0, updater);
115 // add_parameter("selection_std_rate_reference_patch", INT, false, false, 0, 0, updater);
116 
117 
118  add_parameter("selection_output", BOOL, false, false, 0, 0, 0);
119  add_parameter("selection_output_logtime", INT, false, false, 0, 0, 0);
120  add_parameter("selection_output_dir", STR, false, false, 0, 0, 0);
121 }
int _selectTraitDimension
Number of quantitative traits under selection.
Definition: LCEselection.h:122
double _base_fitness
Definition: LCEselection.h:110
double(LCE_Selection_base::* _getFitness)(Individual *, unsigned int)
Pointer to the function returning the individual fitness.
Definition: LCEselection.h:150
double _max_fitness
Definition: LCEselection.h:111
vector< gsl_matrix * > _gsl_selection_matrix
Definition: LCEselection.h:54
LCE_SelectionFH * _writer
Definition: LCEselection.h:164
unsigned int _linearSelTraitIndex
Definition: LCEselection.h:73
gsl_vector * _diffs
Definition: LCEselection.h:55
bool set_param_rate_of_change()
Definition: LCEselection.cc:903
void(LCE_Selection_base::* _setScalingFactor)(age_idx, unsigned int)
Pointer to the function used to set the fitness scaling factor when fitness is relative.
Definition: LCEselection.h:155
bool _is_absolute
Definition: LCEselection.h:113
double _eVariance
Evironmental variance.
Definition: LCEselection.h:131
double _scaling_factor
Definition: LCEselection.h:111
bool _do_change_local_opt
Definition: LCEselection.h:59
bool _is_local
Definition: LCEselection.h:112
gsl_vector * _res1
Definition: LCEselection.h:56
bool set_sel_model()
Definition: LCEselection.cc:316
unsigned int _set_std_rate_at_generation
Definition: LCEselection.h:61
double _mean_fitness
Definition: LCEselection.h:111
bool set_fit_model()
Definition: LCEselection.cc:258
LCE_SelectionSH * _stater
Definition: LCEselection.h:163
int _std_rate_reference_patch
Definition: LCEselection.h:62
void(LCE_Selection_base::* _setNewLocalOptima)(void)
Pointer to the function used to change the local phenotypic optima or its rate of change.
Definition: LCEselection.h:159
vector< double(LCE_Selection_base::*)(Individual *, unsigned int, unsigned int) > _getRawFitness
A vector containing pointers to fitness function related to each trait under selection.
Definition: LCEselection.h:146
bool _truncation_upper
Definition: LCEselection.h:85
bool set_local_optima()
Definition: LCEselection.cc:864
double _letheq
Definition: LCEselection.h:91
vector< TMatrix * > _selection_matrix
Definition: LCEselection.h:53
bool _rate_of_change_is_std
Definition: LCEselection.h:60
age_idx _linearSelAgeClass
Definition: LCEselection.h:74
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:96
Implementation of the ParamUpdaterBase interface.
Definition: param.h:371
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:110
@ DBL
Definition: types.h:76
@ MAT
Definition: types.h:76
@ BOOL
Definition: types.h:76
@ STR
Definition: types.h:76
@ INT
Definition: types.h:76
@ OFFSx
Definition: types.h:40

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

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.

347 {return NONE;}
#define NONE
No age flag.
Definition: types.h:46

References NONE.

◆ addPhenotypicSD()

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

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 ( )
1312 {
1313  for (int i = 0; i < _selectTraitDimension; ++i)
1314  for (unsigned int j = 0; j < _local_optima.nrows(); ++j) {
1316  }
1317 }
TMatrix _rate_of_change_local_optima
Definition: LCEselection.h:58
TMatrix _local_optima
Definition: LCEselection.h:57
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:191
void plus(unsigned int i, unsigned int j, double value)
Adds a value to an element of the matrix.
Definition: tmatrix.h:254
unsigned int nrows() const
Definition: tmatrix.h:211

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.

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

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.

345 {return new LCE_Selection_base();}
LCE_Selection_base()
Definition: LCEselection.cc:44

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

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.

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

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

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

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.

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

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.

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

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.

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

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.

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

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.

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

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

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.

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

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.

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

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.

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

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.

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

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.

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

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.

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

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
176 {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
1197 {
1198  double max = 0, local_max;
1199 
1200  for(unsigned int i = 0, npatch = _popPtr->getPatchNbr(); i < npatch; i++) {
1201 
1202  local_max = getMaxPatchFitness(age, i);
1203 
1204  max = (local_max > max ? local_max : max);
1205  }
1206 
1207  return max;
1208 }
double getMaxPatchFitness(age_idx age, unsigned int p)
Computes the maximum fitness value in a given patch for a given age class.
Definition: LCEselection.cc:1212

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

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

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

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.

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

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.

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

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.

346 {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.

348 {return OFFSPRG;}

References OFFSPRG.

◆ resetCounters()

void LCE_Selection_base::resetCounters ( )

Resets the fitness counters.

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

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.

344 {return false;}

◆ set_fit_model()

bool LCE_Selection_base::set_fit_model ( )
259 {
260 
261  if(_paramSet->isSet("selection_fitness_model")) {
262 
263  string fit_model = _paramSet->getArg("selection_fitness_model");
264 
265  if( fit_model == "absolute") {
266 
267  _is_local = false;
268  _is_absolute = true;
271 
272  } else if( fit_model == "relative_local" ) {
273 
274  _is_local = true;
275  _is_absolute = false;
278 
279  } else if(fit_model == "relative_global") {
280 
281  _is_local = false;
282  _is_absolute = false;
285 
286  } else if(fit_model == "relative_max_local") {
287 
288  _is_local = true;
289  _is_absolute = false;
292 
293  } else if(fit_model == "relative_max_global") {
294 
295  _is_local = false;
296  _is_absolute = false;
299 
300  } else {
301  return error("Unknown fitness model \"%s\"", fit_model.c_str());
302  }
303  } //default case:
304  else {
305  _is_local = false;
306  _is_absolute = true;
309  }
310 
311  return true;
312 }
double getFitnessRelative(Individual *ind, unsigned int patch)
Returns the relative fitness of the individual, adjusted by a scaling factor.
Definition: LCEselection.h:286
void setScalingFactorAbsolute(age_idx age, unsigned int p)
Resets the fitness scaling factor equal to one.
Definition: LCEselection.h:324
void setScalingFactorMaxGlobal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the maximum population fitness value.
Definition: LCEselection.cc:1258
void setScalingFactorMaxLocal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the maximum local patch fitness value.
Definition: LCEselection.cc:1250
void setScalingFactorGlobal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the mean population fitness.
Definition: LCEselection.cc:1240
void setScalingFactorLocal(age_idx age, unsigned int p)
Sets the fitness scaling factor equal to the inverse of the mean local patch fitness.
Definition: LCEselection.cc:1232
string getArg(string name)
Accessor to the parameters argument string.
Definition: param.h:308
int error(const char *str,...)
Definition: output.cc:77

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

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

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

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

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
222 { 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:1162

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

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.

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

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

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

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

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

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

References _scaling_factor, and getMaxPatchFitness().

Referenced by set_fit_model().

+ Here is the caller graph for this function:

◆ setSelectionMatrix()

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

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

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

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)
1433 {
1434 
1435  _fitness[ped_class] += fitness;
1436  _ind_cntr[ped_class]++;
1437 
1438  if(survived) _survival[ped_class]++;
1439 
1440 }

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

Catalogued on GSR