|
Nemo
2.2.0
|
Base class performing (viability) selection. 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 | setSpatialMatrix (string param, TMatrix *mat, unsigned int nVal) |
| bool | setSelectionMatrix () |
| bool | setLocalOptima () |
| bool | set_sel_model () |
| bool | set_fit_model () |
| void | resetCounters () |
| Resets the fitness counters. | |
| void | setMeans (unsigned int tot_ind) |
| Computes the average fitness of each pedigree class. | |
| double | getMeanFitness (age_t AGE) |
| Computes the mean fitness of the whole population for a given age class. | |
| double | getMeanPatchFitness (age_idx AGE, unsigned int p) |
| Computes the mean fitness in a given patch for a given age class. | |
| double | setMeanFitness (age_t AGE) |
| Sets the _mean_fitness variable to the value of the mean population fitness. | |
| double | getFitness (Individual *ind, unsigned int patch) |
| Calls the fitness function according to the fitness model. | |
| double | getFitnessFixedEffect (Individual *offsprg, unsigned int patch) |
| Returns the fitness of an individual in the fixed selection model. | |
| double | getFitnessDirect (Individual *offsprg, unsigned int patch) |
| Returns the fitness of an individual following the direct selection model. | |
| double | getFitnessMultivariateGaussian (Individual *offsprg, unsigned int patch) |
| Returns the fitness of an individual following the Gaussian selection model with one trait under selection. | |
| double | getFitnessUnivariateGaussian (Individual *offsprg, unsigned int patch) |
| Returns the fitness of an individual following the Gaussian selection model with several traits under selection. | |
| double | getFitnessMultivariateGaussian_VE (Individual *offsprg, unsigned int patch) |
| Returns the fitness of an individual following the Gaussian selection model with one trait under selection and environmental variance. | |
| double | getFitnessUnivariateGaussian_VE (Individual *offsprg, unsigned int patch) |
| Returns the fitness of an individual following the Gaussian selection model with several traits under selection and environmental variance. | |
| double | getFitnessAbsolute (Individual *ind, unsigned int patch) |
| Returns the raw fitness of the individual, without adjustment (absolute fitness). | |
| double | getFitnessRelative (Individual *ind, unsigned int patch) |
| Returns the relative fitness of the individual, adjusted by a scaling factor. | |
| void | setScalingFactorLocal (age_t AGE, unsigned int p) |
| Sets the fitness scaling factor equal to the inverse of the mean local patch fitness. | |
| void | setScalingFactorGlobal (age_t AGE, unsigned int p) |
| Sets the fitness scaling factor equal to the inverse of the mean population fitness. | |
| void | setScalingFactorAbsolute (age_t AGE, unsigned int p) |
| Resets the fitness scaling factor equal to one. | |
| void | doViabilitySelection (sex_t SEX, age_idx AGE, Patch *patch, unsigned int p) |
| Selectively removes individuals in the population depending on their fitness. | |
Implementations | |
| virtual bool | setParameters () |
| Default interface needed to initialize the component's variables from its input parameters value. | |
| virtual void | execute () |
| Execute the event on the pop. | |
| virtual void | loadStatServices (StatServices *loader) |
| Loads the component's StatHandler onto the StatServices. | |
| virtual void | loadFileServices (FileServices *loader) |
| Loads the component's FileHandler onto the FileServices. | |
| virtual LifeCycleEvent * | clone () |
| Cloning interface. | |
| virtual age_t | removeAgeClass () |
| Removes the returned age-class flag(s) from the current Metapop age-class flags. | |
| virtual age_t | addAgeClass () |
| Adds the returned age-class flag(s) to the current Metapop age-class flags. | |
| virtual age_t | requiredAgeClass () |
| Specifies what age-classes are required by the LCE to execute. | |
Protected Attributes | |
| unsigned int | _nb_trait |
| int | _selectTraitDimension |
| vector< double > | _selection_variance |
| double | _letheq |
| double | _base_fitness |
| double | _mean_fitness |
| double | _max_fitness |
| double | _scaling_factor |
| bool | _is_local |
| bool | _is_absolute |
| double | _fitness [5] |
| Fitness counters, one for each pedigree class. | |
| double | _survival [5] |
| double | _ind_cntr [5] |
| double | _eVariance |
| double(LCE_Selection_base::* | _getRawFitness )(Individual *, unsigned int) |
| double(LCE_Selection_base::* | _getFitness )(Individual *, unsigned int) |
| void(LCE_Selection_base::* | _setScalingFactor )(age_t, unsigned int) |
| LCE_SelectionSH * | _stater |
Private Attributes | |
| double | _Fpedigree [5] |
| Array of pedigree values used in the fixed-selection model. | |
| double | _FitnessFixModel [5] |
| Absolute fitness values of the five pedigree class for the fixed selection model (lethal equivalents model). | |
Gaussian selection variables | |
| vector< TMatrix * > | _selection_matrix |
| vector< gsl_matrix * > | _gsl_selection_matrix |
| gsl_vector * | _diffs |
| gsl_vector * | _res1 |
| TMatrix * | _local_optima |
| double * | _phe |
Friends | |
| class | LCE_SelectionSH |
| The StatHandler associated class is a friend. | |
Base class performing (viability) selection.
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.
Definition at line 49 of file LCEselection.h.
| LCE_Selection_base::LCE_Selection_base | ( | ) |
Definition at line 41 of file LCEselection.cc.
References SimComponent::add_parameter(), BOOL, DBL, INT, MAT, set_fit_model(), set_sel_model(), and STR.
Referenced by clone().
: LifeCycleEvent("viability_selection", ""), _selection_matrix(0), _gsl_selection_matrix(0), _diffs(0), _res1(0), _local_optima(0), _phe(0), _selectTraitDimension(1), _base_fitness(1), _mean_fitness(0), _max_fitness(0), _scaling_factor(1), _is_local(0), _is_absolute(1), _eVariance(0), _getRawFitness(0), _getFitness(0), _stater(0) { add_parameter("selection_trait",STR,false,false,0,0); //no updaters here, to keep it safe... ParamUpdater< LCE_Selection_base > * updater = new ParamUpdater<LCE_Selection_base>(&LCE_Selection_base::set_fit_model); add_parameter("selection_fitness_model",STR,false,false,0,0, updater); updater = new ParamUpdater<LCE_Selection_base>(&LCE_Selection_base::set_sel_model); add_parameter("selection_model",STR,false,false,0,0, updater); add_parameter("selection_matrix",MAT,false,false,0,0, updater); add_parameter("selection_variance",DBL,false,false,0,0, updater); add_parameter("selection_correlation",DBL,false,false,0,0, updater); add_parameter("selection_trait_dimension",INT,false,false,0,0, updater); add_parameter("selection_base_fitness",DBL,false,true,0,1, updater); add_parameter("selection_lethal_equivalents",DBL,false,false,0,0, updater); add_parameter("selection_pedigree_F",MAT,false,false,0,0, updater); add_parameter("selection_local_optima",DBL,false,false,0,0, updater); add_parameter("selection_randomize",BOOL,false,false,0,0, updater); add_parameter("selection_environmental_variance", DBL, false, false, 0, 0, updater); }
| LCE_Selection_base::~LCE_Selection_base | ( | ) | [virtual] |
Definition at line 70 of file LCEselection.cc.
References _diffs, _gsl_selection_matrix, _local_optima, _phe, _res1, _selection_matrix, and _stater.
{
for(unsigned int i = 0; i < _selection_matrix.size(); ++i)
delete _selection_matrix[i];
for(unsigned int i = 0; i < _gsl_selection_matrix.size(); ++i)
gsl_matrix_free(_gsl_selection_matrix[i]);
if(_local_optima != 0) delete _local_optima;
if(_diffs != 0) gsl_vector_free(_diffs);
if(_res1 != 0) gsl_vector_free(_res1);
if(_phe != 0) delete [] _phe;
if(_stater) delete _stater;
}
| virtual age_t LCE_Selection_base::addAgeClass | ( | ) | [inline, virtual] |
Adds the returned age-class flag(s) to the current Metapop age-class flags.
Implements LifeCycleEvent.
Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.
Definition at line 226 of file LCEselection.h.
References NONE.
{return NONE;}
| virtual LifeCycleEvent* LCE_Selection_base::clone | ( | ) | [inline, virtual] |
Cloning interface.
Implements LifeCycleEvent.
Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.
Definition at line 224 of file LCEselection.h.
References LCE_Selection_base().
{return new LCE_Selection_base();}
| 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.
| SEX | the sex class |
| AGE | the age class index |
| patch | the focal patch |
| p | the focal patch index |
Definition at line 580 of file LCEselection.cc.
References _fitness, _ind_cntr, LifeCycleEvent::_popPtr, Patch::get(), getFitness(), Individual::getPedigreeClass(), IndFactory::recycle(), Patch::remove(), Patch::size(), and RAND::Uniform().
Referenced by execute().
{
register Individual* ind;
register double fitness;
register unsigned int cat;
for(unsigned int i = 0; i < patch->size(SEX, AGE); i++) {
ind = patch->get(SEX, AGE, i);
cat = ind->getPedigreeClass();
fitness = getFitness( ind, p);
_fitness[cat] += fitness;
_ind_cntr[cat]++;
if(RAND::Uniform() > fitness ) {
patch->remove(SEX, AGE, i);
_popPtr->recycle(ind);
i--;
} //else; this individual stays in the patch
}
}
| void LCE_Selection_base::execute | ( | ) | [virtual] |
Execute the event on the pop.
Implements LifeCycleEvent.
Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.
Definition at line 557 of file LCEselection.cc.
References LifeCycleEvent::_popPtr, _setScalingFactor, doViabilitySelection(), FEM, Metapop::getPatch(), Metapop::getPatchNbr(), MAL, OFFSPRG, OFFSx, resetCounters(), setMeans(), and Metapop::size().
{
Patch * patch;
unsigned int popSize = _popPtr->size(OFFSPRG);
resetCounters();
for(unsigned int p = 0; p < _popPtr->getPatchNbr(); p++) {
(this->*_setScalingFactor)(OFFSPRG, p);
patch = _popPtr->getPatch(p);
doViabilitySelection(FEM, OFFSx, patch, p);
doViabilitySelection(MAL, OFFSx, patch, p);
}
setMeans(popSize);
}
| 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".
| ind | the focal indvidual, we want to know its fitness |
| patch | the index of the patch of the focal individual |
Definition at line 139 of file LCEselection.h.
References _getFitness.
Referenced by doViabilitySelection(), getMeanFitness(), getMeanPatchFitness(), LCE_SelectionSH::getPatchFitness(), and LCE_Breed_Selection::makeOffspringWithSelection().
{
return (this->*_getFitness)(ind, patch);
}
| double LCE_Selection_base::getFitnessAbsolute | ( | Individual * | ind, |
| unsigned int | patch | ||
| ) | [inline] |
Returns the raw fitness of the individual, without adjustment (absolute fitness).
Calls the fitness function according to the right selection model.
| ind | the focal indvidual, we want to know its fitness |
| patch | the index of the patch of the focal individual |
Definition at line 173 of file LCEselection.h.
References _getRawFitness.
Referenced by set_fit_model().
{
return (this->*_getRawFitness)(ind, patch);
}
| double LCE_Selection_base::getFitnessDirect | ( | Individual * | offsprg, |
| unsigned int | patch | ||
| ) | [inline] |
Returns the fitness of an individual following the direct selection model.
Definition at line 151 of file LCEselection.h.
References LifeCycleEvent::_LCELinkedTraitIndex, and Individual::getTraitValue().
Referenced by set_sel_model().
{
return *(double*)offsprg->getTraitValue(_LCELinkedTraitIndex);
}
| double LCE_Selection_base::getFitnessFixedEffect | ( | Individual * | offsprg, |
| unsigned int | patch | ||
| ) | [inline] |
Returns the fitness of an individual in the fixed selection model.
Definition at line 145 of file LCEselection.h.
References _FitnessFixModel, and Individual::getPedigreeClass().
Referenced by set_sel_model().
{
return _FitnessFixModel[ offsprg->getPedigreeClass() ];
}
| double LCE_Selection_base::getFitnessMultivariateGaussian | ( | Individual * | offsprg, |
| unsigned int | patch | ||
| ) |
Returns the fitness of an individual following the Gaussian selection model with one trait under selection.
Definition at line 446 of file LCEselection.cc.
References _diffs, _gsl_selection_matrix, LifeCycleEvent::_LCELinkedTraitIndex, _local_optima, _phe, _res1, _selectTraitDimension, fatal(), TMatrix::get(), and Individual::getTraitValue().
Referenced by setSelectionMatrix().
{
register double res2;
if(!ind) fatal("passing NULL ind ptr to LCE_Selection_base::getFitnessMultivariateGaussian!!!\n");
_phe = (double*)ind->getTraitValue(_LCELinkedTraitIndex);
for( int i = 0; i < _selectTraitDimension; i++)
gsl_vector_set(_diffs, i, _phe[i] - _local_optima->get(patch, i));
//(diff)T * W * diff:
//right partial product:
gsl_blas_dsymv(CblasUpper, 1.0, _gsl_selection_matrix[patch], _diffs, 0.0, _res1);
//left product:
gsl_blas_ddot(_diffs, _res1, &res2);
return exp( -0.5 * res2 );
}
| double LCE_Selection_base::getFitnessMultivariateGaussian_VE | ( | Individual * | offsprg, |
| unsigned int | patch | ||
| ) |
Returns the fitness of an individual following the Gaussian selection model with one trait under selection and environmental variance.
Definition at line 484 of file LCEselection.cc.
References _diffs, _eVariance, _gsl_selection_matrix, LifeCycleEvent::_LCELinkedTraitIndex, _local_optima, _phe, _res1, _selectTraitDimension, RAND::Gaussian(), TMatrix::get(), and Individual::getTraitValue().
Referenced by setSelectionMatrix().
{
register double res2;
_phe = (double*)ind->getTraitValue(_LCELinkedTraitIndex);
//add the environmental variance here:
for( int i = 0; i < _selectTraitDimension; i++)
gsl_vector_set(_diffs, i, _phe[i] + RAND::Gaussian(_eVariance) - _local_optima->get(patch, i));
//(diff)T * W * diff:
//right partial product:
gsl_blas_dsymv(CblasUpper, 1.0, _gsl_selection_matrix[patch], _diffs, 0.0, _res1);
//left product:
gsl_blas_ddot(_diffs, _res1, &res2);
return exp( -0.5 * res2 );
}
| 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.
| ind | the focal indvidual, we want to know its fitness |
| patch | the index of the patch of the focal individual |
Definition at line 185 of file LCEselection.h.
References _getRawFitness, and _scaling_factor.
Referenced by set_fit_model().
{
return (this->*_getRawFitness)(ind, patch) * _scaling_factor;
}
| double LCE_Selection_base::getFitnessUnivariateGaussian | ( | Individual * | offsprg, |
| unsigned int | patch | ||
| ) |
Returns the fitness of an individual following the Gaussian selection model with several traits under selection.
Definition at line 431 of file LCEselection.cc.
References LifeCycleEvent::_LCELinkedTraitIndex, _local_optima, _phe, _selection_variance, TMatrix::get(), and Individual::getTraitValue().
Referenced by setSelectionMatrix().
{
register double res2, diff;
_phe = (double*)ind->getTraitValue(_LCELinkedTraitIndex);
diff = _phe[0] - _local_optima->get(patch, 0);
res2 = diff*diff / _selection_variance[patch];
return exp( -0.5 * res2 );
}
| double LCE_Selection_base::getFitnessUnivariateGaussian_VE | ( | Individual * | offsprg, |
| unsigned int | patch | ||
| ) |
Returns the fitness of an individual following the Gaussian selection model with several traits under selection and environmental variance.
Definition at line 468 of file LCEselection.cc.
References _eVariance, LifeCycleEvent::_LCELinkedTraitIndex, _local_optima, _phe, _selection_variance, RAND::Gaussian(), TMatrix::get(), and Individual::getTraitValue().
Referenced by setSelectionMatrix().
{
register double res2, diff;
_phe = (double*)ind->getTraitValue(_LCELinkedTraitIndex);
//add the environmental variance here:
diff = _phe[0] + RAND::Gaussian(_eVariance) - _local_optima->get(patch, 0);
res2 = diff*diff / _selection_variance[patch];
return exp( -0.5 * res2 );
}
| double LCE_Selection_base::getMeanFitness | ( | age_t | AGE | ) |
Computes the mean fitness of the whole population for a given age class.
| AGE | the age class flag |
Definition at line 506 of file LCEselection.cc.
References LifeCycleEvent::_popPtr, ADLTx, ADULTS, FEM, Patch::get(), getFitness(), Metapop::getPatch(), Metapop::getPatchNbr(), MAL, OFFSx, Metapop::size(), and Patch::size().
Referenced by LCE_Breed_Selection_Disperse::execute(), setMeanFitness(), and setScalingFactorGlobal().
{
double mean = 0;
Patch *patch;
age_idx age = (AGE == ADULTS ? ADLTx : OFFSx);
for(unsigned int i = 0, npatch = _popPtr->getPatchNbr(); i < npatch; i++) {
patch = _popPtr->getPatch(i);
for(unsigned int j = 0, size = patch->size(FEM, AGE); j < size; j++)
mean += getFitness( patch->get(FEM, age, j), i);
for(unsigned int j = 0, size = patch->size(MAL, AGE); j < size; j++)
mean += getFitness( patch->get(MAL, age, j), i);
}
return mean/_popPtr->size(AGE);
}
| double LCE_Selection_base::getMeanPatchFitness | ( | age_idx | AGE, |
| unsigned int | p | ||
| ) |
Computes the mean fitness in a given patch for a given age class.
| AGE | the index of the age class |
| p | the patch index |
Definition at line 524 of file LCEselection.cc.
References LifeCycleEvent::_popPtr, FEM, Patch::get(), getFitness(), Metapop::getPatch(), MAL, and Patch::size().
Referenced by LCE_Breed_Selection_Disperse::breed_selection_disperse(), and setScalingFactorLocal().
{
double mean = 0;
Patch *patch = _popPtr->getPatch(p);
for(unsigned int j = 0, size = patch->size(FEM, age); j < size; j++)
mean += getFitness( patch->get(FEM, age, j), p);
for(unsigned int j = 0, size = patch->size(MAL, age); j < size; j++)
mean += getFitness( patch->get(MAL, age, j), p);
return mean/patch->size(age);
}
| virtual void LCE_Selection_base::loadFileServices | ( | FileServices * | loader | ) | [inline, virtual] |
Loads the component's FileHandler onto the FileServices.
| loader | the file service |
Implements SimComponent.
Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.
Definition at line 223 of file LCEselection.h.
{}
| void LCE_Selection_base::loadStatServices | ( | StatServices * | loader | ) | [virtual] |
Loads the component's StatHandler onto the StatServices.
| loader | the stat service |
Implements SimComponent.
Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.
Definition at line 85 of file LCEselection.cc.
References _stater, StatServices::attach(), and LCE_SelectionSH.
{
if(_stater == NULL) _stater = new LCE_SelectionSH(this);
loader->attach(_stater);
}
| virtual age_t LCE_Selection_base::removeAgeClass | ( | ) | [inline, virtual] |
Removes the returned age-class flag(s) from the current Metapop age-class flags.
Implements LifeCycleEvent.
Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.
Definition at line 225 of file LCEselection.h.
References NONE.
{return NONE;}
| virtual age_t LCE_Selection_base::requiredAgeClass | ( | ) | [inline, virtual] |
Specifies what age-classes are required by the LCE to execute.
Implements LifeCycleEvent.
Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.
Definition at line 227 of file LCEselection.h.
References OFFSPRG.
{return OFFSPRG;}
| void LCE_Selection_base::resetCounters | ( | ) | [inline] |
Resets the fitness counters.
Definition at line 98 of file LCEselection.h.
References _fitness, _ind_cntr, and _survival.
Referenced by LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), execute(), and setParameters().
| bool LCE_Selection_base::set_fit_model | ( | ) |
Definition at line 111 of file LCEselection.cc.
References _getFitness, _is_absolute, _is_local, SimComponent::_paramSet, _setScalingFactor, error(), ParamSet::getArg(), getFitnessAbsolute(), getFitnessRelative(), ParamSet::isSet(), setScalingFactorAbsolute(), setScalingFactorGlobal(), and setScalingFactorLocal().
Referenced by LCE_Selection_base(), and setParameters().
{
if(_paramSet->isSet("selection_fitness_model")) {
string fit_model = _paramSet->getArg("selection_fitness_model");
if(fit_model.compare("absolute") == 0) {
_is_local = false;
_is_absolute = true;
_getFitness = &LCE_Selection_base::getFitnessAbsolute;
_setScalingFactor = &LCE_Selection_base::setScalingFactorAbsolute;
} else if(fit_model.compare("relative_local") == 0) {
_is_local = true;
_is_absolute = false;
_getFitness = &LCE_Selection_base::getFitnessRelative;
_setScalingFactor = &LCE_Selection_base::setScalingFactorLocal;
} else if(fit_model.compare("relative_global") == 0) {
_is_local = false;
_is_absolute = false;
_getFitness = &LCE_Selection_base::getFitnessRelative;
_setScalingFactor = &LCE_Selection_base::setScalingFactorGlobal;
} else {
error("Unknown fitness model \"%s\"", fit_model.c_str());
return false;
}
} //default case:
else {
_is_local = false;
_is_absolute = true;
_getFitness = &LCE_Selection_base::getFitnessAbsolute;
_setScalingFactor = &LCE_Selection_base::setScalingFactorAbsolute;
}
return true;
}
| bool LCE_Selection_base::set_sel_model | ( | ) |
Definition at line 156 of file LCEselection.cc.
References _base_fitness, _eVariance, _FitnessFixModel, _Fpedigree, _getRawFitness, _letheq, SimComponent::_paramSet, _selectTraitDimension, error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), ParamSet::getArg(), getFitnessDirect(), getFitnessFixedEffect(), Param::getMatrix(), TMatrix::getNbCols(), Param::isSet(), ParamSet::isSet(), setSelectionMatrix(), and warning().
Referenced by LCE_Selection_base(), and setParameters().
{
_selectTraitDimension = (int)get_parameter_value("selection_trait_dimension");
_base_fitness = get_parameter_value("selection_base_fitness");
if(get_parameter("selection_environmental_variance")->isSet())
//the variable actually olds the standard dev...
_eVariance = sqrt(get_parameter_value("selection_environmental_variance"));
else
_eVariance = 0;
if(!_paramSet->isSet("selection_model")) {
_getRawFitness = &LCE_Selection_base::getFitnessDirect;
} else {
string sel_model = _paramSet->getArg("selection_model");
if(sel_model.compare("fix") == 0) {
if(!get_parameter("selection_lethal_equivalents")->isSet()) {
error("\"selection_lethal_equivalents\" parameter is missing with \"fix\" selection!\n");
return false;
} else
_letheq = get_parameter_value("selection_lethal_equivalents");
if(!get_parameter("selection_base_fitness")->isSet()) {
warning("\"selection_base_fitness\" parameter is missing under fix selection model, setting it to 1.\n");
_base_fitness = 1.0;
}
if(!get_parameter("selection_pedigree_F")->isSet()) {
error("\"selection_pedigree_F\" parameter is missing with \"fix\" selection!\n");
return false;
} else {
TMatrix tmp_mat;
get_parameter("selection_pedigree_F")->getMatrix(&tmp_mat);
if(tmp_mat.getNbCols() != 5) {
error("\"selection_pedigree_F\" must be an array of size 5.\n");
return false;
}
for(unsigned int i = 0; i < 5; i++)
_Fpedigree[i] = tmp_mat.get(0,i);
}
for(unsigned int i = 0; i < 5; i++)
_FitnessFixModel[i] = _base_fitness * exp( -_letheq * _Fpedigree[i] );
_getRawFitness = &LCE_Selection_base::getFitnessFixedEffect;
} else if(sel_model.compare("direct") == 0) {
//check trait dimensionality!!
_getRawFitness = &LCE_Selection_base::getFitnessDirect;
} else if(sel_model.compare("gaussian") == 0) {
return setSelectionMatrix();
} else {
error("wrong selection model, must be either \"fix\", \"direct\", or \"gaussian\".\n");
return false;
}
} //end_if isSet()
return true;
}
| bool LCE_Selection_base::setLocalOptima | ( | ) |
| double LCE_Selection_base::setMeanFitness | ( | age_t | AGE | ) | [inline] |
Sets the _mean_fitness variable to the value of the mean population fitness.
| AGE | the age class flag |
Definition at line 133 of file LCEselection.h.
References _mean_fitness, and getMeanFitness().
{ return (_mean_fitness = getMeanFitness(AGE));}
| void LCE_Selection_base::setMeans | ( | unsigned int | tot_ind | ) | [inline] |
Computes the average fitness of each pedigree class.
Called after selection has been done in the whole population.
| tot_ind | count of the total number of individuals produced |
Definition at line 109 of file LCEselection.h.
References _fitness, _ind_cntr, _mean_fitness, and _survival.
Referenced by LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), and execute().
{
_mean_fitness = 0;
for(unsigned int i = 0; i < 5; i++) {
_mean_fitness += _fitness[i];
_fitness[i] /= _ind_cntr[i];
_survival[i] /= _ind_cntr[i];
_ind_cntr[i] /= tot_ind;
}
_mean_fitness /= tot_ind;
}
| bool LCE_Selection_base::setParameters | ( | ) | [virtual] |
Default interface needed to initialize the component's variables from its input parameters value.
Formerly called 'init'.
Implements SimComponent.
Reimplemented in LCE_Breed_Selection_Disperse, and LCE_Breed_Selection.
Definition at line 93 of file LCEselection.cc.
References _max_fitness, _mean_fitness, _nb_trait, LifeCycleEvent::_popPtr, _scaling_factor, LifeCycleEvent::attach_trait(), SimComponent::get_parameter(), IndFactory::getIndividualProtoype(), Individual::getTraitNumber(), resetCounters(), set_fit_model(), and set_sel_model().
Referenced by LCE_Breed_Selection::setParameters(), and LCE_Breed_Selection_Disperse::setParameters().
{
if(!attach_trait(get_parameter("selection_trait")->getArg())) return false;
if(!set_fit_model()) return false;
if(!set_sel_model()) return false;
_mean_fitness = _max_fitness = 0;
_nb_trait = _popPtr->getIndividualProtoype()->getTraitNumber();
_scaling_factor = 1;
resetCounters();
return true;
}
| void LCE_Selection_base::setScalingFactorAbsolute | ( | age_t | AGE, |
| unsigned int | p | ||
| ) | [inline] |
Resets the fitness scaling factor equal to one.
| AGE | the age class flag (unused here) |
| p | the focal patch index (unused here) |
Definition at line 205 of file LCEselection.h.
References _scaling_factor.
Referenced by set_fit_model().
{ _scaling_factor = 1; }
| void LCE_Selection_base::setScalingFactorGlobal | ( | age_t | 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.
| AGE | the age class flag |
| p | the focal patch index |
Definition at line 548 of file LCEselection.cc.
References _scaling_factor, and getMeanFitness().
Referenced by LCE_SelectionSH::getPatchFitness(), and set_fit_model().
{
if(p != 0) return; //we compupte the mean fitness only once
_scaling_factor = 1;
_scaling_factor = 1.0/getMeanFitness(AGE);
}
| void LCE_Selection_base::setScalingFactorLocal | ( | age_t | AGE, |
| unsigned int | p | ||
| ) |
Sets the fitness scaling factor equal to the inverse of the mean local patch fitness.
| AGE | the age class flag |
| p | the focal patch index |
Definition at line 540 of file LCEselection.cc.
References _scaling_factor, getMeanPatchFitness(), and OFFSx.
Referenced by LCE_SelectionSH::getPatchFitness(), and set_fit_model().
{
_scaling_factor = 1; //this to have the raw mean fitness below
_scaling_factor = 1.0/getMeanPatchFitness(OFFSx, p);
}
| bool LCE_Selection_base::setSelectionMatrix | ( | ) |
Definition at line 227 of file LCEselection.cc.
References _diffs, _eVariance, _getRawFitness, _gsl_selection_matrix, _local_optima, SimComponent::_paramSet, LifeCycleEvent::_popPtr, _res1, _selection_matrix, _selection_variance, _selectTraitDimension, TMatrix::assign(), error(), TMatrix::get(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), getFitnessUnivariateGaussian(), getFitnessUnivariateGaussian_VE(), ParamSet::getMatrix(), TMatrix::getNbCols(), TMatrix::getNbRows(), Metapop::getPatchNbr(), Param::isSet(), TMatrix::reset(), TMatrix::set(), and setSpatialMatrix().
Referenced by set_sel_model().
{
TMatrix tmp_mat;
unsigned int patchNbr = _popPtr->getPatchNbr();
if(!get_parameter("selection_matrix")->isSet() && !get_parameter("selection_variance")->isSet()) {
error("\"selection_matrix\" or \"selection_variance\" must be set with selection model = \"gaussian\".\n");
return false;
}
if(get_parameter("selection_variance")->isSet() && !get_parameter("selection_trait_dimension")->isSet()) {
error("parameter \"selection_trait_dimension\" is missing!\n");
return false;
}
_selection_matrix.clear();
if(get_parameter("selection_matrix")->isSet()) {
//selection matrix provided, same selection surface in each patch
_paramSet->getMatrix("selection_matrix", &tmp_mat);
if(tmp_mat.getNbCols() != tmp_mat.getNbRows()) {
error("\"selection_matrix\" must be a square matrix!\n");
return false;
}
_selectTraitDimension = tmp_mat.getNbCols();
//we have one selection matrix per patch
for(unsigned int i = 0; i < patchNbr; ++i)
_selection_matrix.push_back( new TMatrix(tmp_mat) );
} else {
//we have to check for spatial variation in variance and covariances
_selectTraitDimension = (unsigned int)get_parameter_value("selection_trait_dimension");
TMatrix var_spatmat, corr_spatmat;
//setting variance spatial matrix:
var_spatmat.reset(patchNbr, (unsigned)_selectTraitDimension);
if(get_parameter("selection_variance")->isMatrix()) {
if( !setSpatialMatrix("selection_variance", &var_spatmat, (unsigned)_selectTraitDimension) ) return false;
} else {
var_spatmat.assign(get_parameter_value("selection_variance"));
}
//setting correlation spatial matrix:
corr_spatmat.reset(patchNbr, (unsigned)_selectTraitDimension*(_selectTraitDimension-1)/2);
if(get_parameter("selection_correlation")->isMatrix()) {
if( !setSpatialMatrix("selection_correlation", &corr_spatmat, (unsigned)_selectTraitDimension*(_selectTraitDimension-1)/2 ) )
return false;
} else {
corr_spatmat.assign((get_parameter("selection_correlation")->isSet() ?
get_parameter_value("selection_correlation") : 0.0 ));
}
//set the selection matrix:
tmp_mat.reset(_selectTraitDimension, _selectTraitDimension);
double covar;
unsigned int col;
for( unsigned int p = 0; p < patchNbr; p++) {
col = 0;
for( int i = 0; i < _selectTraitDimension; i++) {
tmp_mat.set(i, i, var_spatmat.get(p, i));
for( int j = i+1; j < _selectTraitDimension; j++) {
covar = corr_spatmat.get(p, col) * sqrt( var_spatmat.get(p, i) * var_spatmat.get(p, j) );
tmp_mat.set(i, j, covar);
tmp_mat.set(j, i, covar);
col++;
}
}
_selection_matrix.push_back(new TMatrix(tmp_mat));
}
}
if(_selectTraitDimension > 1) {
//selection on more than one trait
//inversing the selection matrices:
if(_gsl_selection_matrix.size() != 0)
for(unsigned int i = 0; i < _gsl_selection_matrix.size(); ++i)
if(_gsl_selection_matrix[i] != NULL) gsl_matrix_free( _gsl_selection_matrix[i] );
_gsl_selection_matrix.clear();
for( unsigned int p = 0; p < patchNbr; p++) {
_selection_matrix[p]->inverse();
_gsl_selection_matrix.push_back( gsl_matrix_alloc(_selectTraitDimension, _selectTraitDimension) );
_selection_matrix[p]->get_gsl_matrix(_gsl_selection_matrix[p]);
}
//allocate the vectors used by the fitness function:
if(_diffs != NULL) gsl_vector_free(_diffs);
_diffs = gsl_vector_alloc( _selectTraitDimension );
if(_res1 != NULL) gsl_vector_free(_res1);
_res1 = gsl_vector_alloc( _selectTraitDimension );
if(_eVariance > 0)
_getRawFitness = &LCE_Selection_base::getFitnessMultivariateGaussian_VE;
else
_getRawFitness = &LCE_Selection_base::getFitnessMultivariateGaussian;
} else {
//selection on one trait only
_selection_variance.clear();
for(unsigned int p = 0; p < patchNbr; p++)
_selection_variance.push_back( _selection_matrix[p]->get(0, 0) );
if(_eVariance > 0)
_getRawFitness = &LCE_Selection_base::getFitnessUnivariateGaussian_VE;
else
_getRawFitness = &LCE_Selection_base::getFitnessUnivariateGaussian;
}
//set the traits' local optima, _selectTraitDimension must be set before that (= nbr of traits to select on)
if(!get_parameter("selection_local_optima")->isSet()) {
error("parameter \"selection_local_optima\" must be set to have Gaussian selection.\n");
return false;
} else {
if(_local_optima == 0) _local_optima = new TMatrix();
_local_optima->reset(patchNbr, _selectTraitDimension);
return setSpatialMatrix("selection_local_optima", _local_optima, _selectTraitDimension);
}
return true;
}
| bool LCE_Selection_base::setSpatialMatrix | ( | string | param, |
| TMatrix * | mat, | ||
| unsigned int | nVal | ||
| ) |
Definition at line 372 of file LCEselection.cc.
References SimComponent::_paramSet, LifeCycleEvent::_popPtr, error(), TMatrix::get(), ParamSet::getMatrix(), TMatrix::getNbCols(), TMatrix::getNbRows(), Metapop::getPatchNbr(), ParamSet::isSet(), TMatrix::set(), and RAND::Uniform().
Referenced by setSelectionMatrix().
{
TMatrix pat_mat;
unsigned int patchNbr = _popPtr->getPatchNbr();
_paramSet->getMatrix(param, &pat_mat);
unsigned int ncol = pat_mat.getNbCols(); //nbr of local optima = nbr of traits = nbr of col
unsigned int npat = pat_mat.getNbRows(); //nbr of diff. value / traits, may be <= patchNbr
//we have two possible configurations:
// 1. ncol == 1; same value for all 'traits' in a patch but varies among patches, with possible repetition of a pattern
// 2. ncol == no traits && npat <= no patches; trait values change in each patch following a pattern (same if npat == 1)
if(npat > patchNbr) {
error("The number of rows in \"%s\" is greater than the number of patches, must be at least equal to this.", param.c_str());
return false;
}
if(ncol != 1 && ncol != nVal) {
error("The number of columns in \"%s\" differs from its expected value.\n", param.c_str());
error("It is expected to be either 1, or equal to \"selection_trait_dimension\" (%i).\n", nVal);
return false;
}
if(_paramSet->isSet("selection_randomize")) {
for(unsigned int i = 0; i < patchNbr; ++i)
for(unsigned int j = 0; j < nVal; j++)
mat->set(i, j, pat_mat.get( RAND::Uniform(npat), j));
} else {
for(unsigned int i = 0; i < patchNbr; ++i) {
if(npat < patchNbr) {//repetition of a pattern
if(ncol == 1)
for(unsigned int j = 0; j < nVal; j++)
mat->set(i, j, pat_mat.get(i % npat, 0));
else
for(unsigned int j = 0; j < nVal; j++)
mat->set(i, j, pat_mat.get(i % npat, j));
} else {//different values for each Patch
if(ncol == 1)
for(unsigned int j = 0; j < nVal; j++)
mat->set(i, j, pat_mat.get(i, 0));
else
for(unsigned int j = 0; j < nVal; j++)
mat->set(i, j, pat_mat.get(i, j));
}
}
}
return true;
}
friend class LCE_SelectionSH [friend] |
The StatHandler associated class is a friend.
Definition at line 65 of file LCEselection.h.
Referenced by loadStatServices().
double LCE_Selection_base::_base_fitness [protected] |
Definition at line 72 of file LCEselection.h.
Referenced by LCE_Breed_Selection_Disperse::breed_selection_disperse(), set_sel_model(), and LCE_Breed_Selection_Disperse::setParameters().
gsl_vector* LCE_Selection_base::_diffs [private] |
Definition at line 55 of file LCEselection.h.
Referenced by getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), setSelectionMatrix(), and ~LCE_Selection_base().
double LCE_Selection_base::_eVariance [protected] |
Definition at line 78 of file LCEselection.h.
Referenced by getFitnessMultivariateGaussian_VE(), getFitnessUnivariateGaussian_VE(), set_sel_model(), and setSelectionMatrix().
double LCE_Selection_base::_fitness[5] [protected] |
Fitness counters, one for each pedigree class.
Definition at line 76 of file LCEselection.h.
Referenced by doViabilitySelection(), LCE_SelectionSH::getFitness(), LCE_Breed_Selection::makeOffspringWithSelection(), resetCounters(), and setMeans().
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] );
Definition at line 63 of file LCEselection.h.
Referenced by getFitnessFixedEffect(), and set_sel_model().
double LCE_Selection_base::_Fpedigree[5] [private] |
Array of pedigree values used in the fixed-selection model.
Definition at line 60 of file LCEselection.h.
Referenced by set_sel_model().
double(LCE_Selection_base::* LCE_Selection_base::_getFitness)(Individual *, unsigned int) [protected] |
Definition at line 81 of file LCEselection.h.
Referenced by getFitness(), and set_fit_model().
double(LCE_Selection_base::* LCE_Selection_base::_getRawFitness)(Individual *, unsigned int) [protected] |
Definition at line 80 of file LCEselection.h.
Referenced by getFitnessAbsolute(), getFitnessRelative(), set_sel_model(), and setSelectionMatrix().
vector< gsl_matrix* > LCE_Selection_base::_gsl_selection_matrix [private] |
Definition at line 54 of file LCEselection.h.
Referenced by getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), setSelectionMatrix(), and ~LCE_Selection_base().
double LCE_Selection_base::_ind_cntr[5] [protected] |
Definition at line 76 of file LCEselection.h.
Referenced by doViabilitySelection(), LCE_SelectionSH::getPedProp(), LCE_Breed_Selection::makeOffspringWithSelection(), resetCounters(), and setMeans().
bool LCE_Selection_base::_is_absolute [protected] |
Definition at line 74 of file LCEselection.h.
Referenced by LCE_SelectionSH::getPatchFitness(), and set_fit_model().
bool LCE_Selection_base::_is_local [protected] |
Definition at line 74 of file LCEselection.h.
Referenced by LCE_SelectionSH::getPatchFitness(), and set_fit_model().
double LCE_Selection_base::_letheq [protected] |
Definition at line 72 of file LCEselection.h.
Referenced by set_sel_model().
TMatrix* LCE_Selection_base::_local_optima [private] |
Definition at line 56 of file LCEselection.h.
Referenced by getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), getFitnessUnivariateGaussian(), getFitnessUnivariateGaussian_VE(), setSelectionMatrix(), and ~LCE_Selection_base().
double LCE_Selection_base::_max_fitness [protected] |
Definition at line 73 of file LCEselection.h.
Referenced by setParameters().
double LCE_Selection_base::_mean_fitness [protected] |
Definition at line 73 of file LCEselection.h.
Referenced by LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), LCE_SelectionSH::getMeanFitness(), setMeanFitness(), setMeans(), and setParameters().
unsigned int LCE_Selection_base::_nb_trait [protected] |
Definition at line 69 of file LCEselection.h.
Referenced by LCE_Breed_Selection::makeOffspringWithSelection(), and setParameters().
double* LCE_Selection_base::_phe [private] |
Definition at line 57 of file LCEselection.h.
Referenced by getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), getFitnessUnivariateGaussian(), getFitnessUnivariateGaussian_VE(), and ~LCE_Selection_base().
gsl_vector * LCE_Selection_base::_res1 [private] |
Definition at line 55 of file LCEselection.h.
Referenced by getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), setSelectionMatrix(), and ~LCE_Selection_base().
double LCE_Selection_base::_scaling_factor [protected] |
Definition at line 73 of file LCEselection.h.
Referenced by LCE_Breed_Selection_Disperse::breed_selection_disperse(), LCE_Breed_Selection::execute(), LCE_Breed_Selection_Disperse::execute(), getFitnessRelative(), LCE_Breed_Selection::makeOffspringWithSelection(), setParameters(), setScalingFactorAbsolute(), setScalingFactorGlobal(), and setScalingFactorLocal().
vector< TMatrix* > LCE_Selection_base::_selection_matrix [private] |
Definition at line 53 of file LCEselection.h.
Referenced by setSelectionMatrix(), and ~LCE_Selection_base().
vector< double > LCE_Selection_base::_selection_variance [protected] |
Definition at line 71 of file LCEselection.h.
Referenced by getFitnessUnivariateGaussian(), getFitnessUnivariateGaussian_VE(), and setSelectionMatrix().
int LCE_Selection_base::_selectTraitDimension [protected] |
Definition at line 70 of file LCEselection.h.
Referenced by getFitnessMultivariateGaussian(), getFitnessMultivariateGaussian_VE(), set_sel_model(), and setSelectionMatrix().
void(LCE_Selection_base::* LCE_Selection_base::_setScalingFactor)(age_t, unsigned int) [protected] |
Definition at line 82 of file LCEselection.h.
Referenced by execute(), and set_fit_model().
LCE_SelectionSH* LCE_Selection_base::_stater [protected] |
Definition at line 84 of file LCEselection.h.
Referenced by loadStatServices(), and ~LCE_Selection_base().
double LCE_Selection_base::_survival[5] [protected] |
Definition at line 76 of file LCEselection.h.
Referenced by LCE_SelectionSH::getSurvival(), LCE_Breed_Selection::makeOffspringWithSelection(), resetCounters(), and setMeans().
1.7.5.1 -- Nemo is hosted by