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

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

Referenced by clone().

+ Here is the caller graph for this function:

◆ ~LCE_PhenotypeExpression()

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

Member Function Documentation

◆ addAgeClass()

virtual age_t LCE_PhenotypeExpression::addAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

126 {return 0;}

◆ check_g_index_matrix()

bool LCE_PhenotypeExpression::check_g_index_matrix ( Param param,
TMatrix mat 
)
590 {
591 
592  for(unsigned int t = 0; t < mat.length(); ++t) {
593  if( mat.get(0,t) > _QuantiProto->get_num_traits() || mat.get(0,t) < 1)
594  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",
595  (unsigned int)mat.get(0,t), param->getName().c_str());
596  // the index must be zero-based => deduce 1 from input index values:
597  mat.minus(0, t, 1.0);
598  }
599  return true;
600 }
string getName()
Definition: param.h:141
double get(unsigned int i, unsigned int j) const
Accessor to element at row i and column j.
Definition: tmatrix.h:191
void minus(unsigned int i, unsigned int j, double value)
Substracts a value from an element of the matrix.
Definition: tmatrix.h:280
unsigned int length() const
Returns the number of elements in the matrix.
Definition: tmatrix.h:216
unsigned int get_num_traits()
Definition: ttquanti.h:421
int error(const char *str,...)
Definition: output.cc:77

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

Referenced by setParameters().

+ Here is the caller graph for this function:

◆ clone()

virtual LifeCycleEvent* LCE_PhenotypeExpression::clone ( )
inlinevirtual

Implements LifeCycleEvent.

112 {return new LCE_PhenotypeExpression();}
LCE_PhenotypeExpression()
Definition: LCEphenoexpression.cc:40

References LCE_PhenotypeExpression().

◆ execute()

void LCE_PhenotypeExpression::execute ( )
virtual

Implements LifeCycleEvent.

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

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 
)
775 {
776  return _env_cue.get(patch, trait);
777 }

References _env_cue, and TMatrix::get().

Referenced by setParameters().

+ Here is the caller graph for this function:

◆ get_env_cue_noise()

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

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

Referenced by setParameters().

+ Here is the caller graph for this function:

◆ loadFileServices()

virtual void LCE_PhenotypeExpression::loadFileServices ( FileServices loader)
inlinevirtual

Implements SimComponent.

118 {}

◆ loadStatServices()

virtual void LCE_PhenotypeExpression::loadStatServices ( StatServices loader)
inlinevirtual

Implements SimComponent.

120 {}

◆ removeAgeClass()

virtual age_t LCE_PhenotypeExpression::removeAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

124 {return 0;}

◆ requiredAgeClass()

virtual age_t LCE_PhenotypeExpression::requiredAgeClass ( )
inlinevirtual

Implements LifeCycleEvent.

128 {return 0;}

◆ resetParameterFromSource()

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

Implements SimComponent.

122 {return false;}

◆ set_env_cue()

bool LCE_PhenotypeExpression::set_env_cue ( )
605 {
606  TMatrix tmp_mat;
607 
609 
610  _paramSet->getMatrix("pheno_plastic_e_value", &tmp_mat);
611 
612  if( !setSpatialMatrix("pheno_plastic_e_value", "\"pheno_plastic_traits\"", &tmp_mat, &_env_cue,
613  (unsigned)_num_trait, _popPtr->getPatchNbr(), false) )
614  return false;
615 
616  return true;
617 }
void getMatrix(string name, TMatrix *mat)
Accessor to the parameters matrix.
Definition: param.h:312
ParamSet * _paramSet
The parameters container.
Definition: simcomponent.h:46
void reset(unsigned int rows, unsigned int cols)
Re-allocate the existing matrix with assigned rows and cols dimensions and all elements to 0.
Definition: tmatrix.h:159
bool setSpatialMatrix(string param, string numColCondition, TMatrix *inMat, TMatrix *outMat, unsigned int nVal, unsigned int patchNbr, bool doRandomize)
Definition: utils.cc:113

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

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

+ Here is the caller graph for this function:

◆ set_g_value_matrix()

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

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

+ Here is the caller graph for this function:

◆ set_phenot_g1_evol()

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

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

+ Here is the caller graph for this function:

◆ set_phenot_g1_g2_evol()

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

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

+ Here is the caller graph for this function:

◆ set_phenot_g2_evol()

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

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

+ Here is the caller graph for this function:

◆ set_phenot_no_evol()

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

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

+ Here is the caller graph for this function:

◆ setIndLiability()

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

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

+ Here is the caller graph for this function:

◆ setIndLiability_evolving()

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

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

+ Here is the caller graph for this function:

◆ setIndLiability_evolving_sigmoid()

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

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

+ Here is the caller graph for this function:

◆ setIndLiability_sigmoid()

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

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

+ Here is the caller graph for this function:

◆ setIndPhenotype()

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

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

Referenced by execute().

+ Here is the caller graph for this function:

◆ setIndPhenotype_labile()

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

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

Referenced by execute().

+ Here is the caller graph for this function:

◆ setParameters()

bool LCE_PhenotypeExpression::setParameters ( )
virtual

Implements SimComponent.

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

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

+ Here is the caller graph for this function:

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

Catalogued on GSR