bpp-phyl3  3.0.0
bpp::MarkovModulatedSubstitutionModel Class Referenceabstract

Partial implementation of the Markov-modulated class of substitution models. More...

#include <Bpp/Phyl/Model/MarkovModulatedSubstitutionModel.h>

+ Inheritance diagram for bpp::MarkovModulatedSubstitutionModel:
+ Collaboration diagram for bpp::MarkovModulatedSubstitutionModel:

Public Member Functions

 MarkovModulatedSubstitutionModel (std::unique_ptr< ReversibleSubstitutionModelInterface > model, unsigned int nbRates, bool normalizeRateChanges, const std::string &prefix)
 Build a new MarkovModulatedSubstitutionModel object. More...
 
 MarkovModulatedSubstitutionModel (const MarkovModulatedSubstitutionModel &model)
 
MarkovModulatedSubstitutionModeloperator= (const MarkovModulatedSubstitutionModel &model)
 
virtual ~MarkovModulatedSubstitutionModel ()
 
MarkovModulatedSubstitutionModelclone () const override=0
 
const Alphabetalphabet () const override
 
std::shared_ptr< const AlphabetgetAlphabet () const override
 
size_t getNumberOfStates () const override
 Get the number of states. More...
 
const StateMapInterfacestateMap () const override
 
std::shared_ptr< const StateMapInterfacegetStateMap () const override
 
const std::vector< int > & getAlphabetStates () const override
 
std::string getAlphabetStateAsChar (size_t index) const override
 
int getAlphabetStateAsInt (size_t index) const override
 
std::vector< size_t > getModelStates (int code) const override
 Get the state in the model corresponding to a particular state in the alphabet. More...
 
std::vector< size_t > getModelStates (const std::string &code) const override
 Get the state in the model corresponding to a particular state in the alphabet. More...
 
const VdoublegetFrequencies () const override
 
const Matrix< double > & exchangeabilityMatrix () const override
 
const Matrix< double > & generator () const override
 
const Matrix< double > & getPij_t (double t) const override
 
const Matrix< double > & getdPij_dt (double t) const override
 
const Matrix< double > & getd2Pij_dt2 (double t) const override
 
const VdoublegetEigenValues () const override
 
const VdoublegetIEigenValues () const override
 
bool isDiagonalizable () const override
 
bool isNonSingular () const override
 
const Matrix< double > & getRowLeftEigenVectors () const override
 
const Matrix< double > & getColumnRightEigenVectors () const override
 
double freq (size_t i) const override
 
double Sij (size_t i, size_t j) const override
 
double Qij (size_t i, size_t j) const override
 A method for computing all necessary matrices. More...
 
double Pij_t (size_t i, size_t j, double t) const override
 
double dPij_dt (size_t i, size_t j, double t) const override
 
double d2Pij_dt2 (size_t i, size_t j, double t) const override
 
double getInitValue (size_t i, int state) const override
 
void setFreqFromData (const SequenceDataInterface &data, double pseudoCount=0) override
 Set equilibrium frequencies equal to the frequencies estimated from the data. More...
 
void setFreq (std::map< int, double > &frequencies) override
 Set equilibrium frequencies. More...
 
const FrequencySetInterfacefrequencySet () const override
 
const ReversibleSubstitutionModelInterfacenestedModel () const
 
size_t getRate (size_t i) const
 Get the rate category corresponding to a particular state in the compound model. More...
 
double getRate () const override
 Get the rate. More...
 
void setRate (double rate) override
 Set the rate of the model (must be positive). More...
 
bool isScalable () const override
 returns if model is scalable More...
 
void setScalable (bool scalable) override
 sets if model is scalable, ie scale can be changed. Default : true, set to false to avoid normalization for example. More...
 
void normalize () override
 Normalize the generator. More...
 
void setDiagonal () override
 set the diagonal of the generator such that sum on each line equals 0. More...
 
double getScale () const override
 Get the scalar product of diagonal elements of the generator and the frequencies vector. If the generator is normalized, then scale=1. Otherwise each element must be multiplied by 1/scale. More...
 
void setScale (double scale) override
 Multiplies the current generator by the given scale. More...
 
void enableEigenDecomposition (bool yn) override
 Set if eigenValues and Vectors must be computed. More...
 
bool enableEigenDecomposition () override
 Tell if eigenValues and Vectors must be computed. More...
 
bool computeFrequencies () const override
 
void computeFrequencies (bool yn) override
 
virtual void fireParameterChanged (const ParameterList &parameters) override
 Tells the model that a parameter value has changed. More...
 
void setNamespace (const std::string &prefix) override
 
virtual const Eigen::VectorXd & Lik_t (const Eigen::VectorXd &values, double t) const =0
 
virtual const Eigen::VectorXd & dLik_dt (const Eigen::VectorXd &values, double t) const =0
 
virtual const Eigen::VectorXd & d2Lik_dt2 (const Eigen::VectorXd &values, double t) const =0
 
virtual std::string getName () const =0
 Get the name of the model. More...
 
virtual void addRateParameter ()=0
 
virtual size_t getNumberOfIndependentParameters () const=0
 
virtual void aliasParameters (const std::string &p1, const std::string &p2)=0
 
virtual void aliasParameters (std::map< std::string, std::string > &unparsedParams, bool verbose)=0
 
virtual void unaliasParameters (const std::string &p1, const std::string &p2)=0
 
virtual const ParameterListgetIndependentParameters () const=0
 
virtual std::vector< std::string > getAlias (const std::string &name) const=0
 
virtual std::map< std::string, std::string > getAliases () const=0
 
virtual bool hasParameter (const std::string &name) const=0
 
virtual const ParameterListgetParameters () const=0
 
virtual const Parameterparameter (const std::string &name) const=0
 
virtual double getParameterValue (const std::string &name) const=0
 
virtual void setAllParametersValues (const ParameterList &parameters)=0
 
virtual void setParameterValue (const std::string &name, double value)=0
 
virtual void setParametersValues (const ParameterList &parameters)=0
 
virtual bool matchParametersValues (const ParameterList &parameters)=0
 
virtual void removeConstraint (const std::string &name)=0
 
virtual void setConstraint (const std::string &name, std::shared_ptr< ConstraintInterface > constraint)=0
 
virtual size_t getNumberOfParameters () const=0
 
virtual std::string getNamespace () const=0
 
virtual std::string getParameterNameWithoutNamespace (const std::string &name) const=0
 
bool hasIndependentParameter (const std::string &name) const
 
const ParameterListgetIndependentParameters () const
 
size_t getNumberOfIndependentParameters () const
 
void aliasParameters (const std::string &p1, const std::string &p2)
 
void aliasParameters (std::map< std::string, std::string > &unparsedParams, bool verbose)
 
void unaliasParameters (const std::string &p1, const std::string &p2)
 
ParameterList getAliasedParameters (const ParameterList &pl) const
 
ParameterList getFromParameters (const ParameterList &pl) const
 
virtual std::vector< std::string > getAlias (const std::string &name) const
 
virtual std::map< std::string, std::string > getAliases () const
 
std::string getFrom (const std::string &name) const
 
bool hasParameter (const std::string &name) const override
 
const ParameterListgetParameters () const override
 
const Parameterparameter (const std::string &name) const override
 
const std::shared_ptr< Parameter > & getParameter (const std::string &name) const
 
double getParameterValue (const std::string &name) const override
 
void setAllParametersValues (const ParameterList &parameters) override
 
void setParameterValue (const std::string &name, double value) override
 
void setParametersValues (const ParameterList &parameters) override
 
bool matchParametersValues (const ParameterList &parameters) override
 
void removeConstraint (const std::string &name) override
 
void setConstraint (const std::string &name, std::shared_ptr< ConstraintInterface > constraint) override
 
size_t getNumberOfParameters () const override
 
std::string getNamespace () const override
 
std::string getParameterNameWithoutNamespace (const std::string &name) const override
 
const Eigen::VectorXd & Lik_t (const Eigen::VectorXd &values, double t) const override
 
const Eigen::VectorXd & dLik_dt (const Eigen::VectorXd &values, double t) const override
 
const Eigen::VectorXd & d2Lik_dt2 (const Eigen::VectorXd &values, double t) const override
 

Protected Member Functions

virtual void updateMatrices_ ()
 
virtual void updateRatesModel_ ()=0
 Update the rates vector, generator and equilibrium frequencies. More...
 
VdoublegetFrequencies_ () override
 
virtual ParameterListgetParameters_ ()=0
 
const std::shared_ptr< Parameter > & getParameter (size_t i) const
 
std::shared_ptr< Parameter > & getParameter (size_t i)
 
void addParameter_ (Parameter *parameter)
 
void addParameters_ (const ParameterList &parameters)
 
void shareParameter_ (const std::shared_ptr< Parameter > &parameter)
 
void shareParameters_ (const ParameterList &parameters)
 
void includeParameters_ (const ParameterList &parameters)
 
void deleteParameter_ (size_t index)
 
void deleteParameter_ (std::string &name)
 
void deleteParameters_ (const std::vector< std::string > &names)
 
void resetParameters_ ()
 
ParametergetParameter_ (const std::string &name)
 
ParametergetParameter_ (size_t index)
 
const ParametergetParameter_ (size_t index) const
 
ParametergetParameterWithNamespace_ (const std::string &name)
 
const ParametergetParameterWithNamespace_ (const std::string &name) const
 
ParameterListgetParameters_ () override
 

Protected Attributes

std::unique_ptr< ReversibleSubstitutionModelInterfacemodel_
 
std::shared_ptr< const MarkovModulatedStateMapstateMap_
 
size_t nbStates_
 
size_t nbRates_
 
RowMatrix< double > ratesGenerator_
 
RowMatrix< double > generator_
 The generator matrix $Q$ of the model. More...
 
RowMatrix< double > exchangeability_
 The exchangeability matrix $S$ of the model. More...
 
RowMatrix< double > leftEigenVectors_
 The $U$ matrix made of left eigen vectors (by row). More...
 
RowMatrix< double > rightEigenVectors_
 The $U^-1$ matrix made of right eigen vectors (by column). More...
 
Vdouble eigenValues_
 The vector of real parts of eigen values. More...
 
Vdouble iEigenValues_
 The vector of imaginary parts of the eigen values (zero in case of reversible pmodel). More...
 
bool eigenDecompose_
 Tell if the eigen decomposition should be performed. More...
 
bool compFreq_
 Tell if the equilibrium frequencies should be computed from the generator. More...
 
RowMatrix< double > pijt_
 These ones are for bookkeeping: More...
 
RowMatrix< double > dpijt_
 
RowMatrix< double > d2pijt_
 
Vdouble freq_
 The vector of equilibrium frequencies. More...
 
bool normalizeRateChanges_
 
std::string nestedPrefix_
 
Rate generator.

These variables must be initialized in the constructor of the derived class.

RowMatrix< double > rates_
 
RowMatrix< double > ratesExchangeability_
 
Vdouble ratesFreq_
 

Private Attributes

ParameterList independentParameters_
 
std::map< std::string, std::shared_ptr< AliasParameterListener > > aliasListenersRegister_
 
ParameterList parameters_
 
std::string prefix_
 
Eigen::VectorXd lik_
 

Detailed Description

Partial implementation of the Markov-modulated class of substitution models.

This class wraps a substitution model and provide a matrix describing rate changes. The rate matrix must be initialized by derived classes of this class. Using these matrices, the diagonalization procedure of Galtier and Jean-Marie is used.

Such models can be described using two matrices: a substitution matrix, $M$, with size $m$, which is a "standard" substitution model of any alphabet type, and a rate matrix $G$ of size $g$. The generator of the markov-modulated model, $Q$ can be written using Kronecker matrix operands.

\[ Q=D_R \otimes M + G \otimes I_m, \]

where $D_R$ is the diagonal matrix of all rates, and $I_m$ is the identity matrix of size $m$.

This generator is normalized so that branch lengths are measured in unit of mean number of substitutions per site, where susbstitution here means "change of alphabet Rate changes are not counted.

Galtier N. and Jean-Marie A., Markov-modulated Markov chains and the covarion process of molecular evolution (2004). Journal of Computational Biology, 11:727-33.

Definition at line 46 of file MarkovModulatedSubstitutionModel.h.

Constructor & Destructor Documentation

◆ MarkovModulatedSubstitutionModel() [1/2]

bpp::MarkovModulatedSubstitutionModel::MarkovModulatedSubstitutionModel ( std::unique_ptr< ReversibleSubstitutionModelInterface model,
unsigned int  nbRates,
bool  normalizeRateChanges,
const std::string &  prefix 
)
inline

Build a new MarkovModulatedSubstitutionModel object.

Parameters
modelThe substitution model to use. Can be of any alphabet type, and will be owned by this instance.
nbRatesThe number of rate classes
normalizeRateChangesTells if the branch lengths must be computed in terms of rate and state NB: In most cases, this parameter should be set to false.
prefixThe parameter namespace to be forwarded to the AbstractParametrizable constructor. changes instead of state change only.

Definition at line 139 of file MarkovModulatedSubstitutionModel.h.

References bpp::AbstractParameterAliasable::addParameters_(), model_, and nestedPrefix_.

◆ MarkovModulatedSubstitutionModel() [2/2]

MarkovModulatedSubstitutionModel::MarkovModulatedSubstitutionModel ( const MarkovModulatedSubstitutionModel model)

Definition at line 16 of file MarkovModulatedSubstitutionModel.cpp.

◆ ~MarkovModulatedSubstitutionModel()

virtual bpp::MarkovModulatedSubstitutionModel::~MarkovModulatedSubstitutionModel ( )
inlinevirtual

Definition at line 172 of file MarkovModulatedSubstitutionModel.h.

Member Function Documentation

◆ addRateParameter()

◆ alphabet()

const Alphabet& bpp::MarkovModulatedSubstitutionModel::alphabet ( ) const
inlineoverridevirtual
Returns
A reference to the alphabet associated to this model.

Implements bpp::BranchModelInterface.

Definition at line 177 of file MarkovModulatedSubstitutionModel.h.

References model_.

◆ clone()

MarkovModulatedSubstitutionModel* bpp::MarkovModulatedSubstitutionModel::clone ( ) const
overridepure virtual

Implements bpp::AbstractParameterAliasable.

Implemented in bpp::TS98, and bpp::G2001.

◆ computeFrequencies() [1/2]

bool bpp::MarkovModulatedSubstitutionModel::computeFrequencies ( ) const
inlineoverridevirtual
Returns
Says if equilibrium frequencies should be computed

Implements bpp::TransitionModelInterface.

Definition at line 299 of file MarkovModulatedSubstitutionModel.h.

References compFreq_.

◆ computeFrequencies() [2/2]

void bpp::MarkovModulatedSubstitutionModel::computeFrequencies ( bool  yn)
inlineoverridevirtual
Returns
Set if equilibrium frequencies should be computed

Implements bpp::TransitionModelInterface.

Definition at line 301 of file MarkovModulatedSubstitutionModel.h.

References compFreq_.

◆ d2Lik_dt2() [1/2]

virtual const Eigen::VectorXd& bpp::TransitionModelInterface::d2Lik_dt2 ( const Eigen::VectorXd &  values,
double  t 
) const
pure virtualinherited

◆ d2Lik_dt2() [2/2]

const Eigen::VectorXd& bpp::AbstractLkTransitionModel::d2Lik_dt2 ( const Eigen::VectorXd &  values,
double  t 
) const
inlineoverridevirtualinherited

◆ d2Pij_dt2()

double bpp::MarkovModulatedSubstitutionModel::d2Pij_dt2 ( size_t  i,
size_t  j,
double  t 
) const
inlineoverridevirtual
Returns
The second order derivative of the probability of change from state i to state j with respect to time t, at time t.
See also
getd2Pij_dt2(), getStates()

Implements bpp::TransitionModelInterface.

Definition at line 222 of file MarkovModulatedSubstitutionModel.h.

References getd2Pij_dt2().

◆ dLik_dt() [1/2]

virtual const Eigen::VectorXd& bpp::TransitionModelInterface::dLik_dt ( const Eigen::VectorXd &  values,
double  t 
) const
pure virtualinherited

◆ dLik_dt() [2/2]

const Eigen::VectorXd& bpp::AbstractLkTransitionModel::dLik_dt ( const Eigen::VectorXd &  values,
double  t 
) const
inlineoverridevirtualinherited

◆ dPij_dt()

double bpp::MarkovModulatedSubstitutionModel::dPij_dt ( size_t  i,
size_t  j,
double  t 
) const
inlineoverridevirtual
Returns
The first order derivative of the probability of change from state i to state j with respect to time t, at time t.
See also
getdPij_dt(), getStates()

Implements bpp::TransitionModelInterface.

Definition at line 221 of file MarkovModulatedSubstitutionModel.h.

References getdPij_dt().

◆ enableEigenDecomposition() [1/2]

bool bpp::MarkovModulatedSubstitutionModel::enableEigenDecomposition ( )
inlineoverridevirtual

Tell if eigenValues and Vectors must be computed.

Implements bpp::SubstitutionModelInterface.

Definition at line 297 of file MarkovModulatedSubstitutionModel.h.

References eigenDecompose_.

◆ enableEigenDecomposition() [2/2]

void bpp::MarkovModulatedSubstitutionModel::enableEigenDecomposition ( bool  yn)
inlineoverridevirtual

Set if eigenValues and Vectors must be computed.

Implements bpp::SubstitutionModelInterface.

Definition at line 295 of file MarkovModulatedSubstitutionModel.h.

References eigenDecompose_.

◆ exchangeabilityMatrix()

const Matrix<double>& bpp::MarkovModulatedSubstitutionModel::exchangeabilityMatrix ( ) const
inlineoverridevirtual
Returns
The matrix of exchangeability terms. It is recommended that exchangeability matrix be normalized so that the normalized generator be obtained directly by the dot product $S . \pi$.

Implements bpp::SubstitutionModelInterface.

Definition at line 199 of file MarkovModulatedSubstitutionModel.h.

References exchangeability_.

◆ fireParameterChanged()

virtual void bpp::MarkovModulatedSubstitutionModel::fireParameterChanged ( const ParameterList parameters)
inlineoverridevirtual

Tells the model that a parameter value has changed.

This updates the matrices consequently.

Reimplemented from bpp::AbstractParameterAliasable.

Reimplemented in bpp::G2001.

Definition at line 309 of file MarkovModulatedSubstitutionModel.h.

References model_, updateMatrices_(), and updateRatesModel_().

Referenced by bpp::G2001::fireParameterChanged().

◆ freq()

double bpp::MarkovModulatedSubstitutionModel::freq ( size_t  i) const
inlineoverridevirtual
Returns
Equilibrium frequency associated to character i.
See also
getFrequencies(), getStates()

Implements bpp::TransitionModelInterface.

Definition at line 216 of file MarkovModulatedSubstitutionModel.h.

References freq_.

◆ frequencySet()

const FrequencySetInterface& bpp::MarkovModulatedSubstitutionModel::frequencySet ( ) const
inlineoverridevirtual
Returns
Get the FrequencySet of equilibrium of this model.
Exceptions
Exceptionif no FrequenceSet is associated to this model.

Implements bpp::BranchModelInterface.

Definition at line 238 of file MarkovModulatedSubstitutionModel.h.

◆ generator()

const Matrix<double>& bpp::MarkovModulatedSubstitutionModel::generator ( ) const
inlineoverridevirtual
Returns
The normalized Markov generator matrix, i.e. all normalized rates of changes from state i to state j. The generator is normalized so that (i) $ \forall i; \sum_j Q_{i,j} = 0 $, meaning that $ $ \forall i; Q_{i,i} = -\sum_{j \neq i}Q_{i,j}$, and (ii) $ \sum_i Q_{i,i} \times \pi_i = -1$. This means that, under normalization, the mean rate of replacement at equilibrium is 1 and that time $t$ are measured in units of expected number of changes per site. Additionally, the rate_ attribute provides the possibility to increase or decrease this mean rate.

See Kosiol and Goldman (2005), Molecular Biology And Evolution 22(2) 193-9.

See also
Qij()

Implements bpp::SubstitutionModelInterface.

Definition at line 201 of file MarkovModulatedSubstitutionModel.h.

References generator_.

◆ getAlphabet()

std::shared_ptr<const Alphabet> bpp::MarkovModulatedSubstitutionModel::getAlphabet ( ) const
inlineoverridevirtual
Returns
A pointer toward the alphabet associated to this model.

Implements bpp::BranchModelInterface.

Definition at line 179 of file MarkovModulatedSubstitutionModel.h.

References model_.

Referenced by getInitValue().

◆ getAlphabetStateAsChar()

std::string bpp::MarkovModulatedSubstitutionModel::getAlphabetStateAsChar ( size_t  index) const
inlineoverridevirtual
Parameters
indexThe model state.
Returns
The corresponding alphabet state as character code.

Implements bpp::BranchModelInterface.

Definition at line 189 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

◆ getAlphabetStateAsInt()

int bpp::MarkovModulatedSubstitutionModel::getAlphabetStateAsInt ( size_t  index) const
inlineoverridevirtual
Parameters
indexThe model state.
Returns
The corresponding alphabet state as character code.

Implements bpp::BranchModelInterface.

Definition at line 191 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

Referenced by getInitValue().

◆ getAlphabetStates()

const std::vector<int>& bpp::MarkovModulatedSubstitutionModel::getAlphabetStates ( ) const
inlineoverridevirtual
Returns
The alphabet states of each state of the model, as a vector of int codes.
See also
Alphabet

Implements bpp::BranchModelInterface.

Definition at line 187 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

◆ getColumnRightEigenVectors()

const Matrix<double>& bpp::MarkovModulatedSubstitutionModel::getColumnRightEigenVectors ( ) const
inlineoverridevirtual
Returns
A matrix with right eigen vectors. Each column in the matrix stands for an eigen vector.

Implements bpp::SubstitutionModelInterface.

Definition at line 214 of file MarkovModulatedSubstitutionModel.h.

References rightEigenVectors_.

◆ getd2Pij_dt2()

const Matrix< double > & MarkovModulatedSubstitutionModel::getd2Pij_dt2 ( double  t) const
overridevirtual
Returns
All second order derivatives of the probability of change from state i to state j with respect to time t, at time t.
See also
d2Pij_dt2()

Implements bpp::TransitionModelInterface.

Definition at line 177 of file MarkovModulatedSubstitutionModel.cpp.

References d2pijt_, eigenValues_, bpp::VectorTools::exp(), leftEigenVectors_, bpp::MatrixTools::mult(), rightEigenVectors_, and bpp::VectorTools::sqr().

Referenced by d2Pij_dt2().

◆ getdPij_dt()

const Matrix< double > & MarkovModulatedSubstitutionModel::getdPij_dt ( double  t) const
overridevirtual
Returns
Get all first order derivatives of the probability of change from state i to state j with respect to time t, at time t.
See also
dPij_dt()

Implements bpp::TransitionModelInterface.

Definition at line 171 of file MarkovModulatedSubstitutionModel.cpp.

References dpijt_, eigenValues_, bpp::VectorTools::exp(), leftEigenVectors_, bpp::MatrixTools::mult(), and rightEigenVectors_.

Referenced by dPij_dt().

◆ getEigenValues()

const Vdouble& bpp::MarkovModulatedSubstitutionModel::getEigenValues ( ) const
inlineoverridevirtual
Returns
A vector with all real parts of the eigen values of the generator of this model;

Implements bpp::SubstitutionModelInterface.

Definition at line 207 of file MarkovModulatedSubstitutionModel.h.

References eigenValues_.

◆ getFrequencies()

const Vdouble& bpp::MarkovModulatedSubstitutionModel::getFrequencies ( ) const
inlineoverridevirtual
Returns
A vector of all equilibrium frequencies.
See also
freq()

Implements bpp::TransitionModelInterface.

Definition at line 197 of file MarkovModulatedSubstitutionModel.h.

References freq_.

◆ getFrequencies_()

Vdouble& bpp::MarkovModulatedSubstitutionModel::getFrequencies_ ( )
inlineoverrideprotectedvirtual

Implements bpp::TransitionModelInterface.

Definition at line 329 of file MarkovModulatedSubstitutionModel.h.

References freq_.

◆ getIEigenValues()

const Vdouble& bpp::MarkovModulatedSubstitutionModel::getIEigenValues ( ) const
inlineoverridevirtual
Returns
A vector with all imaginary parts of the eigen values of the generator of this model;

Implements bpp::SubstitutionModelInterface.

Definition at line 208 of file MarkovModulatedSubstitutionModel.h.

References iEigenValues_.

◆ getInitValue()

double MarkovModulatedSubstitutionModel::getInitValue ( size_t  i,
int  state 
) const
overridevirtual

This method is used to initialize likelihoods in recursions. It typically sends 1 if i = state, 0 otherwise, where i is one of the possible states of the alphabet allowed in the model and state is the observed state in the considered sequence/site.

Parameters
ithe index of the state in the model.
stateAn observed state in the sequence/site.
Returns
1 or 0 depending if the two states are compatible.
Exceptions
IndexOutOfBoundsExceptionif array position is out of range.
BadIntExceptionif states are not allowed in the associated alphabet.
See also
getStates();

Implements bpp::BranchModelInterface.

Definition at line 185 of file MarkovModulatedSubstitutionModel.cpp.

References getAlphabet(), getAlphabetStateAsInt(), model_, nbRates_, and nbStates_.

◆ getModelStates() [1/2]

std::vector<size_t> bpp::MarkovModulatedSubstitutionModel::getModelStates ( const std::string &  code) const
inlineoverridevirtual

Get the state in the model corresponding to a particular state in the alphabet.

Parameters
codeThe alphabet state to check.
Returns
A vector of indices of model states.

Implements bpp::BranchModelInterface.

Definition at line 195 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

◆ getModelStates() [2/2]

std::vector<size_t> bpp::MarkovModulatedSubstitutionModel::getModelStates ( int  code) const
inlineoverridevirtual

Get the state in the model corresponding to a particular state in the alphabet.

Parameters
codeThe alphabet state to check.
Returns
A vector of indices of model states.

Implements bpp::BranchModelInterface.

Definition at line 193 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

◆ getName()

virtual std::string bpp::BranchModelInterface::getName ( ) const
pure virtualinherited

Get the name of the model.

Returns
The name of this model.

Implemented in bpp::WordSubstitutionModel, bpp::TS98, bpp::TransitionFromTransitionModel, bpp::RegisterRatesSubstitutionModel, bpp::RE08, bpp::WAG01, bpp::UserProteinSubstitutionModel, bpp::LLG08_UL3, bpp::LLG08_UL3::EmbeddedModel, bpp::LLG08_UL2, bpp::LLG08_UL2::EmbeddedModel, bpp::LLG08_EX3, bpp::LLG08_EX3::EmbeddedModel, bpp::LLG08_EX2, bpp::LLG08_EX2::EmbeddedModel, bpp::LLG08_EHO, bpp::LLG08_EHO::EmbeddedModel, bpp::LGL08_CAT, bpp::LGL08_CAT::EmbeddedModel, bpp::LG08, bpp::JTT92, bpp::JCprot, bpp::DSO78, bpp::Coala, bpp::POMO, bpp::OneChangeTransitionModel, bpp::OneChangeRegisterTransitionModel, bpp::YpR_Gen, bpp::YpR_Sym, bpp::TN93, bpp::T92, bpp::SSR, bpp::RN95s, bpp::RN95, bpp::L95, bpp::K80, bpp::JCnuc, bpp::GTR, bpp::gBGC, bpp::F81, bpp::MultinomialFromTransitionModel, bpp::MixtureOfTransitionModels, bpp::MixtureOfATransitionModel, bpp::KroneckerWordSubstitutionModel, bpp::InMixedSubstitutionModel, bpp::G2001, bpp::FromMixtureSubstitutionModel, bpp::EquiprobableSubstitutionModel, bpp::D1WalkSubstitutionModel, bpp::YNGP_M9, bpp::YNGP_M8, bpp::YNGP_M7, bpp::YNGP_M3, bpp::YNGP_M2, bpp::YNGP_M10, bpp::YNGP_M1, bpp::YN98, bpp::TripletSubstitutionModel, bpp::SENCA, bpp::RELAX, bpp::MG94, bpp::KroneckerCodonDistanceSubstitutionModel, bpp::KroneckerCodonDistanceFrequenciesSubstitutionModel, bpp::KCM, bpp::GY94, bpp::DFPDistanceFrequenciesSubstitutionModel, bpp::DFP07, bpp::CodonSameAARateSubstitutionModel, bpp::CodonDistancePhaseFrequenciesSubstitutionModel, bpp::CodonDistanceFrequenciesSubstitutionModel, bpp::CodonAdHocSubstitutionModel, bpp::AnonymousSubstitutionModel, bpp::AbstractWrappedModel, bpp::TwoParameterBinarySubstitutionModel, bpp::LG10_EX_EHO, bpp::LG10_EX_EHO::EmbeddedModel, bpp::HKY85, bpp::F84, bpp::CodonDistanceSubstitutionModel, and bpp::BinarySubstitutionModel.

Referenced by bpp::YpR::checkModel(), bpp::TransitionMatrixFromModel::compute(), bpp::AbstractWrappedModel::getName(), bpp::FromMixtureSubstitutionModel::getName(), bpp::AbstractSubstitutionModel::getPij_t(), bpp::BppOSubstitutionModelFormat::initialize_(), bpp::MixtureOfSubstitutionModels::MixtureOfSubstitutionModels(), bpp::MixtureOfATransitionModel::model(), bpp::LegacyPhylogeneticsApplicationTools::setSubstitutionModelParametersInitialValuesWithAliases(), bpp::ModelPath::toString(), and bpp::BppOSubstitutionModelFormat::write().

◆ getNumberOfStates()

size_t bpp::MarkovModulatedSubstitutionModel::getNumberOfStates ( ) const
inlineoverridevirtual

Get the number of states.

For most models, this equals the size of the alphabet.

See also
getAlphabetChars for the list of supported states.
Returns
The number of different states in the model.

Implements bpp::BranchModelInterface.

Definition at line 181 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

Referenced by setDiagonal().

◆ getPij_t()

const Matrix< double > & MarkovModulatedSubstitutionModel::getPij_t ( double  t) const
overridevirtual
Returns
All probabilities of change from state i to state j during time t.
See also
Pij_t()

Implements bpp::TransitionModelInterface.

Definition at line 162 of file MarkovModulatedSubstitutionModel.cpp.

References eigenValues_, bpp::VectorTools::exp(), leftEigenVectors_, bpp::MatrixTools::mult(), nbRates_, nbStates_, pijt_, and rightEigenVectors_.

Referenced by Pij_t().

◆ getRate() [1/2]

double bpp::MarkovModulatedSubstitutionModel::getRate ( ) const
inlineoverridevirtual

Get the rate.

Implements bpp::BranchModelInterface.

Reimplemented in bpp::TS98.

Definition at line 260 of file MarkovModulatedSubstitutionModel.h.

References model_.

◆ getRate() [2/2]

size_t bpp::MarkovModulatedSubstitutionModel::getRate ( size_t  i) const
inline

Get the rate category corresponding to a particular state in the compound model.

Parameters
iThe state.
Returns
The corresponding rate category.
See also
getState;

Definition at line 255 of file MarkovModulatedSubstitutionModel.h.

References nbStates_.

◆ getRowLeftEigenVectors()

const Matrix<double>& bpp::MarkovModulatedSubstitutionModel::getRowLeftEigenVectors ( ) const
inlineoverridevirtual
Returns
A matrix with left eigen vectors. Each row in the matrix stands for an eigen vector.

Implements bpp::SubstitutionModelInterface.

Definition at line 213 of file MarkovModulatedSubstitutionModel.h.

References leftEigenVectors_.

◆ getScale()

double bpp::MarkovModulatedSubstitutionModel::getScale ( ) const
inlineoverridevirtual

Get the scalar product of diagonal elements of the generator and the frequencies vector. If the generator is normalized, then scale=1. Otherwise each element must be multiplied by 1/scale.

Returns
Minus the scalar product of diagonal elements and the frequencies vector.

Implements bpp::SubstitutionModelInterface.

Definition at line 282 of file MarkovModulatedSubstitutionModel.h.

References bpp::MatrixTools::diag(), freq_, and generator_.

Referenced by updateMatrices_().

◆ getStateMap()

std::shared_ptr<const StateMapInterface> bpp::MarkovModulatedSubstitutionModel::getStateMap ( ) const
inlineoverridevirtual
Returns
A shared_ptr to the mapping of model states with alphabet states.

Implements bpp::BranchModelInterface.

Definition at line 185 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

◆ isDiagonalizable()

bool bpp::MarkovModulatedSubstitutionModel::isDiagonalizable ( ) const
inlineoverridevirtual
Returns
True if the model is diagonalizable in R.

Implements bpp::SubstitutionModelInterface.

Definition at line 210 of file MarkovModulatedSubstitutionModel.h.

◆ isNonSingular()

bool bpp::MarkovModulatedSubstitutionModel::isNonSingular ( ) const
inlineoverridevirtual
Returns
True is the model is non-singular.

Implements bpp::SubstitutionModelInterface.

Definition at line 211 of file MarkovModulatedSubstitutionModel.h.

◆ isScalable()

bool bpp::MarkovModulatedSubstitutionModel::isScalable ( ) const
inlineoverridevirtual

returns if model is scalable

Implements bpp::SubstitutionModelInterface.

Definition at line 264 of file MarkovModulatedSubstitutionModel.h.

References model_.

Referenced by updateMatrices_().

◆ Lik_t() [1/2]

virtual const Eigen::VectorXd& bpp::TransitionModelInterface::Lik_t ( const Eigen::VectorXd &  values,
double  t 
) const
pure virtualinherited

This method is used to compute likelihoods in recursions. It computes the probability of a vector given a start state.

Parameters
valuesAn vector of states on the site.
tthe branch length

Implements bpp::BranchModelInterface.

Implemented in bpp::AbstractLkTransitionModel.

◆ Lik_t() [2/2]

const Eigen::VectorXd& bpp::AbstractLkTransitionModel::Lik_t ( const Eigen::VectorXd &  values,
double  t 
) const
inlineoverridevirtualinherited

This method is used to compute likelihoods in recursions. It computes the probability of a vector given a start state.

Parameters
valuesAn vector of states on the site.
tthe branch length

Implements bpp::TransitionModelInterface.

Definition at line 30 of file AbstractSubstitutionModel.h.

References bpp::TransitionModelInterface::getPij_t(), and bpp::AbstractLkTransitionModel::lik_.

◆ nestedModel()

const ReversibleSubstitutionModelInterface& bpp::MarkovModulatedSubstitutionModel::nestedModel ( ) const
inline

Definition at line 243 of file MarkovModulatedSubstitutionModel.h.

References model_.

Referenced by bpp::BppOSubstitutionModelFormat::write().

◆ normalize()

void bpp::MarkovModulatedSubstitutionModel::normalize ( )
inlineoverridevirtual

Normalize the generator.

Implements bpp::SubstitutionModelInterface.

Definition at line 274 of file MarkovModulatedSubstitutionModel.h.

References model_, and updateMatrices_().

◆ operator=()

◆ Pij_t()

double bpp::MarkovModulatedSubstitutionModel::Pij_t ( size_t  i,
size_t  j,
double  t 
) const
inlineoverridevirtual
Returns
The probability of change from state i to state j during time t.
See also
getPij_t(), getStates()

Implements bpp::TransitionModelInterface.

Definition at line 220 of file MarkovModulatedSubstitutionModel.h.

References getPij_t().

◆ Qij()

double bpp::MarkovModulatedSubstitutionModel::Qij ( size_t  i,
size_t  j 
) const
inlineoverridevirtual

A method for computing all necessary matrices.

Returns
The rate in the generator of change from state i to state j.
See also
getStates();

Implements bpp::SubstitutionModelInterface.

Definition at line 218 of file MarkovModulatedSubstitutionModel.h.

References generator_.

◆ setDiagonal()

void MarkovModulatedSubstitutionModel::setDiagonal ( )
overridevirtual

set the diagonal of the generator such that sum on each line equals 0.

Implements bpp::SubstitutionModelInterface.

Definition at line 144 of file MarkovModulatedSubstitutionModel.cpp.

References generator_, getNumberOfStates(), and RowMatrix< double >::getRow().

◆ setFreq()

void bpp::MarkovModulatedSubstitutionModel::setFreq ( std::map< int, double > &  frequencies)
inlineoverridevirtual

Set equilibrium frequencies.

Parameters
frequenciesThe map of the frequencies to use.

Implements bpp::TransitionModelInterface.

Definition at line 232 of file MarkovModulatedSubstitutionModel.h.

References model_, and updateMatrices_().

◆ setFreqFromData()

void bpp::MarkovModulatedSubstitutionModel::setFreqFromData ( const SequenceDataInterface data,
double  pseudoCount = 0 
)
inlineoverridevirtual

Set equilibrium frequencies equal to the frequencies estimated from the data.

Parameters
dataThe sequences to use.
pseudoCountA quantity $\psi$ to add to adjust the observed values in order to prevent issues due to missing states on small data set. The corrected frequencies shall be computed as

\[ \pi_i = \frac{n_i+\psi}{\sum_j (f_j+\psi)} \]

Implements bpp::TransitionModelInterface.

Definition at line 226 of file MarkovModulatedSubstitutionModel.h.

References model_, and updateMatrices_().

◆ setNamespace()

void MarkovModulatedSubstitutionModel::setNamespace ( const std::string &  prefix)
overridevirtual

◆ setRate()

void bpp::MarkovModulatedSubstitutionModel::setRate ( double  rate)
inlineoverridevirtual

Set the rate of the model (must be positive).

Parameters
ratemust be positive.

Implements bpp::BranchModelInterface.

Reimplemented in bpp::TS98.

Definition at line 262 of file MarkovModulatedSubstitutionModel.h.

References model_.

◆ setScalable()

void bpp::MarkovModulatedSubstitutionModel::setScalable ( bool  scalable)
inlineoverridevirtual

sets if model is scalable, ie scale can be changed. Default : true, set to false to avoid normalization for example.

Implements bpp::SubstitutionModelInterface.

Definition at line 269 of file MarkovModulatedSubstitutionModel.h.

References model_.

◆ setScale()

void bpp::MarkovModulatedSubstitutionModel::setScale ( double  scale)
inlineoverridevirtual

Multiplies the current generator by the given scale.

Parameters
scalethe scale by which the generator is multiplied.

Implements bpp::SubstitutionModelInterface.

Definition at line 289 of file MarkovModulatedSubstitutionModel.h.

References model_, and updateMatrices_().

Referenced by updateMatrices_().

◆ Sij()

double bpp::MarkovModulatedSubstitutionModel::Sij ( size_t  i,
size_t  j 
) const
inlineoverridevirtual
Returns
The exchangeability between state i and state j.

By definition Sij(i,j) = Sij(j,i).

Implements bpp::SubstitutionModelInterface.

Definition at line 217 of file MarkovModulatedSubstitutionModel.h.

References exchangeability_.

◆ stateMap()

const StateMapInterface& bpp::MarkovModulatedSubstitutionModel::stateMap ( ) const
inlineoverridevirtual
Returns
The mapping of model states with alphabet states.

Implements bpp::BranchModelInterface.

Definition at line 183 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

◆ updateMatrices_()

◆ updateRatesModel_()

virtual void bpp::MarkovModulatedSubstitutionModel::updateRatesModel_ ( )
protectedpure virtual

Update the rates vector, generator and equilibrium frequencies.

This method must be implemented by the derived class. It is called by the fireParameterChanged() method.

Implemented in bpp::TS98, and bpp::G2001.

Referenced by fireParameterChanged().

Member Data Documentation

◆ compFreq_

bool bpp::MarkovModulatedSubstitutionModel::compFreq_
protected

Tell if the equilibrium frequencies should be computed from the generator.

Definition at line 110 of file MarkovModulatedSubstitutionModel.h.

Referenced by computeFrequencies(), and operator=().

◆ d2pijt_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::d2pijt_
mutableprotected

Definition at line 117 of file MarkovModulatedSubstitutionModel.h.

Referenced by getd2Pij_dt2(), operator=(), and updateMatrices_().

◆ dpijt_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::dpijt_
mutableprotected

Definition at line 116 of file MarkovModulatedSubstitutionModel.h.

Referenced by getdPij_dt(), operator=(), and updateMatrices_().

◆ eigenDecompose_

bool bpp::MarkovModulatedSubstitutionModel::eigenDecompose_
protected

Tell if the eigen decomposition should be performed.

Definition at line 103 of file MarkovModulatedSubstitutionModel.h.

Referenced by enableEigenDecomposition(), and operator=().

◆ eigenValues_

Vdouble bpp::MarkovModulatedSubstitutionModel::eigenValues_
protected

The vector of real parts of eigen values.

Definition at line 92 of file MarkovModulatedSubstitutionModel.h.

Referenced by getd2Pij_dt2(), getdPij_dt(), getEigenValues(), getPij_t(), operator=(), and updateMatrices_().

◆ exchangeability_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::exchangeability_
protected

The exchangeability matrix $S$ of the model.

Definition at line 77 of file MarkovModulatedSubstitutionModel.h.

Referenced by exchangeabilityMatrix(), operator=(), Sij(), and updateMatrices_().

◆ freq_

Vdouble bpp::MarkovModulatedSubstitutionModel::freq_
protected

The vector of equilibrium frequencies.

Definition at line 122 of file MarkovModulatedSubstitutionModel.h.

Referenced by freq(), getFrequencies(), getFrequencies_(), getScale(), operator=(), and updateMatrices_().

◆ generator_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::generator_
protected

The generator matrix $Q$ of the model.

Definition at line 72 of file MarkovModulatedSubstitutionModel.h.

Referenced by generator(), getScale(), operator=(), Qij(), setDiagonal(), and updateMatrices_().

◆ iEigenValues_

Vdouble bpp::MarkovModulatedSubstitutionModel::iEigenValues_
protected

The vector of imaginary parts of the eigen values (zero in case of reversible pmodel).

Definition at line 98 of file MarkovModulatedSubstitutionModel.h.

Referenced by getIEigenValues(), operator=(), and updateMatrices_().

◆ leftEigenVectors_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::leftEigenVectors_
protected

The $U$ matrix made of left eigen vectors (by row).

Definition at line 82 of file MarkovModulatedSubstitutionModel.h.

Referenced by getd2Pij_dt2(), getdPij_dt(), getPij_t(), getRowLeftEigenVectors(), operator=(), and updateMatrices_().

◆ lik_

Eigen::VectorXd bpp::AbstractLkTransitionModel::lik_
mutableprivateinherited

◆ model_

◆ nbRates_

size_t bpp::MarkovModulatedSubstitutionModel::nbRates_
protected

◆ nbStates_

size_t bpp::MarkovModulatedSubstitutionModel::nbStates_
protected

◆ nestedPrefix_

std::string bpp::MarkovModulatedSubstitutionModel::nestedPrefix_
protected

◆ normalizeRateChanges_

bool bpp::MarkovModulatedSubstitutionModel::normalizeRateChanges_
protected

Definition at line 124 of file MarkovModulatedSubstitutionModel.h.

Referenced by operator=(), and updateMatrices_().

◆ pijt_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::pijt_
mutableprotected

These ones are for bookkeeping:

Definition at line 115 of file MarkovModulatedSubstitutionModel.h.

Referenced by getPij_t(), operator=(), and updateMatrices_().

◆ rates_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::rates_
protected

◆ ratesExchangeability_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::ratesExchangeability_
protected

◆ ratesFreq_

Vdouble bpp::MarkovModulatedSubstitutionModel::ratesFreq_
protected

◆ ratesGenerator_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::ratesGenerator_
protected

Definition at line 67 of file MarkovModulatedSubstitutionModel.h.

Referenced by operator=(), and updateMatrices_().

◆ rightEigenVectors_

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::rightEigenVectors_
protected

The $U^-1$ matrix made of right eigen vectors (by column).

Definition at line 87 of file MarkovModulatedSubstitutionModel.h.

Referenced by getColumnRightEigenVectors(), getd2Pij_dt2(), getdPij_dt(), getPij_t(), operator=(), and updateMatrices_().

◆ stateMap_

std::shared_ptr<const MarkovModulatedStateMap> bpp::MarkovModulatedSubstitutionModel::stateMap_
protected

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