bpp-phyl  2.3.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 (ReversibleSubstitutionModel *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 =0
 
const AlphabetgetAlphabet () const
 
size_t getNumberOfStates () const
 Get the number of states. More...
 
const StateMapgetStateMap () const
 
const std::vector< int > & getAlphabetStates () const
 
std::string getAlphabetStateAsChar (size_t index) const
 
int getAlphabetStateAsInt (size_t index) const
 
std::vector< size_t > getModelStates (int code) const
 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
 Get the state in the model corresponding to a particular state in the alphabet. More...
 
const VdoublegetFrequencies () const
 
const Matrix< double > & getExchangeabilityMatrix () const
 
const Matrix< double > & getGenerator () const
 
const Matrix< double > & getPij_t (double t) const
 
const Matrix< double > & getdPij_dt (double t) const
 
const Matrix< double > & getd2Pij_dt2 (double t) const
 
const VdoublegetEigenValues () const
 
const VdoublegetIEigenValues () const
 
bool isDiagonalizable () const
 
bool isNonSingular () const
 
const Matrix< double > & getRowLeftEigenVectors () const
 
const Matrix< double > & getColumnRightEigenVectors () const
 
double freq (size_t i) const
 
double Sij (size_t i, size_t j) const
 
double Qij (size_t i, size_t j) const
 
double Pij_t (size_t i, size_t j, double t) const
 
double dPij_dt (size_t i, size_t j, double t) const
 
double d2Pij_dt2 (size_t i, size_t j, double t) const
 
double getInitValue (size_t i, int state) const throw (IndexOutOfBoundsException, BadIntException)
 
void setFreqFromData (const SequenceContainer &data, double pseudoCount=0)
 Set equilibrium frequencies equal to the frequencies estimated from the data. More...
 
virtual void setFreq (std::map< int, double > &frequencies)
 Set equilibrium frequencies. More...
 
const ReversibleSubstitutionModelgetNestedModel () 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
 Get the rate. More...
 
void setRate (double rate)
 Set the rate of the model (must be positive). More...
 
bool isScalable () const
 returns if model is scalable More...
 
void setScalable (bool scalable)
 sets if model is scalable, ie scale can be changed. Default : true, set to false to avoid normalization for example. More...
 
void normalize ()
 Normalize the generator. More...
 
double getScale () const
 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)
 Multiplies the current generator by the given scale. More...
 
void enableEigenDecomposition (bool yn)
 Set if eigenValues and Vectors must be computed. More...
 
bool enableEigenDecomposition ()
 Tell if eigenValues and Vectors must be computed. More...
 
virtual void fireParameterChanged (const ParameterList &parameters)
 Tells the model that a parameter value has changed. More...
 
void setNamespace (const std::string &prefix)
 
virtual void addRateParameter ()=0
 
virtual std::string getName () const =0
 Get the name of the model. More...
 
virtual const FrequenciesSetgetFrequenciesSet () const
 If the model owns a FrequenciesSet, returns a pointer to it, otherwise return 0. More...
 
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 ParametergetParameter (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 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
 
const ParameterListgetParameters () const
 
const ParametergetParameter (const std::string &name) const
 
const std::shared_ptr< Parameter > & getSharedParameter (const std::string &name) const
 
double getParameterValue (const std::string &name) const
 
void setAllParametersValues (const ParameterList &parameters)
 
void setParameterValue (const std::string &name, double value)
 
void setParametersValues (const ParameterList &parameters)
 
bool matchParametersValues (const ParameterList &parameters)
 
size_t getNumberOfParameters () const
 
std::string getNamespace () const
 
std::string getParameterNameWithoutNamespace (const std::string &name) const
 

Protected Member Functions

virtual void updateMatrices ()
 
virtual void updateRatesModel ()=0
 Update the rates vector, generator and equilibrium frequencies. More...
 
const std::shared_ptr< Parameter > & getSharedParameter (size_t i) const
 
std::shared_ptr< Parameter > & getSharedParameter (size_t i)
 
void addParameter_ (Parameter *parameter)
 
void addParameters_ (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_ ()
 
void shareParameter_ (const std::shared_ptr< Parameter > &parameter)
 
void shareParameters_ (const ParameterList &parameters)
 
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_ ()
 

Protected Attributes

ReversibleSubstitutionModelmodel_
 
MarkovModulatedStateMap stateMap_
 
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...
 
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_
 

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 state". 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 75 of file MarkovModulatedSubstitutionModel.h.

Constructor & Destructor Documentation

bpp::MarkovModulatedSubstitutionModel::MarkovModulatedSubstitutionModel ( ReversibleSubstitutionModel 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 161 of file MarkovModulatedSubstitutionModel.h.

References bpp::AbstractParameterAliasable::addParameters_(), bpp::ParameterAliasable::getIndependentParameters(), operator=(), and bpp::ParameterAliasable::setNamespace().

MarkovModulatedSubstitutionModel::MarkovModulatedSubstitutionModel ( const MarkovModulatedSubstitutionModel model)

Definition at line 51 of file MarkovModulatedSubstitutionModel.cpp.

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

Definition at line 178 of file MarkovModulatedSubstitutionModel.h.

References clone(), and model_.

Member Function Documentation

MarkovModulatedSubstitutionModel* bpp::MarkovModulatedSubstitutionModel::clone ( ) const
pure virtual
double bpp::MarkovModulatedSubstitutionModel::d2Pij_dt2 ( size_t  i,
size_t  j,
double  t 
) const
inlinevirtual
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::TransitionModel.

Definition at line 225 of file MarkovModulatedSubstitutionModel.h.

References getd2Pij_dt2(), and getInitValue().

double bpp::MarkovModulatedSubstitutionModel::dPij_dt ( size_t  i,
size_t  j,
double  t 
) const
inlinevirtual
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::TransitionModel.

Definition at line 224 of file MarkovModulatedSubstitutionModel.h.

References getdPij_dt().

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

Set if eigenValues and Vectors must be computed.

Implements bpp::SubstitutionModel.

Definition at line 287 of file MarkovModulatedSubstitutionModel.h.

bool bpp::MarkovModulatedSubstitutionModel::enableEigenDecomposition ( )
inlinevirtual

Tell if eigenValues and Vectors must be computed.

Implements bpp::SubstitutionModel.

Definition at line 289 of file MarkovModulatedSubstitutionModel.h.

References eigenDecompose_.

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

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 296 of file MarkovModulatedSubstitutionModel.h.

References bpp::AbstractParameterAliasable::fireParameterChanged(), bpp::ParameterAliasable::matchParametersValues(), setNamespace(), updateMatrices(), and updateRatesModel().

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

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

Implements bpp::TransitionModel.

Definition at line 219 of file MarkovModulatedSubstitutionModel.h.

const Alphabet* bpp::MarkovModulatedSubstitutionModel::getAlphabet ( ) const
inlinevirtual
Returns
Get the alphabet associated to this model.

Implements bpp::TransitionModel.

Definition at line 184 of file MarkovModulatedSubstitutionModel.h.

References bpp::TransitionModel::getAlphabet().

Referenced by getInitValue().

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

Implements bpp::TransitionModel.

Definition at line 192 of file MarkovModulatedSubstitutionModel.h.

References bpp::AbstractStateMap::getAlphabetStateAsChar().

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

Implements bpp::TransitionModel.

Definition at line 194 of file MarkovModulatedSubstitutionModel.h.

References bpp::AbstractStateMap::getAlphabetStateAsInt().

Referenced by getInitValue().

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

Implements bpp::TransitionModel.

Definition at line 190 of file MarkovModulatedSubstitutionModel.h.

References bpp::AbstractStateMap::getAlphabetStates().

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

Implements bpp::SubstitutionModel.

Definition at line 217 of file MarkovModulatedSubstitutionModel.h.

References rightEigenVectors_.

const Matrix< double > & MarkovModulatedSubstitutionModel::getd2Pij_dt2 ( double  t) const
virtual
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::TransitionModel.

Definition at line 194 of file MarkovModulatedSubstitutionModel.cpp.

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

Referenced by d2Pij_dt2(), and getGenerator().

const Matrix< double > & MarkovModulatedSubstitutionModel::getdPij_dt ( double  t) const
virtual
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::TransitionModel.

Definition at line 188 of file MarkovModulatedSubstitutionModel.cpp.

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

Referenced by dPij_dt(), and getGenerator().

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

Implements bpp::SubstitutionModel.

Definition at line 210 of file MarkovModulatedSubstitutionModel.h.

References eigenValues_.

const Matrix<double>& bpp::MarkovModulatedSubstitutionModel::getExchangeabilityMatrix ( ) const
inlinevirtual
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::SubstitutionModel.

Definition at line 202 of file MarkovModulatedSubstitutionModel.h.

References exchangeability_.

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

Implements bpp::TransitionModel.

Definition at line 200 of file MarkovModulatedSubstitutionModel.h.

References freq_.

const Matrix<double>& bpp::MarkovModulatedSubstitutionModel::getGenerator ( ) const
inlinevirtual
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. Additionnaly, the rate_ attibute 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::SubstitutionModel.

Definition at line 204 of file MarkovModulatedSubstitutionModel.h.

References generator_, getd2Pij_dt2(), getdPij_dt(), and getPij_t().

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

Implements bpp::SubstitutionModel.

Definition at line 211 of file MarkovModulatedSubstitutionModel.h.

References iEigenValues_.

double MarkovModulatedSubstitutionModel::getInitValue ( size_t  i,
int  state 
) const
throw (IndexOutOfBoundsException,
BadIntException
)
virtual

This method is used to initialize likelihoods in reccursions. 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::TransitionModel.

Definition at line 202 of file MarkovModulatedSubstitutionModel.cpp.

References bpp::Alphabet::getAlias(), getAlphabet(), bpp::TransitionModel::getAlphabet(), getAlphabetStateAsInt(), bpp::Alphabet::intToChar(), model_, nbRates_, and nbStates_.

Referenced by d2Pij_dt2().

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

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

Definition at line 196 of file MarkovModulatedSubstitutionModel.h.

References bpp::AbstractStateMap::getModelStates().

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

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

Definition at line 198 of file MarkovModulatedSubstitutionModel.h.

References bpp::AbstractStateMap::getModelStates().

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

Get the name of the model.

Returns
The name of this model.

Implemented in bpp::YpR_Gen, bpp::YpR_Sym, bpp::FromMixtureSubstitutionModel, bpp::HKY85, bpp::F84, bpp::KroneckerCodonDistanceFrequenciesSubstitutionModel, bpp::AbstractFromSubstitutionModelTransitionModel, bpp::JCprot, bpp::T92, bpp::KroneckerCodonDistanceSubstitutionModel, bpp::K80, bpp::RE08, bpp::RN95, bpp::MixtureOfSubstitutionModels, bpp::GTR, bpp::TN93, bpp::JCnuc, bpp::CodonDistanceFrequenciesSubstitutionModel, bpp::KroneckerWordSubstitutionModel, bpp::RN95s, bpp::BinarySubstitutionModel, bpp::CodonDistancePhaseFrequenciesSubstitutionModel, bpp::MixtureOfASubstitutionModel, bpp::WordSubstitutionModel, bpp::CodonDistanceCpGSubstitutionModel, bpp::LLG08_EX3, bpp::UserProteinSubstitutionModel, bpp::LLG08_EHO, bpp::LLG08_UL3, bpp::CodonDistanceSubstitutionModel, bpp::LG10_EX_EHO, bpp::LGL08_CAT, bpp::LLG08_EX2, bpp::LLG08_UL2, bpp::SSR, bpp::WAG01, bpp::YNGP_M1, bpp::YNGP_M10, bpp::YNGP_M9, bpp::G2001, bpp::L95, bpp::CodonRateFrequenciesSubstitutionModel, bpp::YNGP_M8, bpp::DSO78, bpp::JTT92, bpp::GY94, bpp::SENCA, bpp::YNGP_M7, bpp::YNGP_M3, bpp::gBGC, bpp::LG08, bpp::YN98, bpp::YNGP_M2, bpp::KCM, bpp::TS98, bpp::TripletSubstitutionModel, bpp::CodonRateSubstitutionModel, bpp::MG94, bpp::Coala, bpp::LLG08_EX3::EmbeddedModel, bpp::LLG08_EHO::EmbeddedModel, bpp::LLG08_UL3::EmbeddedModel, bpp::LG10_EX_EHO::EmbeddedModel, bpp::LGL08_CAT::EmbeddedModel, bpp::LLG08_EX2::EmbeddedModel, and bpp::LLG08_UL2::EmbeddedModel.

Referenced by bpp::AbstractCodonFitnessSubstitutionModel::AbstractCodonFitnessSubstitutionModel(), bpp::AbstractFromSubstitutionModelTransitionModel::getName(), bpp::FromMixtureSubstitutionModel::getName(), bpp::MixtureOfSubstitutionModels::getSubmodelNumbers(), bpp::BppOSubstitutionModelFormat::read(), bpp::BppOSubstitutionModelFormat::readMixed_(), bpp::AbstractBiblioSubstitutionModel::updateMatrices(), and bpp::BppOSubstitutionModelFormat::write().

const ReversibleSubstitutionModel* bpp::MarkovModulatedSubstitutionModel::getNestedModel ( ) const
inline

Definition at line 241 of file MarkovModulatedSubstitutionModel.h.

References model_.

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

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

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

Definition at line 186 of file MarkovModulatedSubstitutionModel.h.

References nbRates_.

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

Implements bpp::TransitionModel.

Definition at line 179 of file MarkovModulatedSubstitutionModel.cpp.

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

Referenced by getGenerator(), and Pij_t().

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 250 of file MarkovModulatedSubstitutionModel.h.

References nbStates_.

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

Get the rate.

Implements bpp::SubstitutionModel.

Reimplemented in bpp::TS98.

Definition at line 255 of file MarkovModulatedSubstitutionModel.h.

References bpp::SubstitutionModel::getRate().

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

Implements bpp::SubstitutionModel.

Definition at line 216 of file MarkovModulatedSubstitutionModel.h.

References leftEigenVectors_.

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

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

Definition at line 275 of file MarkovModulatedSubstitutionModel.h.

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

Referenced by updateMatrices().

const StateMap& bpp::MarkovModulatedSubstitutionModel::getStateMap ( ) const
inlinevirtual
Returns
The mapping of model states with alphabet states.

Implements bpp::TransitionModel.

Definition at line 188 of file MarkovModulatedSubstitutionModel.h.

References stateMap_.

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

Implements bpp::SubstitutionModel.

Definition at line 213 of file MarkovModulatedSubstitutionModel.h.

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

Implements bpp::SubstitutionModel.

Definition at line 214 of file MarkovModulatedSubstitutionModel.h.

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

returns if model is scalable

Implements bpp::SubstitutionModel.

Definition at line 259 of file MarkovModulatedSubstitutionModel.h.

References bpp::SubstitutionModel::isScalable().

Referenced by updateMatrices().

void bpp::MarkovModulatedSubstitutionModel::normalize ( )
inlinevirtual

Normalize the generator.

Implements bpp::SubstitutionModel.

Definition at line 269 of file MarkovModulatedSubstitutionModel.h.

References bpp::SubstitutionModel::normalize(), and updateMatrices().

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

Implements bpp::TransitionModel.

Definition at line 223 of file MarkovModulatedSubstitutionModel.h.

References getPij_t().

double bpp::MarkovModulatedSubstitutionModel::Qij ( size_t  i,
size_t  j 
) const
inlinevirtual
Returns
The rate in the generator of change from state i to state j.
See also
getStates();

Implements bpp::SubstitutionModel.

Definition at line 221 of file MarkovModulatedSubstitutionModel.h.

References generator_.

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

Set equilibrium frequencies.

Parameters
frequenciesThe map of the frequencies to use.

Implements bpp::TransitionModel.

Definition at line 235 of file MarkovModulatedSubstitutionModel.h.

References bpp::TransitionModel::setFreq(), and updateMatrices().

void bpp::MarkovModulatedSubstitutionModel::setFreqFromData ( const SequenceContainer data,
double  pseudoCount = 0 
)
inlinevirtual

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

Definition at line 229 of file MarkovModulatedSubstitutionModel.h.

References bpp::TransitionModel::setFreqFromData(), and updateMatrices().

void MarkovModulatedSubstitutionModel::setNamespace ( const std::string &  prefix)
virtual
void bpp::MarkovModulatedSubstitutionModel::setRate ( double  rate)
inlinevirtual

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

Parameters
ratemust be positive.

Implements bpp::SubstitutionModel.

Reimplemented in bpp::TS98.

Definition at line 257 of file MarkovModulatedSubstitutionModel.h.

References bpp::SubstitutionModel::setRate().

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

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

Implements bpp::SubstitutionModel.

Definition at line 264 of file MarkovModulatedSubstitutionModel.h.

References bpp::SubstitutionModel::setScalable().

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

Multiplies the current generator by the given scale.

Parameters
scalethe scale by which the generator is multiplied.

Implements bpp::SubstitutionModel.

Definition at line 282 of file MarkovModulatedSubstitutionModel.h.

References bpp::SubstitutionModel::setScale(), and updateMatrices().

Referenced by updateMatrices().

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

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

Implements bpp::SubstitutionModel.

Definition at line 220 of file MarkovModulatedSubstitutionModel.h.

References exchangeability_.

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::G2001, and bpp::TS98.

Referenced by fireParameterChanged().

Member Data Documentation

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

Definition at line 139 of file MarkovModulatedSubstitutionModel.h.

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

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

Definition at line 138 of file MarkovModulatedSubstitutionModel.h.

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

bool bpp::MarkovModulatedSubstitutionModel::eigenDecompose_
protected

Tell if the eigen decomposition should be performed.

Definition at line 132 of file MarkovModulatedSubstitutionModel.h.

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

Vdouble bpp::MarkovModulatedSubstitutionModel::eigenValues_
protected

The vector of real parts of eigen values.

Definition at line 121 of file MarkovModulatedSubstitutionModel.h.

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

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

The exchangeability matrix $S$ of the model.

Definition at line 106 of file MarkovModulatedSubstitutionModel.h.

Referenced by getExchangeabilityMatrix(), operator=(), Sij(), and updateMatrices().

Vdouble bpp::MarkovModulatedSubstitutionModel::freq_
protected

The vector of equilibrium frequencies.

Definition at line 144 of file MarkovModulatedSubstitutionModel.h.

Referenced by getFrequencies(), getScale(), operator=(), and updateMatrices().

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

The generator matrix $Q$ of the model.

Definition at line 101 of file MarkovModulatedSubstitutionModel.h.

Referenced by getGenerator(), operator=(), Qij(), and updateMatrices().

Vdouble bpp::MarkovModulatedSubstitutionModel::iEigenValues_
protected

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

Definition at line 127 of file MarkovModulatedSubstitutionModel.h.

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

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

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

Definition at line 111 of file MarkovModulatedSubstitutionModel.h.

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

ReversibleSubstitutionModel* bpp::MarkovModulatedSubstitutionModel::model_
protected
size_t bpp::MarkovModulatedSubstitutionModel::nbRates_
protected
size_t bpp::MarkovModulatedSubstitutionModel::nbStates_
protected
std::string bpp::MarkovModulatedSubstitutionModel::nestedPrefix_
protected

Definition at line 148 of file MarkovModulatedSubstitutionModel.h.

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

bool bpp::MarkovModulatedSubstitutionModel::normalizeRateChanges_
protected

Definition at line 146 of file MarkovModulatedSubstitutionModel.h.

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

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

These ones are for bookkeeping:

Definition at line 137 of file MarkovModulatedSubstitutionModel.h.

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

RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::rates_
protected
RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::ratesExchangeability_
protected
Vdouble bpp::MarkovModulatedSubstitutionModel::ratesFreq_
protected
RowMatrix<double> bpp::MarkovModulatedSubstitutionModel::ratesGenerator_
protected

Definition at line 96 of file MarkovModulatedSubstitutionModel.h.

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

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

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

Definition at line 116 of file MarkovModulatedSubstitutionModel.h.

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

MarkovModulatedStateMap bpp::MarkovModulatedSubstitutionModel::stateMap_
protected

Definition at line 82 of file MarkovModulatedSubstitutionModel.h.

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


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