Nemo  2.4.0b
Simulate forward-in-time genetic evolution in a spatially explicit, individual-based stochastic simulator
LCE_PhenotypeExpression Class Reference

#include <LCEphenoexpression.h>

+ Inheritance diagram for LCE_PhenotypeExpression:
+ Collaboration diagram for LCE_PhenotypeExpression:

Public Member Functions

 LCE_PhenotypeExpression ()
 
virtual ~LCE_PhenotypeExpression ()
 
bool set_g_value_matrix (Param *param, TMatrix &mat)
 
bool check_g_index_matrix (Param *param, TMatrix &mat)
 
bool set_env_cue ()
 
void set_phenot_no_evol (unsigned int patch, TTQuanti *trait)
 
void set_phenot_g1_evol (unsigned int patch, TTQuanti *trait)
 
void set_phenot_g2_evol (unsigned int patch, TTQuanti *trait)
 
void set_phenot_g1_g2_evol (unsigned int patch, TTQuanti *trait)
 
double get_env_cue_no_noise (unsigned int patch, unsigned int trait)
 
double get_env_cue_noise (unsigned int patch, unsigned int trait)
 
virtual void execute ()
 
void setIndPhenotype (Patch *patch, sex_t SEX, age_idx AGE)
 
void setIndPhenotype_labile (Patch *patch, sex_t SEX, age_idx AGE)
 
void setIndLiability (Patch *patch, sex_t SEX, age_idx AGE)
 
void setIndLiability_evolving (Patch *patch, sex_t SEX, age_idx AGE)
 
void setIndLiability_sigmoid (Patch *patch, sex_t SEX, age_idx AGE)
 
void setIndLiability_evolving_sigmoid (Patch *patch, sex_t SEX, age_idx AGE)
 
virtual LifeCycleEventclone ()
 
virtual bool setParameters ()
 
virtual void loadFileServices (FileServices *loader)
 
virtual void loadStatServices (StatServices *loader)
 
virtual bool resetParameterFromSource (std::string param, SimComponent *cmpt)
 
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...
 

Private Attributes

unsigned int _num_trait
 Number of plastic phenotypes. More...
 
TMatrix _env_cue
 A matrix to hold the environmental cues (e value). More...
 
TMatrix _e_noise
 A matrix to hold the environmental noise (e reliability). More...
 
TMatrix _e_rate
 A matrix to hold the per generation rate of change of the environmental cues. More...
 
bool _e_copy_trait_optimum_value
 A flag to set whether environmental cue values are equal to and copied from the trait local optimum values from LCE_selection. More...
 
TMatrix _g0_linked_index
 
TMatrix _g1_linked_index
 
TMatrix _g2_linked_index
 
TMatrix _g1_values
 
TMatrix _g2_values
 
TMatrix _e_values
 
bool _g1_evolves
 
bool _g2_evolves
 
bool _do_change_cue
 
bool _is_labile
 
bool _has_plasticity
 
bool _has_liability
 
unsigned int _num_liability_trait
 
bool _has_evolving_threshold
 
TMatrix _liability_linked_index
 
TMatrix _liability_threshold_linked_index
 
vector< vector< double > > _liability_threshold
 
vector< vector< double > > _liability_values
 
bool _has_liability_sigmoid
 
TMatrix _liability_steepness_linked_index
 
vector< double > _liability_steepness_fixed
 
bool _liability_steepness_allow_negative
 
void(LCE_PhenotypeExpression::* _set_phenotype_func )(unsigned int, TTQuanti *)
 
double(LCE_PhenotypeExpression::* _get_env_cue_func )(unsigned int, unsigned int)
 
void(LCE_PhenotypeExpression::* _set_liability_func )(Patch *, sex_t, age_idx)
 
TProtoQuanti_QuantiProto
 A pointer to the plastic trait prototype. More...
 

Additional Inherited Members

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

Constructor & Destructor Documentation

◆ LCE_PhenotypeExpression()

LCE_PhenotypeExpression::LCE_PhenotypeExpression ( )
41  : LifeCycleEvent("phenotype_expression","quant"),
42  _num_trait(0),
44  _QuantiProto(0),
45  _g1_evolves(0),
46  _g2_evolves(0),
47  _do_change_cue(0),
48  _is_labile(0),
49  _has_plasticity(0),
50  _has_liability(0),
58  {
59 
61 
63  add_parameter("pheno_plastic_e_value", MAT, false, false, 0, 0, updater); // environmental cue for phenotype expression
64 
66  add_parameter("pheno_plastic_g0_quanti_trait", INT, false, false, 0, 0, updater); // link to quantitative trait (trait index)
67 
68  // non-mandatory parameters
69  add_parameter("pheno_plastic_e_is_selection_optimum_value", BOOL, false, false, 0, 0, updater);
70  add_parameter("pheno_plastic_e_rate_change", MAT, false, false,0,0,updater);
71  add_parameter("pheno_plastic_e_noise",MAT, false, false,0,0,updater);
72  add_parameter("pheno_plastic_is_labile", BOOL, false, false, 0, 0, 0); // FALSE - developmental plasticity
73 
74  // NOR - QUANTITATIVE TRAITS ----------------------------------------------------
75  add_parameter("pheno_plastic_g1_value", DBL, false, false, 0, 0, updater); // only with constant plasticity
76  add_parameter("pheno_plastic_g1_quanti_trait", INT, false, false, 0, 0, updater); // link to quantitative trait (trait index)
77  add_parameter("pheno_plastic_g2_value", DBL, false, false, 0, 0, updater); // only with evolving plasticity
78  add_parameter("pheno_plastic_g2_quanti_trait", INT, false, false, 0, 0, updater); // link to quantitative trait (trait index)
79 
80  // LIABILITY TRAITS ---------------------------------------------------------------
81  add_parameter("pheno_liability_quanti_trait", INT, false, false, 0, 0, updater);
82  add_parameter("pheno_liability_threshold", MAT, false, false, 0, 0, updater);
83  add_parameter("pheno_liability_values", MAT, false, false, 0, 0, updater);
84  add_parameter("pheno_liability_threshold_quanti_trait", INT, false, false, 0, 0, updater);
85  add_parameter("pheno_liability_steepness", MAT, false, false, 0, 0, updater);
86  add_parameter("pheno_liability_steepness_quanti_trait", INT, false, false, 0, 0, updater);
87  add_parameter("pheno_liability_steepness_negative", BOOL, false, false, 0, 0, updater);
88 
89  }
bool _liability_steepness_allow_negative
Definition: LCEphenoexpression.h:77
unsigned int _num_trait
Number of plastic phenotypes.
Definition: LCEphenoexpression.h:39
bool _has_plasticity
Definition: LCEphenoexpression.h:64
bool _has_evolving_threshold
Definition: LCEphenoexpression.h:68
bool _do_change_cue
Definition: LCEphenoexpression.h:62
void(LCE_PhenotypeExpression::* _set_phenotype_func)(unsigned int, TTQuanti *)
Definition: LCEphenoexpression.h:79
void(LCE_PhenotypeExpression::* _set_liability_func)(Patch *, sex_t, age_idx)
Definition: LCEphenoexpression.h:81
double(LCE_PhenotypeExpression::* _get_env_cue_func)(unsigned int, unsigned int)
Definition: LCEphenoexpression.h:80
bool _e_copy_trait_optimum_value
A flag to set whether environmental cue values are equal to and copied from the trait local optimum v...
Definition: LCEphenoexpression.h:51
bool set_env_cue()
Definition: LCEphenoexpression.cc:605
bool _has_liability_sigmoid
Definition: LCEphenoexpression.h:74
bool _has_liability
Definition: LCEphenoexpression.h:65
TProtoQuanti * _QuantiProto
A pointer to the plastic trait prototype.
Definition: LCEphenoexpression.h:84
unsigned int _num_liability_trait
Definition: LCEphenoexpression.h:67
bool _g2_evolves
Definition: LCEphenoexpression.h:61
virtual bool setParameters()
Definition: LCEphenoexpression.cc:97
bool _is_labile
Definition: LCEphenoexpression.h:63
bool _g1_evolves
Definition: LCEphenoexpression.h:60
LifeCycleEvent(const char *name, const char *trait_link)
Cstor.
Definition: lifecycleevent.h:98
Implementation of the ParamUpdaterBase interface.
Definition: param.h:363
virtual void add_parameter(Param *param)
Interface to add a parameter to the set.
Definition: simcomponent.h:112
@ DBL
Definition: types.h:78
@ MAT
Definition: types.h:78
@ BOOL
Definition: types.h:78
@ INT
Definition: types.h:78

References SimComponent::add_parameter(), BOOL, DBL, INT, MAT, set_env_cue(), and setParameters().

Referenced by clone().

◆ ~LCE_PhenotypeExpression()

virtual LCE_PhenotypeExpression::~LCE_PhenotypeExpression ( )
inlinevirtual
91 { }

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_PhenotypeExpression::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

127 {return 0;}

◆ check_g_index_matrix()

bool LCE_PhenotypeExpression::check_g_index_matrix ( Param param,
TMatrix mat 
)
591 {
592 
593  for(unsigned int t = 0; t < mat.length(); ++t) {
594  if( mat.get(0,t) > _QuantiProto->get_num_traits() || mat.get(0,t) < 1)
595  return error("phenotype_expression::quanti trait index %i provided in \"%s\" is not valid. It must be > 0 and not higher than the number of \"quanti_traits\".\n",
596  (unsigned int)mat.get(0,t), param->getName().c_str());
597  // the index must be zero-based => deduce 1 from input index values:
598  mat.minus(0, t, 1.0);
599  }
600  return true;
601 }
string getName()
Definition: param.h:137
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:193
void minus(unsigned int i, unsigned int j, double value)
Substracts a value from an element of the matrix.
Definition: tmatrix.h:273
unsigned int length() const
Returns the number of elements in the matrix.
Definition: tmatrix.h:218
unsigned int get_num_traits()
Definition: ttquanti.h:423
int error(const char *str,...)
Definition: output.cc:79

References _QuantiProto, error(), TMatrix::get(), TProtoQuanti::get_num_traits(), Param::getName(), TMatrix::length(), and TMatrix::minus().

Referenced by setParameters().

◆ clone()

virtual LifeCycleEvent* LCE_PhenotypeExpression::clone ( )
inlinevirtual

Implements LifeCycleEvent.

113 {return new LCE_PhenotypeExpression();}
LCE_PhenotypeExpression()
Definition: LCEphenoexpression.cc:41

References LCE_PhenotypeExpression().

◆ execute()

void LCE_PhenotypeExpression::execute ( )
virtual

Implements LifeCycleEvent.

624 {
625 
626  unsigned int stage_nb = _popPtr->getNumAgeClasses();
627 
628  age_idx age;
629 
630  Patch *patch;
631 
632  // =====================================================================
633  // PLASTICITY (NOR)
634  // =====================================================================
635 
636  if(_has_plasticity) {
637 
638  if(_popPtr->getCurrentGeneration() == 1){
639 
640  // reset the e values to their original values for a new replicate
641  set_env_cue();
642 
643  }
644 
646 
647  // set the cue _e_ equal to the local trait optima, which may change over time
648 
649  const TMatrix& trait_optima = dynamic_cast<LCE_Selection_base*>(SIMenv::MainSim->get_LCE("viability_selection"))->getLocalOptima();
650 
651  _env_cue.copy(trait_optima);
652 
653  } else
654 
655  if(_do_change_cue) {
656  // apply rate of change to the e values
657  for(unsigned int p = 0; p < _popPtr->getPatchNbr(); ++p) {
658  for(unsigned int t = 0; t < _num_trait; ++t) {
659  _env_cue.plus(p, t,_e_rate.get(p,t));
660  }
661  }
662  }
663 
664  if(_is_labile) {
665 
666  // (re)set the individuals' phenotypes in all age classes
667  // phenotypes are recalculated from genotypic values to avoid compounding
668  for(unsigned int p = 0; p < _popPtr->getPatchNbr(); ++p)
669  {
670  patch = _popPtr->getPatch(p);
671 
672  for(unsigned int s = 0; s < stage_nb; ++s)
673  {
674  age = age_idx(s);
675 
676  setIndPhenotype_labile (patch, FEM, age);
677 
678  setIndPhenotype_labile (patch, MAL, age);
679 
680  }
681  }
682  } else {
683  // Developmental plasticity
684  // set the phenotypes in the offspring only
685  for(unsigned int p = 0; p < _popPtr->getPatchNbr(); ++p)
686  {
687  patch = _popPtr->getPatch(p);
688 
689  setIndPhenotype (patch, FEM, OFFSx);
690 
691  setIndPhenotype (patch, MAL, OFFSx);
692 
693  }
694  }
695 
696  } // end _has_plasticity
697 
698  // =====================================================================
699  // LIABILITY TRAITS
700  // =====================================================================
701 
702  if(_has_liability) {
703 
704  if(_is_labile) {
705  // we want to re-calculate the phenotype when the underlying trait is labile
706  for(unsigned int p = 0; p < _popPtr->getPatchNbr(); ++p)
707  {
708  patch = _popPtr->getPatch(p);
709 
710  for(unsigned int s = 0; s < stage_nb; ++s)
711  {
712  age = age_idx(s);
713 
714  (this->*_set_liability_func)(patch, FEM, age);
715 
716  (this->*_set_liability_func)(patch, MAL, age);
717 
718  }
719  }
720  } else {
721  // Developmental: set liability phenotypes in offspring only
722  for(unsigned int p = 0; p < _popPtr->getPatchNbr(); ++p)
723  {
724  patch = _popPtr->getPatch(p);
725 
726  (this->*_set_liability_func)(patch, FEM, OFFSx);
727 
728  (this->*_set_liability_func)(patch, MAL, OFFSx);
729 
730  }
731  }
732 
733  } // end _has_liability
734 
735 }
LifeCycleEvent * get_LCE(string name)
Search for component with "name" in the life cycle events list.
Definition: basicsimulation.cc:76
TMatrix _env_cue
A matrix to hold the environmental cues (e value).
Definition: LCEphenoexpression.h:42
void setIndPhenotype(Patch *patch, sex_t SEX, age_idx AGE)
Definition: LCEphenoexpression.cc:739
void setIndPhenotype_labile(Patch *patch, sex_t SEX, age_idx AGE)
Definition: LCEphenoexpression.cc:755
TMatrix _e_rate
A matrix to hold the per generation rate of change of the environmental cues.
Definition: LCEphenoexpression.h:48
Base class performing (viability) selection on an arbitrary trait.
Definition: LCEselection.h:51
Metapop * _popPtr
The ptr to the current Metapop.
Definition: lifecycleevent.h:81
unsigned int getNumAgeClasses()
Definition: metapop.h:290
unsigned int getPatchNbr()
Definition: metapop.h:276
Patch * getPatch(unsigned int i)
Patch accessor, return the ith+1 patch in the metapop.
Definition: metapop.h:257
unsigned int getCurrentGeneration()
Definition: metapop.h:296
Second class in the metapopulation design structure, between the Metapop and Individual classes.
Definition: metapop.h:432
static SimRunner * MainSim
Definition: simenv.h:42
A class to handle matrix in params, coerces matrix into a vector of same total size.
Definition: tmatrix.h:50
void copy(const TMatrix &mat)
Copy a matrix.
Definition: tmatrix.h:78
void plus(unsigned int i, unsigned int j, double value)
Adds a value to an element of the matrix.
Definition: tmatrix.h:256
@ FEM
Definition: types.h:37
@ MAL
Definition: types.h:37
age_idx
Array index of the age classes in the patch sizes and containers arrays.
Definition: types.h:41
@ OFFSx
Definition: types.h:42

References _do_change_cue, _e_copy_trait_optimum_value, _e_rate, _env_cue, _has_liability, _has_plasticity, _is_labile, _num_trait, LifeCycleEvent::_popPtr, _set_liability_func, TMatrix::copy(), FEM, TMatrix::get(), ComponentManager::get_LCE(), Metapop::getCurrentGeneration(), Metapop::getNumAgeClasses(), Metapop::getPatch(), Metapop::getPatchNbr(), SIMenv::MainSim, MAL, OFFSx, TMatrix::plus(), set_env_cue(), setIndPhenotype(), and setIndPhenotype_labile().

◆ get_env_cue_no_noise()

double LCE_PhenotypeExpression::get_env_cue_no_noise ( unsigned int  patch,
unsigned int  trait 
)
776 {
777  return _env_cue.get(patch, trait);
778 }

References _env_cue, and TMatrix::get().

Referenced by setParameters().

◆ get_env_cue_noise()

double LCE_PhenotypeExpression::get_env_cue_noise ( unsigned int  patch,
unsigned int  trait 
)
783 {
784  return _env_cue.get(patch, trait) + RAND::Gaussian(_e_noise.get(patch, trait));
785 }
TMatrix _e_noise
A matrix to hold the environmental noise (e reliability).
Definition: LCEphenoexpression.h:45
static double Gaussian(double sigma)
Definition: Uniform.h:264

References _e_noise, _env_cue, RAND::Gaussian(), and TMatrix::get().

Referenced by setParameters().

◆ loadFileServices()

virtual void LCE_PhenotypeExpression::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

119 {}

◆ loadStatServices()

virtual void LCE_PhenotypeExpression::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

121 {}

◆ removeAgeClass()

virtual age_t LCE_PhenotypeExpression::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

125 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_PhenotypeExpression::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

129 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

123 {return false;}

◆ set_env_cue()

bool LCE_PhenotypeExpression::set_env_cue ( )
606 {
607  TMatrix tmp_mat;
608 
610 
611  _paramSet->getMatrix("pheno_plastic_e_value", &tmp_mat);
612 
613  if( !setSpatialMatrix("pheno_plastic_e_value", "\"pheno_plastic_traits\"", &tmp_mat, &_env_cue,
614  (unsigned)_num_trait, _popPtr->getPatchNbr(), false) )
615  return false;
616 
617  return true;
618 }
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:304
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:48
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:161
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
Definition: utils.cc:115

References _env_cue, _num_trait, SimComponent::_paramSet, LifeCycleEvent::_popPtr, ParamSet::getMatrix(), Metapop::getPatchNbr(), TMatrix::reset(), and setSpatialMatrix().

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

◆ set_g_value_matrix()

bool LCE_PhenotypeExpression::set_g_value_matrix ( Param param,
TMatrix mat 
)
569 {
570  if( param->isMatrix() ) {
571 
572  param->getMatrix(&mat);
573 
574  if(mat.nrows() > 1)
575  return error("phenotype_expression::the array of trait indices for parameter \"%s\" should have one row only\n.", param->getName().c_str());
576 
577  if(mat.ncols() > _QuantiProto->get_num_traits())
578  return error("phenotype_expression::the number of trait indices in \"%s\" is larger than the number of quantitative traits.\n", param->getName().c_str());
579  }
580  else
581  {
582  mat.reset(1,1, param->getValue());
583  }
584 
585  return true;
586 }
double getValue()
Returns the argument value according to its type.
Definition: param.cc:368
bool isMatrix()
Checks if the argument is of matrix type.
Definition: param.h:172
void getMatrix(TMatrix *mat)
Sets the matrix from the argument string if the parameter is set and of matrix type.
Definition: param.cc:378
unsigned int ncols() const
Definition: tmatrix.h:216
unsigned int nrows() const
Definition: tmatrix.h:213

References _QuantiProto, error(), TProtoQuanti::get_num_traits(), Param::getMatrix(), Param::getName(), Param::getValue(), Param::isMatrix(), TMatrix::ncols(), TMatrix::nrows(), and TMatrix::reset().

Referenced by setParameters().

◆ set_phenot_g1_evol()

void LCE_PhenotypeExpression::set_phenot_g1_evol ( unsigned int  patch,
TTQuanti trait 
)
803 {
804  double pheno = 0;
805  for(unsigned int t = 0, ID0, ID1; t < _num_trait; ++t) {
806  ID0 = _g0_linked_index.get(0,t);
807  ID1 = _g1_linked_index.get(0,t);
808  pheno = trait->get_phenotype(ID0) + trait->get_phenotype(ID1) *
809  ( (this->*_get_env_cue_func)(patch, t) - _g2_values.get(0, t) );
810  trait->set_phenotype(ID0, pheno);
811  }
812 }
TMatrix _g1_linked_index
Definition: LCEphenoexpression.h:54
TMatrix _g2_values
Definition: LCEphenoexpression.h:58
TMatrix _g0_linked_index
Definition: LCEphenoexpression.h:53
void set_phenotype(unsigned int trait, double value)
Definition: ttquanti.cc:3154
double get_phenotype(unsigned int trai)
Definition: ttquanti.cc:3145

References _g0_linked_index, _g1_linked_index, _g2_values, _get_env_cue_func, _num_trait, TMatrix::get(), TTQuanti::get_phenotype(), and TTQuanti::set_phenotype().

Referenced by setParameters().

◆ set_phenot_g1_g2_evol()

void LCE_PhenotypeExpression::set_phenot_g1_g2_evol ( unsigned int  patch,
TTQuanti trait 
)
831 {
832  double pheno = 0;
833  for(unsigned int t = 0, ID0, ID1, ID2; t < _num_trait; ++t) {
834  ID0 = _g0_linked_index.get(0,t);
835  ID1 = _g1_linked_index.get(0,t);
836  ID2 = _g2_linked_index.get(0,t);
837  pheno = trait->get_phenotype(ID0) + trait->get_phenotype(ID1) *
838  ( (this->*_get_env_cue_func)(patch, t) - trait->get_phenotype(ID2) );
839  trait->set_phenotype(ID0, pheno);
840  }
841 }
TMatrix _g2_linked_index
Definition: LCEphenoexpression.h:55

References _g0_linked_index, _g1_linked_index, _g2_linked_index, _get_env_cue_func, _num_trait, TMatrix::get(), TTQuanti::get_phenotype(), and TTQuanti::set_phenotype().

Referenced by setParameters().

◆ set_phenot_g2_evol()

void LCE_PhenotypeExpression::set_phenot_g2_evol ( unsigned int  patch,
TTQuanti trait 
)
817 {
818  double pheno = 0;
819  for(unsigned int t = 0, ID0, ID2; t < _num_trait; ++t) {
820  ID0 = _g0_linked_index.get(0,t);
821  ID2 = _g2_linked_index.get(0,t);
822  pheno = trait->get_phenotype(ID0) + _g1_values.get(0, t) *
823  ( (this->*_get_env_cue_func)(patch, t) - trait->get_phenotype(ID2) );
824  trait->set_phenotype(ID0, pheno);
825  }
826 }
TMatrix _g1_values
Definition: LCEphenoexpression.h:57

References _g0_linked_index, _g1_values, _g2_linked_index, _get_env_cue_func, _num_trait, TMatrix::get(), TTQuanti::get_phenotype(), and TTQuanti::set_phenotype().

Referenced by setParameters().

◆ set_phenot_no_evol()

void LCE_PhenotypeExpression::set_phenot_no_evol ( unsigned int  patch,
TTQuanti trait 
)
790 {
791  double pheno = 0;
792  for(unsigned int t = 0, ID0; t < _num_trait; ++t) {
793  ID0 = _g0_linked_index.get(0,t);
794  pheno = trait->get_phenotype(ID0) + _g1_values.get(0, t) *
795  ( (this->*_get_env_cue_func)(patch, t) - _g2_values.get(0, t) );
796  trait->set_phenotype(ID0, pheno);
797  }
798 }

References _g0_linked_index, _g1_values, _g2_values, _get_env_cue_func, _num_trait, TMatrix::get(), TTQuanti::get_phenotype(), and TTQuanti::set_phenotype().

Referenced by setParameters().

◆ setIndLiability()

void LCE_PhenotypeExpression::setIndLiability ( Patch patch,
sex_t  SEX,
age_idx  AGE 
)
846 {
847  TTQuanti *trait;
848  unsigned int ID, num_thresh, cls;
849  double liability;
850 
851  for(unsigned int i = 0; i < patch->size(SEX, AGE); ++i)
852  {
853  trait = dynamic_cast<TTQuanti*> (patch->get(SEX, AGE, i)->getTrait(_LCELinkedTraitIndex));
854 
855  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
856 
857  ID = _liability_linked_index.get(0, t);
858  liability = trait->get_phenotype(ID);
859 
860  // find which class the liability falls into
861  num_thresh = _liability_threshold[t].size();
862  cls = num_thresh; // default: above all thresholds
863 
864  for(unsigned int k = 0; k < num_thresh; ++k) {
865  if(liability < _liability_threshold[t][k]) {
866  cls = k;
867  break;
868  }
869  }
870 
871  trait->set_phenotype(ID, _liability_values[t][cls]);
872  }
873  }
874 }
TTrait * getTrait(IDX T)
Trait accessor.
Definition: individual.h:277
vector< vector< double > > _liability_values
Definition: LCEphenoexpression.h:72
vector< vector< double > > _liability_threshold
Definition: LCEphenoexpression.h:71
TMatrix _liability_linked_index
Definition: LCEphenoexpression.h:69
int _LCELinkedTraitIndex
The index in the individual's trait table of the linked trait.
Definition: lifecycleevent.h:89
unsigned int size(age_t AGE)
Returns the size of the container of the appropriate age class(es) for both sexes.
Definition: metapop.h:498
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:534
TTQuanti.
Definition: ttquanti.h:61

References LifeCycleEvent::_LCELinkedTraitIndex, _liability_linked_index, _liability_threshold, _liability_values, _num_liability_trait, Patch::get(), TMatrix::get(), TTQuanti::get_phenotype(), Individual::getTrait(), TTQuanti::set_phenotype(), and Patch::size().

Referenced by setParameters().

◆ setIndLiability_evolving()

void LCE_PhenotypeExpression::setIndLiability_evolving ( Patch patch,
sex_t  SEX,
age_idx  AGE 
)
938 {
939  TTQuanti *trait;
940  unsigned int ID, num_thresh, cls;
941  int threshIdx;
942  double liability, threshold, val0, val1;
943 
944  for(unsigned int i = 0; i < patch->size(SEX, AGE); ++i)
945  {
946  trait = dynamic_cast<TTQuanti*> (patch->get(SEX, AGE, i)->getTrait(_LCELinkedTraitIndex));
947 
948  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
949 
950  ID = _liability_linked_index.get(0, t);
951  liability = trait->get_phenotype(ID);
952  threshIdx = (int)_liability_threshold_linked_index.get(0, t);
953 
954  if(threshIdx >= 0) {
955  // evolving: single threshold from quanti trait phenotype
956  threshold = trait->get_phenotype((unsigned int)threshIdx);
957  val0 = _liability_values[t][0];
958  val1 = _liability_values[t][1];
959  // no sigmoid: hard step
960  cls = (liability < threshold) ? 0 : 1;
961  trait->set_phenotype(ID, _liability_values[t][cls]);
962 
963  } else {
964  // fixed: multi-threshold from variable vector
965  num_thresh = _liability_threshold[t].size();
966  cls = num_thresh;
967  for(unsigned int k = 0; k < num_thresh; ++k) {
968  if(liability < _liability_threshold[t][k]) {
969  cls = k;
970  break;
971  }
972  }
973  trait->set_phenotype(ID, _liability_values[t][cls]);
974  }
975  }
976  }
977 }
TMatrix _liability_threshold_linked_index
Definition: LCEphenoexpression.h:70

References LifeCycleEvent::_LCELinkedTraitIndex, _liability_linked_index, _liability_threshold, _liability_threshold_linked_index, _liability_values, _num_liability_trait, Patch::get(), TMatrix::get(), TTQuanti::get_phenotype(), Individual::getTrait(), TTQuanti::set_phenotype(), and Patch::size().

Referenced by setParameters().

◆ setIndLiability_evolving_sigmoid()

void LCE_PhenotypeExpression::setIndLiability_evolving_sigmoid ( Patch patch,
sex_t  SEX,
age_idx  AGE 
)
982 {
983  TTQuanti *trait;
984  unsigned int ID, num_thresh, cls;
985  int threshIdx, steepIdx;
986  double liability, threshold, val0, val1, steepness, sigmoid;
987 
988  for(unsigned int i = 0; i < patch->size(SEX, AGE); ++i)
989  {
990  trait = dynamic_cast<TTQuanti*> (patch->get(SEX, AGE, i)->getTrait(_LCELinkedTraitIndex));
991 
992  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
993 
994  ID = _liability_linked_index.get(0, t);
995  liability = trait->get_phenotype(ID);
996  threshIdx = (int)_liability_threshold_linked_index.get(0, t);
997 
998  if(threshIdx >= 0) {
999  // evolving: single threshold from quanti trait phenotype
1000  threshold = trait->get_phenotype((unsigned int)threshIdx);
1001  val0 = _liability_values[t][0];
1002  val1 = _liability_values[t][1];
1003  steepIdx = (int)_liability_steepness_linked_index.get(0, t);
1004 
1005  if(steepIdx >= 0) {
1006  // evolving steepness from quanti trait
1007  steepness = trait->get_phenotype((unsigned int)steepIdx);
1008  if(!_liability_steepness_allow_negative && steepness < 0) steepness = 0;
1009  sigmoid = 1.0 / (1.0 + exp(-steepness * (liability - threshold)));
1010  trait->set_phenotype(ID, val0 + (val1 - val0) * sigmoid);
1011 
1012  } else if(steepIdx == -1) {
1013  // fixed steepness
1014  steepness = _liability_steepness_fixed[t];
1015  sigmoid = 1.0 / (1.0 + exp(-steepness * (liability - threshold)));
1016  trait->set_phenotype(ID, val0 + (val1 - val0) * sigmoid);
1017 
1018  } else {
1019  // no sigmoid (steepIdx == -2): hard step (backward compatible)
1020  cls = (liability < threshold) ? 0 : 1;
1021  trait->set_phenotype(ID, _liability_values[t][cls]);
1022  }
1023  } else {
1024  // fixed: multi-threshold from variable vector
1025  num_thresh = _liability_threshold[t].size();
1026  cls = num_thresh;
1027  for(unsigned int k = 0; k < num_thresh; ++k) {
1028  if(liability < _liability_threshold[t][k]) {
1029  cls = k;
1030  break;
1031  }
1032  }
1033  trait->set_phenotype(ID, _liability_values[t][cls]);
1034  }
1035  }
1036  }
1037 }
TMatrix _liability_steepness_linked_index
Definition: LCEphenoexpression.h:75
vector< double > _liability_steepness_fixed
Definition: LCEphenoexpression.h:76

References LifeCycleEvent::_LCELinkedTraitIndex, _liability_linked_index, _liability_steepness_allow_negative, _liability_steepness_fixed, _liability_steepness_linked_index, _liability_threshold, _liability_threshold_linked_index, _liability_values, _num_liability_trait, Patch::get(), TMatrix::get(), TTQuanti::get_phenotype(), Individual::getTrait(), TTQuanti::set_phenotype(), and Patch::size().

Referenced by setParameters().

◆ setIndLiability_sigmoid()

void LCE_PhenotypeExpression::setIndLiability_sigmoid ( Patch patch,
sex_t  SEX,
age_idx  AGE 
)
879 {
880  TTQuanti *trait;
881  unsigned int ID, num_thresh, cls;
882  double liability, val0, val1, threshold, steepness, sigmoid;
883  int steepIdx;
884 
885  for(unsigned int i = 0; i < patch->size(SEX, AGE); ++i)
886  {
887  trait = dynamic_cast<TTQuanti*> (patch->get(SEX, AGE, i)->getTrait(_LCELinkedTraitIndex));
888 
889  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
890 
891  ID = _liability_linked_index.get(0, t);
892  liability = trait->get_phenotype(ID);
893  val0 = _liability_values[t][0];
894  val1 = _liability_values[t][1];
895  steepIdx = (int)_liability_steepness_linked_index.get(0, t); //in case steepness evolves
896  threshold = _liability_threshold[t][0];
897 
898  if(steepIdx >= 0) {
899  // evolving steepness from quanti trait, non-evolving threshold
900  steepness = trait->get_phenotype((unsigned int)steepIdx);
901 
902  if(!_liability_steepness_allow_negative && steepness < 0)
903  steepness = 0;
904 
905  sigmoid = 1.0 / (1.0 + exp(-steepness * (liability - threshold)));
906 
907  trait->set_phenotype(ID, val0 + (val1 - val0) * sigmoid);
908 
909  } else if(steepIdx == -1) {
910  // fixed steepness
911  steepness = _liability_steepness_fixed[t];
912  sigmoid = 1.0 / (1.0 + exp(-steepness * (liability - threshold)));
913 
914  trait->set_phenotype(ID, val0 + (val1 - val0) * sigmoid);
915 
916  } else {
917  // no evolving trait, no sigmoid (steepIdx == -2): hard step(s)
918  // since threshold is not evolving, multiple thresholds may exist
919  // find which class the liability falls into
920  num_thresh = _liability_threshold[t].size();
921  cls = num_thresh; // default: above all thresholds
922 
923  for(unsigned int k = 0; k < num_thresh; ++k) {
924  if(liability < _liability_threshold[t][k]) {
925  cls = k;
926  break;
927  }
928  }
929  trait->set_phenotype(ID, _liability_values[t][cls]);
930  } // END_no sigmoid
931  } // END_for all traits
932  } // END_for all individuals
933 }

References LifeCycleEvent::_LCELinkedTraitIndex, _liability_linked_index, _liability_steepness_allow_negative, _liability_steepness_fixed, _liability_steepness_linked_index, _liability_threshold, _liability_values, _num_liability_trait, Patch::get(), TMatrix::get(), TTQuanti::get_phenotype(), Individual::getTrait(), TTQuanti::set_phenotype(), and Patch::size().

Referenced by setParameters().

◆ setIndPhenotype()

void LCE_PhenotypeExpression::setIndPhenotype ( Patch patch,
sex_t  SEX,
age_idx  AGE 
)
740 {
741  TTQuanti *trait;
742 
743  for(unsigned int i = 0; i < patch->size(SEX, AGE); ++i)
744  {
745 
746  trait = dynamic_cast<TTQuanti*> (patch->get(SEX, AGE, i)->getTrait(_LCELinkedTraitIndex));
747 
748  (this->*_set_phenotype_func)(patch->getID(), trait);
749 
750  }
751 }
unsigned int getID()
Definition: metapop.h:481

References LifeCycleEvent::_LCELinkedTraitIndex, _set_phenotype_func, Patch::get(), Patch::getID(), Individual::getTrait(), and Patch::size().

Referenced by execute().

◆ setIndPhenotype_labile()

void LCE_PhenotypeExpression::setIndPhenotype_labile ( Patch patch,
sex_t  SEX,
age_idx  AGE 
)
756 {
757  TTQuanti *trait;
758 
759  for(unsigned int i = 0; i < patch->size(SEX, AGE); ++i)
760  {
761 
762  trait = dynamic_cast<TTQuanti*> (patch->get(SEX, AGE, i)->getTrait(_LCELinkedTraitIndex));
763 
764  // reset phenotypes to genotypic values before applying the NOR
765  // this prevents compounding of the plasticity effect across generations
767 
768  (this->*_set_phenotype_func)(patch->getID(), trait);
769 
770  }
771 }
void reset_phenotype_to_genotypic_value()
Definition: ttquanti.cc:3137

References LifeCycleEvent::_LCELinkedTraitIndex, _set_phenotype_func, Patch::get(), Patch::getID(), Individual::getTrait(), TTQuanti::reset_phenotype_to_genotypic_value(), and Patch::size().

Referenced by execute().

◆ setParameters()

bool LCE_PhenotypeExpression::setParameters ( )
virtual

Implements SimComponent.

99 {
100 
101  _QuantiProto = dynamic_cast<TProtoQuanti*> ( _popPtr->getTraitPrototype("quant"));
102 
103  // =====================================================================
104  // PLASTICITY (NOR)
105  // =====================================================================
106 
107  _has_plasticity = _paramSet->isSet("pheno_plastic_g0_quanti_trait");
108 
109  if(_has_plasticity) {
110 
111  if(!_paramSet->isSet("pheno_plastic_e_value"))
112  return error("phenotype_expression::\"pheno_plastic_e_value\" is required when plastic traits are defined.\n");
113 
114  // ...........................................................................
115  // dimension of the NOR, how many g0's?
116  if(!set_g_value_matrix(_paramSet->get_param("pheno_plastic_g0_quanti_trait") , _g0_linked_index))
117  return false;
118 
119  if(!check_g_index_matrix(_paramSet->get_param("pheno_plastic_g0_quanti_trait") , _g0_linked_index))
120  return false;
121 
123 
124  // check if g1 evolves:
125  if(_paramSet->isSet("pheno_plastic_g1_quanti_trait")) {
126 
127  if(!set_g_value_matrix(_paramSet->get_param("pheno_plastic_g1_quanti_trait") , _g1_linked_index)) {
128  return false;
129 
130  } else {
131 
132  if(!check_g_index_matrix(_paramSet->get_param("pheno_plastic_g1_quanti_trait") , _g1_linked_index))
133  return false;
134 
135  _g1_evolves = true;
136  }
137 
139  return error("phenotype_expression::the number of evolving n-o-r (g1) should be equal to the number of g0 linked traits.\n");
140 
141  } else {
142  _g1_evolves = false;
143  }
144 
145  // check if g2 evolves;
146  if(_paramSet->isSet("pheno_plastic_g2_quanti_trait")) {
147  if(!set_g_value_matrix(_paramSet->get_param("pheno_plastic_g2_quanti_trait") , _g2_linked_index)) {
148 
149  return false;
150 
151  } else {
152 
153  if(!check_g_index_matrix(_paramSet->get_param("pheno_plastic_g2_quanti_trait") , _g2_linked_index))
154  return false;
155 
156  _g2_evolves = true;
157  }
158 
160  return error("phenotype_expression::the number of evolving g2-values should be equal to the number of g0 linked traits.\n");
161 
162  } else {
163  _g2_evolves = false;
164  }
165 
167  // G!
168  if(_paramSet->isSet("pheno_plastic_g1_value")) {
169 
170  if(_g1_evolves)
171 
172  warning("phenotype_expression::parameter \"pheno_plastic_g1_value\" is set but g1 evolves. Fixed g1 values will be ignored.\n");
173 
174  else {
175 
176  if(!set_g_value_matrix(_paramSet->get_param("pheno_plastic_g1_value"), _g1_values))
177  return false;
178 
179  if(_g1_values.length() != _num_trait)
180  return error("phenotype_expression::the number of slope values (g1) should be equal to the number of g0 linked traits.\n");
181  }
182  }
183  else
184  if(!_g1_evolves) {
185 
186  return error("phenotype_expression::the slope values (g1) of the modelled n-o-r are missing.\n");
187 
188  }
189 
190  // G2
191  if(_paramSet->isSet("pheno_plastic_g2_value")) {
192 
193  if(_g2_evolves)
194 
195  warning("phenotype_expression::parameter \"pheno_plastic_g2_value\" is set but g2 evolves. Fixed g2 values will be ignored.\n");
196 
197  else {
198 
199  if(!set_g_value_matrix(_paramSet->get_param("pheno_plastic_g2_value"), _g2_values))
200  return false;
201 
202  if(_g2_values.length() != _num_trait)
203  return error("phenotype_expression::the number of reference values (g2) should be equal to the number of g0 linked traits.\n");
204  }
205  }
206  else
207  if(!_g2_evolves) {
208 
209  warning("phenotype_expression::reference values (g2) of the n-o-r modeled are set to 0 by default.\n");
210 
211  _g2_values.reset(1, _num_trait, 0.0);
212  }
213 
214  if(_g1_evolves) {
215 
216  if(_g2_evolves)
218  else
220 
221  } else if(_g2_evolves) {
222 
224 
225  } else
227 
228 
229  TMatrix tmp_mat;
230 
231  // ...........................................................................
232  // plastic_e_value - the environmental cue(s) "e" relevant for phenotype expression
233 
234  if(!set_env_cue()) return false;
235 
236  // ...........................................................................
237  // plastic_e_value_noise - the reliability of the environmental cue(s) "e"
238  if(get_parameter("pheno_plastic_e_noise")->isSet() ){
239 
241 
242  _paramSet->getMatrix("pheno_plastic_e_noise", &tmp_mat);
243 
244  if( !setSpatialMatrix("pheno_plastic_e_noise", "\"pheno_plastic_traits\"", &tmp_mat, &_e_noise,
245  (unsigned)_num_trait, _popPtr->getPatchNbr(), false) )
246  return false;
247 
249 
250  } else {
251 
253 
255  }
256 
257  // ...........................................................................
258  // plastic_e_value_change_rate - the rate of change for the environmental cue(s) "e"
259  if(get_parameter("pheno_plastic_e_rate_change")->isSet() ){
260 
261  _e_rate.reset(_popPtr->getPatchNbr(), (unsigned)_num_trait);
262 
263  _paramSet->getMatrix("pheno_plastic_e_rate_change", &tmp_mat);
264 
265  if( !setSpatialMatrix("pheno_plastic_e_rate_change", "\"pheno_plastic_traits\"", &tmp_mat, &_e_rate,
266  (unsigned)_num_trait, _popPtr->getPatchNbr(), false) )
267  return false;
268 
269  _do_change_cue = true;
270 
271  } else {
272 
273  _e_rate.reset(_popPtr->getPatchNbr(), (unsigned)_num_trait, 0.0);
274 
275  _do_change_cue = false;
276  }
277 
278  // set matrix of environmental gains ..................................................
279  // to keep track of the change of environmental cues
280 
281  if(get_parameter("pheno_plastic_e_is_selection_optimum_value")->isSet()) {
282 
283  _e_copy_trait_optimum_value = get_parameter_value("pheno_plastic_e_is_selection_optimum_value");
284 
285  } else {
287  }
288 
289  } // end _has_plasticity
290 
291  // =====================================================================
292  // LIABILITY TRAITS
293  // =====================================================================
294 
295  _has_liability = _paramSet->isSet("pheno_liability_quanti_trait");
296 
297  if(_has_liability) {
298 
299  // check that traits are not assigned multiple times to liability, threshold or steepness
300  std::unordered_set<int> trait_seen;
301 
302  // trait indices
303  if(!set_g_value_matrix(_paramSet->get_param("pheno_liability_quanti_trait"), _liability_linked_index))
304  return false;
305 
306  if(!check_g_index_matrix(_paramSet->get_param("pheno_liability_quanti_trait"), _liability_linked_index))
307  return false;
308 
310 
311  // check for duplicates in trait assignments
312  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
313  if(!trait_seen.insert(_liability_linked_index.get(0, t)).second) // the index is already 0-based
314  return error("phenotype_expression::quanti trait index %i is already assigned to a liability trait.\n",
315  (unsigned int)(_liability_linked_index.get(0,t)+1.0));
316  }
317 
318  // ---- EVOLVING THRESHOLDS ----
319  _has_evolving_threshold = false;
320 
321  if(_paramSet->isSet("pheno_liability_threshold_quanti_trait")) {
322 
323  if(!set_g_value_matrix(_paramSet->get_param("pheno_liability_threshold_quanti_trait"),
325  return false;
326 
327  // we don't check the index here because we allow for value 0 as "not evolving threshold"
328 
330  return error("phenotype_expression::number of entries in \"pheno_liability_threshold_quanti_trait\" (%i) != number of liability traits (%i).\n",
332 
333  // validate & convert: 0 -> -1 (fixed), >0 -> 0-based index
334  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
335  double val = _liability_threshold_linked_index.get(0, t);
336  if(val < 0)
337  return error("phenotype_expression::negative entry in \"pheno_liability_threshold_quanti_trait\".\n");
338  if(val == 0) {
340  } else {
341 
342  if((unsigned int)val > _QuantiProto->get_num_traits())
343  return error("phenotype_expression::invalid quanti trait index %i in \"pheno_liability_threshold_quanti_trait\".\n", (unsigned int)val);
344 
345  // check that the trait index is unique
346  if (!trait_seen.insert(val - 1.0).second)
347  return error("phenotype_expression::quanti trait index %i in \"pheno_liability_threshold_quanti_trait\" "
348  "is already assigned to a liability or threshold trait.\n", (unsigned int)val);
349 
350  _liability_threshold_linked_index.set(0, t, val - 1.0); // 0-based
352  }
353  }
354  }
355 
356  // ---- FIXED THRESHOLDS (variable matrix) ----
357  // we allow the parameter pheno_liability_threshold to receive a matrix with empty rows for the evolving thresholds
358  bool needs_fixed_threshold = false;
360  needs_fixed_threshold = true;
361  } else {
362  for(unsigned int t = 0; t < _num_liability_trait; ++t)
363  if(_liability_threshold_linked_index.get(0, t) < 0) { needs_fixed_threshold = true; break; }
364  }
365 
366  if(needs_fixed_threshold) {
367  if(!_paramSet->isSet("pheno_liability_threshold"))
368  return error("phenotype_expression::\"pheno_liability_threshold\" is required when fixed-threshold liability traits exist.\n");
369  }
370 
371  if(_paramSet->isSet("pheno_liability_threshold")) {
372  _paramSet->get_param("pheno_liability_threshold")->getVariableMatrix(&_liability_threshold);
373 
375  return error("phenotype_expression::rows in \"pheno_liability_threshold\" (%i) != number of liability traits (%i).\n",
377 
378  // validate ascending order per trait
379  for(unsigned int t = 0; t < _num_liability_trait; ++t)
380  for(unsigned int k = 1; k < _liability_threshold[t].size(); ++k)
381  if(_liability_threshold[t][k] <= _liability_threshold[t][k-1])
382  return error("phenotype_expression::thresholds for liability trait %i are not in strictly ascending order.\n", t+1);
383 
384  } else {
385  // no fixed thresholds needed (all evolving): init empty rows
387  }
388 
389  // validate evolving-threshold traits have empty threshold rows
391  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
392  if(_liability_threshold_linked_index.get(0, t) >= 0 && _liability_threshold[t].size() != 0)
393  return error("phenotype_expression::liability trait %i uses evolving threshold but has fixed thresholds in \"pheno_liability_threshold\".\n", t+1);
394  }
395  }
396 
397  // ---- PHENOTYPE VALUES (variable matrix) ----
398  if(!_paramSet->isSet("pheno_liability_values"))
399  return error("phenotype_expression::\"pheno_liability_values\" is required when liability traits are defined.\n");
400 
401  _paramSet->get_param("pheno_liability_values")->getVariableMatrix(&_liability_values);
402 
404  return error("phenotype_expression::rows in \"pheno_liability_values\" (%i) != number of liability traits (%i).\n",
406 
407  // per-trait validation: values.size == thresholds.size + 1
408  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
409  unsigned int expected_nvals;
411  expected_nvals = 2; // evolving: single threshold, 2 values
412  else
413  expected_nvals = _liability_threshold[t].size() + 1;
414 
415  if(_liability_values[t].size() != expected_nvals)
416  return error("phenotype_expression::liability trait %i has %i values but expected %i.\n",
417  t+1, (int)_liability_values[t].size(), expected_nvals);
418  }
419 
420  // ---- debug
421 #ifdef _DEBUG_
422  for(unsigned int i=0; i < _liability_linked_index.length(); ++i) {
423  cout << "---- LIABILITY TRAIT: "<< _liability_linked_index.get(0,i)+1 << "\n"
424  << " "<<_liability_threshold[i].size()<< " threshold values";
425  if(_liability_threshold[i].size() != 0) {
426  cout << ": ";
427  for(unsigned int j=0; j < _liability_threshold[i].size(); ++j)
428  cout << _liability_threshold[i][j]<<" ";
429  }
430  cout << "\n";
431  cout << " "<<_liability_values[i].size() << " phenotype values";
432  if(_liability_values[i].size() != 0) {
433  cout << ": ";
434  for(unsigned int j=0; j < _liability_values[i].size(); ++j)
435  cout << _liability_values[i][j]<<" ";
436  }
437  cout << "\n";
438  }
439 #endif
440 
441  // ---- SIGMOIDAL (LOGISTIC) STEEPNESS ----
442  _has_liability_sigmoid = false;
445 
446  if(_paramSet->isSet("pheno_liability_steepness_negative"))
447  _liability_steepness_allow_negative = (bool)_paramSet->getValue("pheno_liability_steepness_negative");
448  else
450 
451  // evolving steepness from quanti trait
452  if(_paramSet->isSet("pheno_liability_steepness_quanti_trait")) {
453 
454  TMatrix steepIdx_mat;
455  if(!set_g_value_matrix(_paramSet->get_param("pheno_liability_steepness_quanti_trait"), steepIdx_mat))
456  return false;
457 
458  if(steepIdx_mat.length() != _num_liability_trait)
459  return error("phenotype_expression::number of entries in \"pheno_liability_steepness_quanti_trait\" (%i) != number of liability traits (%i).\n",
460  steepIdx_mat.length(), _num_liability_trait);
461 
462 
463  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
464  double val = steepIdx_mat.get(0, t);
465  if(val < 0)
466  return error("phenotype_expression::negative entry in \"pheno_liability_steepness_quanti_trait\".\n");
467  if(val == 0) continue; // no sigmoid for this trait
468 
469  if((unsigned int)val > _QuantiProto->get_num_traits())
470  return error("phenotype_expression::invalid quanti trait index %i in \"pheno_liability_steepness_quanti_trait\".\n", (unsigned int)val);
471 
472  // check that the trait index is unique
473  if (!trait_seen.insert(val - 1.0).second)
474  return error("phenotype_expression::quanti trait index %i in \"pheno_liability_steepness_quanti_trait\" "
475  "is already assigned to a liability, threshold or steepness trait.\n", (unsigned int)val);
476 
477  // check that the threshold and values are correctly set, for non-evolving threshold
478  // we expect one threshold value and two liability values
480 
481  if(_liability_threshold[t].size() != 1)
482  return error("phenotype_expression::liability trait %i has %i threshold(s) but expected %i.\n",
483  t+1, (int)_liability_threshold[t].size(), 1);
484 
485  if(_liability_values[t].size() != 2)
486  return error("phenotype_expression::liability trait %i has %i values but expected %i.\n",
487  t+1, (int)_liability_values[t].size(), 2);
488  }
489 
490  _liability_steepness_linked_index.set(0, t, val - 1.0); // 0-based
491  _has_liability_sigmoid = true;
492  }
493  }
494 
495  // fixed steepness
496  if(_paramSet->isSet("pheno_liability_steepness")) {
497 
498  TMatrix steepVal_mat;
499  if(!set_g_value_matrix(_paramSet->get_param("pheno_liability_steepness"), steepVal_mat))
500  return false;
501 
502  if(steepVal_mat.length() != _num_liability_trait)
503  return error("phenotype_expression::number of entries in \"pheno_liability_steepness\" (%i) != number of liability traits (%i).\n",
504  steepVal_mat.length(), _num_liability_trait);
505 
506  for(unsigned int t = 0; t < _num_liability_trait; ++t) {
507 
508  double val = steepVal_mat.get(0, t);
509 
510  if(_liability_steepness_linked_index.get(0, t) >= 0) {
511  if(val != 0) warning("phenotype_expression::liability trait %i has evolving steepness; fixed steepness value ignored.\n", t+1);
512  continue;
513  }
514 
515  if(val == 0) continue; // no sigmoid for this trait
516 
517  if(val < 0)
518  return error("phenotype_expression::fixed steepness for liability trait %i must be > 0.\n", t+1);
519 
520  _liability_steepness_linked_index.set(0, t, -1.0); // fixed
522  _has_liability_sigmoid = true;
523  }
524  }
525 
526  } else {
528  _has_evolving_threshold = false;
529  _has_liability_sigmoid = false;
530  }
531 
532  // =====================================================================
533  // CHECK AT LEAST ONE FEATURE IS CONFIGURED
534  // =====================================================================
535 
537  return error("phenotype_expression::at least \"pheno_plastic_g0_quanti_trait\" or \"pheno_liability_quanti_trait\" must be set.\n");
538 
539  // labile plasticity ? ------------------------------------------------------------------
540  if(_paramSet->isSet("pheno_plastic_is_labile")) {
541  _is_labile = _paramSet->getValue("pheno_plastic_is_labile");
542  }
543  else {
544  _is_labile = false;
545  }
546 
547  // set liability function pointer
548  if(_has_liability) {
552  else
554  } else {
557  else
559  }
560  }
561 
562  return true;
563 
564 }
TraitPrototype * getTraitPrototype(trait_t type)
Accessor to a TraitPrototype.
Definition: indfactory.cc:140
void setIndLiability(Patch *patch, sex_t SEX, age_idx AGE)
Definition: LCEphenoexpression.cc:845
double get_env_cue_noise(unsigned int patch, unsigned int trait)
Definition: LCEphenoexpression.cc:782
void set_phenot_g1_g2_evol(unsigned int patch, TTQuanti *trait)
Definition: LCEphenoexpression.cc:830
void setIndLiability_evolving(Patch *patch, sex_t SEX, age_idx AGE)
Definition: LCEphenoexpression.cc:937
void setIndLiability_evolving_sigmoid(Patch *patch, sex_t SEX, age_idx AGE)
Definition: LCEphenoexpression.cc:981
bool check_g_index_matrix(Param *param, TMatrix &mat)
Definition: LCEphenoexpression.cc:590
void set_phenot_g1_evol(unsigned int patch, TTQuanti *trait)
Definition: LCEphenoexpression.cc:802
bool set_g_value_matrix(Param *param, TMatrix &mat)
Definition: LCEphenoexpression.cc:568
void set_phenot_no_evol(unsigned int patch, TTQuanti *trait)
Definition: LCEphenoexpression.cc:789
double get_env_cue_no_noise(unsigned int patch, unsigned int trait)
Definition: LCEphenoexpression.cc:775
void setIndLiability_sigmoid(Patch *patch, sex_t SEX, age_idx AGE)
Definition: LCEphenoexpression.cc:878
void set_phenot_g2_evol(unsigned int patch, TTQuanti *trait)
Definition: LCEphenoexpression.cc:816
double getValue(string name)
Accessor the parameters value.
Definition: param.h:302
Param * get_param(string name)
Look for a param "name" in its parameters list.
Definition: param.cc:667
bool isSet()
Accessor to the status flag.
Definition: param.h:288
void getVariableMatrix(vector< vector< double > > *mat)
Definition: param.cc:462
virtual double get_parameter_value(std::string name)
Param value getter.
Definition: simcomponent.h:143
virtual Param * get_parameter(std::string name)
Param getter.
Definition: simcomponent.h:139
void set(unsigned int i, unsigned int j, double val)
Sets element at row i and column j to value val.
Definition: tmatrix.h:103
TProtoQuanti.
Definition: ttquanti.h:415
void warning(const char *str,...)
Definition: output.cc:58

References _do_change_cue, _e_copy_trait_optimum_value, _e_noise, _e_rate, _g0_linked_index, _g1_evolves, _g1_linked_index, _g1_values, _g2_evolves, _g2_linked_index, _g2_values, _get_env_cue_func, _has_evolving_threshold, _has_liability, _has_liability_sigmoid, _has_plasticity, _is_labile, _liability_linked_index, _liability_steepness_allow_negative, _liability_steepness_fixed, _liability_steepness_linked_index, _liability_threshold, _liability_threshold_linked_index, _liability_values, _num_liability_trait, _num_trait, SimComponent::_paramSet, LifeCycleEvent::_popPtr, _QuantiProto, _set_liability_func, _set_phenotype_func, check_g_index_matrix(), error(), TMatrix::get(), get_env_cue_no_noise(), get_env_cue_noise(), TProtoQuanti::get_num_traits(), ParamSet::get_param(), SimComponent::get_parameter(), SimComponent::get_parameter_value(), ParamSet::getMatrix(), Metapop::getPatchNbr(), IndFactory::getTraitPrototype(), ParamSet::getValue(), Param::getVariableMatrix(), ParamSet::isSet(), TMatrix::length(), TMatrix::reset(), TMatrix::set(), set_env_cue(), set_g_value_matrix(), set_phenot_g1_evol(), set_phenot_g1_g2_evol(), set_phenot_g2_evol(), set_phenot_no_evol(), setIndLiability(), setIndLiability_evolving(), setIndLiability_evolving_sigmoid(), setIndLiability_sigmoid(), setSpatialMatrix(), and warning().

Referenced by LCE_PhenotypeExpression().

Member Data Documentation

◆ _do_change_cue

bool LCE_PhenotypeExpression::_do_change_cue
private

Referenced by execute(), and setParameters().

◆ _e_copy_trait_optimum_value

bool LCE_PhenotypeExpression::_e_copy_trait_optimum_value
private

A flag to set whether environmental cue values are equal to and copied from the trait local optimum values from LCE_selection.

Referenced by execute(), and setParameters().

◆ _e_noise

TMatrix LCE_PhenotypeExpression::_e_noise
private

A matrix to hold the environmental noise (e reliability).

Referenced by get_env_cue_noise(), and setParameters().

◆ _e_rate

TMatrix LCE_PhenotypeExpression::_e_rate
private

A matrix to hold the per generation rate of change of the environmental cues.

Referenced by execute(), and setParameters().

◆ _e_values

TMatrix LCE_PhenotypeExpression::_e_values
private

◆ _env_cue

TMatrix LCE_PhenotypeExpression::_env_cue
private

A matrix to hold the environmental cues (e value).

Referenced by execute(), get_env_cue_no_noise(), get_env_cue_noise(), and set_env_cue().

◆ _g0_linked_index

TMatrix LCE_PhenotypeExpression::_g0_linked_index
private

◆ _g1_evolves

bool LCE_PhenotypeExpression::_g1_evolves
private

Referenced by setParameters().

◆ _g1_linked_index

TMatrix LCE_PhenotypeExpression::_g1_linked_index
private

◆ _g1_values

TMatrix LCE_PhenotypeExpression::_g1_values
private

◆ _g2_evolves

bool LCE_PhenotypeExpression::_g2_evolves
private

Referenced by setParameters().

◆ _g2_linked_index

TMatrix LCE_PhenotypeExpression::_g2_linked_index
private

◆ _g2_values

TMatrix LCE_PhenotypeExpression::_g2_values
private

◆ _get_env_cue_func

double(LCE_PhenotypeExpression::* LCE_PhenotypeExpression::_get_env_cue_func) (unsigned int, unsigned int)
private

◆ _has_evolving_threshold

bool LCE_PhenotypeExpression::_has_evolving_threshold
private

Referenced by setParameters().

◆ _has_liability

bool LCE_PhenotypeExpression::_has_liability
private

Referenced by execute(), and setParameters().

◆ _has_liability_sigmoid

bool LCE_PhenotypeExpression::_has_liability_sigmoid
private

Referenced by setParameters().

◆ _has_plasticity

bool LCE_PhenotypeExpression::_has_plasticity
private

Referenced by execute(), and setParameters().

◆ _is_labile

bool LCE_PhenotypeExpression::_is_labile
private

Referenced by execute(), and setParameters().

◆ _liability_linked_index

TMatrix LCE_PhenotypeExpression::_liability_linked_index
private

◆ _liability_steepness_allow_negative

bool LCE_PhenotypeExpression::_liability_steepness_allow_negative
private

◆ _liability_steepness_fixed

vector<double> LCE_PhenotypeExpression::_liability_steepness_fixed
private

◆ _liability_steepness_linked_index

TMatrix LCE_PhenotypeExpression::_liability_steepness_linked_index
private

◆ _liability_threshold

vector< vector<double> > LCE_PhenotypeExpression::_liability_threshold
private

◆ _liability_threshold_linked_index

TMatrix LCE_PhenotypeExpression::_liability_threshold_linked_index
private

◆ _liability_values

vector< vector<double> > LCE_PhenotypeExpression::_liability_values
private

◆ _num_liability_trait

unsigned int LCE_PhenotypeExpression::_num_liability_trait
private

◆ _num_trait

unsigned int LCE_PhenotypeExpression::_num_trait
private

◆ _QuantiProto

TProtoQuanti* LCE_PhenotypeExpression::_QuantiProto
private

A pointer to the plastic trait prototype.

Referenced by check_g_index_matrix(), set_g_value_matrix(), and setParameters().

◆ _set_liability_func

void(LCE_PhenotypeExpression::* LCE_PhenotypeExpression::_set_liability_func) (Patch *, sex_t, age_idx)
private

Referenced by execute(), and setParameters().

◆ _set_phenotype_func

void(LCE_PhenotypeExpression::* LCE_PhenotypeExpression::_set_phenotype_func) (unsigned int, TTQuanti *)
private

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

Generated for Nemo v2.4.0b by  doxygen 1.9.1 -- Nemo is hosted on  Download Nemo

Locations of visitors to this page
Catalogued on GSR