bpp-phyl3  3.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
bpp::MultinomialFromTransitionModel Class Reference

From a model, compute the likelihood of counts given an ancestral state. More...

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

+ Inheritance diagram for bpp::MultinomialFromTransitionModel:
+ Collaboration diagram for bpp::MultinomialFromTransitionModel:

Public Member Functions

 MultinomialFromTransitionModel (std::shared_ptr< TransitionModelInterface > originalModel)
 
 MultinomialFromTransitionModel (const MultinomialFromTransitionModel &fmsm)
 
MultinomialFromTransitionModeloperator= (const MultinomialFromTransitionModel &fmsm)
 
virtual ~MultinomialFromTransitionModel ()
 
MultinomialFromTransitionModelclone () const override
 
void fireParameterChanged (const ParameterList &parameters) override
 
const BranchModelInterfacemodel () const override
 
const TransitionModelInterfacetransitionModel () const
 
const Eigen::VectorXd & Lik_t (const Eigen::VectorXd &from, double t) const override
 
const Eigen::VectorXd & dLik_dt (const Eigen::VectorXd &from, double t) const override
 
const Eigen::VectorXd & d2Lik_dt2 (const Eigen::VectorXd &from, double t) const override
 
void setFreqFromData (const SequenceDataInterface &data, double pseudoCount=0)
 
virtual void setFreq (std::map< int, double > &m)
 
double getRate () const override
 Get the rate. More...
 
void setRate (double rate) override
 Set the rate of the model (must be positive). More...
 
double getInitValue (size_t i, int state) const override
 
std::string getName () const override
 Get the name of the model. More...
 
void addRateParameter () override
 
void setNamespace (const std::string &prefix)
 
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 std::vector< int > & getAlphabetStates () const override
 
const StateMapInterfacestateMap () const override
 
std::shared_ptr< const StateMapInterfacegetStateMap () const override
 
int getAlphabetStateAsInt (size_t i) const override
 
std::string getAlphabetStateAsChar (size_t i) 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 Alphabetalphabet () const override
 
std::shared_ptr< const AlphabetgetAlphabet () const override
 
size_t getNumberOfStates () const override
 Get the number of states. More...
 
const FrequencySetInterfacefrequencySet () const override
 

Protected Member Functions

BranchModelInterfacemodel ()
 
TransitionModelInterfacetransitionModel ()
 
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
 

Private Types

typedef bool lessEigenType(Eigen::VectorXd const &, Eigen::VectorXd const &)
 

Private Member Functions

void compute_Multinomial_ (const Eigen::VectorXd &counts) const
 Fills the res vector of the likelihoods of the counts given ancestral states & transition matrix. More...
 
void compute_dMultinomial_dt_ (const Eigen::VectorXd &counts) const
 
void compute_d2Multinomial_dt2_ (const Eigen::VectorXd &counts) const
 
double getFact_ (const Eigen::VectorXd &counts) const
 Compute the log of the normalization term for the multinomial for any count, and keeps it in a map to avoid recalcultation. More...
 

Static Private Member Functions

static bool lessEigen (Eigen::VectorXd const &a, Eigen::VectorXd const &b)
 
static uint factorial (uint n)
 

Private Attributes

std::shared_ptr< TransitionModelInterfacesubModel_
 The related model. More...
 
size_t size_
 
double tref_
 Reference time to avoid recomuputation of transition matrix when time has not changed. If <0, it means that transition matrix should be recomputed (for ex if parameters have changed). More...
 
const Matrix< double > * Pij_t
 Transition Matrices owned by the submodel. More...
 
const Matrix< double > * dPij_dt
 
const Matrix< double > * d2Pij_dt2
 
Eigen::VectorXd Pi_
 Used return vectors. More...
 
Eigen::VectorXd dPi_
 
Eigen::VectorXd d2Pi_
 
std::map< Eigen::VectorXd, double, bool(*)(const Eigen::VectorXd &, const Eigen::VectorXd &)> mapFact_
 map to store constant values of multinomial More...
 
ParameterList independentParameters_
 
std::map< std::string, std::shared_ptr< AliasParameterListener > > aliasListenersRegister_
 
ParameterList parameters_
 
std::string prefix_
 

Detailed Description

From a model, compute the likelihood of counts given an ancestral state.

It has the same parameters as the SubModel.

If counts are not integers, rounded values are used.

Definition at line 30 of file MultinomialFromTransitionModel.h.

Member Typedef Documentation

◆ lessEigenType

typedef bool bpp::MultinomialFromTransitionModel::lessEigenType(Eigen::VectorXd const &, Eigen::VectorXd const &)
private

Definition at line 33 of file MultinomialFromTransitionModel.h.

Constructor & Destructor Documentation

◆ MultinomialFromTransitionModel() [1/2]

bpp::MultinomialFromTransitionModel::MultinomialFromTransitionModel ( std::shared_ptr< TransitionModelInterface originalModel)
inline

◆ MultinomialFromTransitionModel() [2/2]

bpp::MultinomialFromTransitionModel::MultinomialFromTransitionModel ( const MultinomialFromTransitionModel fmsm)
inline

Definition at line 109 of file MultinomialFromTransitionModel.h.

◆ ~MultinomialFromTransitionModel()

virtual bpp::MultinomialFromTransitionModel::~MultinomialFromTransitionModel ( )
inlinevirtual

Definition at line 133 of file MultinomialFromTransitionModel.h.

Member Function Documentation

◆ addRateParameter()

◆ alphabet()

const Alphabet& bpp::AbstractWrappedModel::alphabet ( ) const
inlineoverridevirtualinherited

◆ clone()

MultinomialFromTransitionModel* bpp::MultinomialFromTransitionModel::clone ( ) const
inlineoverridevirtual

◆ compute_d2Multinomial_dt2_()

void MultinomialFromTransitionModel::compute_d2Multinomial_dt2_ ( const Eigen::VectorXd &  counts) const
private

Definition at line 54 of file MultinomialFromTransitionModel.cpp.

References bpp::exp(), and bpp::numeric::log().

◆ compute_dMultinomial_dt_()

void MultinomialFromTransitionModel::compute_dMultinomial_dt_ ( const Eigen::VectorXd &  counts) const
private

Definition at line 33 of file MultinomialFromTransitionModel.cpp.

References bpp::exp(), and bpp::numeric::log().

◆ compute_Multinomial_()

void MultinomialFromTransitionModel::compute_Multinomial_ ( const Eigen::VectorXd &  counts) const
private

Fills the res vector of the likelihoods of the counts given ancestral states & transition matrix.

Definition at line 14 of file MultinomialFromTransitionModel.cpp.

References bpp::exp(), and bpp::numeric::log().

◆ d2Lik_dt2()

const Eigen::VectorXd & MultinomialFromTransitionModel::d2Lik_dt2 ( const Eigen::VectorXd &  from,
double  t 
) const
overridevirtual

Implements bpp::BranchModelInterface.

Definition at line 106 of file MultinomialFromTransitionModel.cpp.

References to().

◆ dLik_dt()

const Eigen::VectorXd & MultinomialFromTransitionModel::dLik_dt ( const Eigen::VectorXd &  from,
double  t 
) const
overridevirtual

Implements bpp::BranchModelInterface.

Definition at line 89 of file MultinomialFromTransitionModel.cpp.

References to().

◆ factorial()

static uint bpp::MultinomialFromTransitionModel::factorial ( uint  n)
inlinestaticprivate

Definition at line 195 of file MultinomialFromTransitionModel.h.

◆ fireParameterChanged()

void bpp::MultinomialFromTransitionModel::fireParameterChanged ( const ParameterList parameters)
inlineoverridevirtual

◆ frequencySet()

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

Implements bpp::BranchModelInterface.

Reimplemented in bpp::RegisterRatesSubstitutionModel, bpp::OneChangeTransitionModel, bpp::OneChangeRegisterTransitionModel, bpp::YN98, and bpp::AbstractWrappedTransitionModel.

Definition at line 59 of file AbstractWrappedModel.h.

References bpp::BranchModelInterface::frequencySet(), and bpp::WrappedModelInterface::model().

Referenced by bpp::YN98::frequencySet().

◆ getAlphabet()

std::shared_ptr<const Alphabet> bpp::AbstractWrappedModel::getAlphabet ( ) const
inlineoverridevirtualinherited

◆ getAlphabetStateAsChar()

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

Implements bpp::BranchModelInterface.

Reimplemented in bpp::RegisterRatesSubstitutionModel.

Definition at line 46 of file AbstractWrappedModel.h.

References bpp::BranchModelInterface::getAlphabetStateAsChar(), and bpp::WrappedModelInterface::model().

Referenced by bpp::RegisterRatesSubstitutionModel::getAlphabetStateAsChar().

◆ getAlphabetStateAsInt()

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

Implements bpp::BranchModelInterface.

Reimplemented in bpp::RegisterRatesSubstitutionModel.

Definition at line 44 of file AbstractWrappedModel.h.

References bpp::BranchModelInterface::getAlphabetStateAsInt(), and bpp::WrappedModelInterface::model().

Referenced by bpp::RegisterRatesSubstitutionModel::getAlphabetStateAsInt().

◆ getAlphabetStates()

const std::vector<int>& bpp::AbstractWrappedModel::getAlphabetStates ( ) const
inlineoverridevirtualinherited

@ brief Methods to supersede TransitionModel methods.

Implements bpp::BranchModelInterface.

Reimplemented in bpp::RegisterRatesSubstitutionModel.

Definition at line 38 of file AbstractWrappedModel.h.

References bpp::BranchModelInterface::getAlphabetStates(), and bpp::WrappedModelInterface::model().

Referenced by bpp::RegisterRatesSubstitutionModel::getAlphabetStates().

◆ getFact_()

double bpp::MultinomialFromTransitionModel::getFact_ ( const Eigen::VectorXd &  counts) const
inlineprivate

Compute the log of the normalization term for the multinomial for any count, and keeps it in a map to avoid recalcultation.

Definition at line 206 of file MultinomialFromTransitionModel.h.

References mapFact_.

◆ getInitValue()

double bpp::MultinomialFromTransitionModel::getInitValue ( size_t  i,
int  state 
) const
inlineoverridevirtual

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 173 of file MultinomialFromTransitionModel.h.

References bpp::BranchModelInterface::getInitValue(), and transitionModel().

◆ getModelStates() [1/2]

std::vector<size_t> bpp::AbstractWrappedModel::getModelStates ( const std::string &  code) const
inlineoverridevirtualinherited

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.

Reimplemented in bpp::RegisterRatesSubstitutionModel.

Definition at line 50 of file AbstractWrappedModel.h.

References bpp::BranchModelInterface::getModelStates(), and bpp::WrappedModelInterface::model().

◆ getModelStates() [2/2]

std::vector<size_t> bpp::AbstractWrappedModel::getModelStates ( int  code) const
inlineoverridevirtualinherited

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.

Reimplemented in bpp::RegisterRatesSubstitutionModel.

Definition at line 48 of file AbstractWrappedModel.h.

References bpp::BranchModelInterface::getModelStates(), and bpp::WrappedModelInterface::model().

Referenced by bpp::RegisterRatesSubstitutionModel::getModelStates().

◆ getName()

std::string bpp::MultinomialFromTransitionModel::getName ( ) const
inlineoverridevirtual

Get the name of the model.

Returns
The name of this model.

Reimplemented from bpp::AbstractWrappedModel.

Definition at line 175 of file MultinomialFromTransitionModel.h.

◆ getNumberOfStates()

size_t bpp::AbstractWrappedModel::getNumberOfStates ( ) const
inlineoverridevirtualinherited

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.

Reimplemented in bpp::RegisterRatesSubstitutionModel.

Definition at line 57 of file AbstractWrappedModel.h.

References bpp::BranchModelInterface::getNumberOfStates(), and bpp::WrappedModelInterface::model().

◆ getRate()

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

Get the rate.

Implements bpp::BranchModelInterface.

Definition at line 169 of file MultinomialFromTransitionModel.h.

References bpp::BranchModelInterface::getRate(), and transitionModel().

Referenced by addRateParameter().

◆ getStateMap()

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

Implements bpp::BranchModelInterface.

Reimplemented in bpp::RegisterRatesSubstitutionModel.

Definition at line 42 of file AbstractWrappedModel.h.

References bpp::BranchModelInterface::getStateMap(), and bpp::WrappedModelInterface::model().

Referenced by bpp::RegisterRatesSubstitutionModel::getStateMap().

◆ lessEigen()

static bool bpp::MultinomialFromTransitionModel::lessEigen ( Eigen::VectorXd const &  a,
Eigen::VectorXd const &  b 
)
inlinestaticprivate

Definition at line 75 of file MultinomialFromTransitionModel.h.

◆ Lik_t()

const Eigen::VectorXd & MultinomialFromTransitionModel::Lik_t ( const Eigen::VectorXd &  values,
double  t 
) const
overridevirtual

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.
ttime
Exceptions
IndexOutOfBoundsExceptionif array position is out of range.
BadIntExceptionif states are not allowed in the associated alphabet.

Implements bpp::BranchModelInterface.

Definition at line 76 of file MultinomialFromTransitionModel.cpp.

References to().

◆ model() [1/2]

BranchModelInterface& bpp::MultinomialFromTransitionModel::model ( )
inlineprotected

Definition at line 87 of file MultinomialFromTransitionModel.h.

References subModel_.

Referenced by addRateParameter(), and fireParameterChanged().

◆ model() [2/2]

const BranchModelInterface& bpp::MultinomialFromTransitionModel::model ( ) const
inlineoverridevirtual

Implements bpp::WrappedModelInterface.

Definition at line 145 of file MultinomialFromTransitionModel.h.

References subModel_.

◆ operator=()

MultinomialFromTransitionModel& bpp::MultinomialFromTransitionModel::operator= ( const MultinomialFromTransitionModel fmsm)
inline

◆ setFreq()

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

◆ setFreqFromData()

void bpp::MultinomialFromTransitionModel::setFreqFromData ( const SequenceDataInterface data,
double  pseudoCount = 0 
)
inline

◆ setRate()

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

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

Parameters
ratemust be positive.

Implements bpp::BranchModelInterface.

Definition at line 171 of file MultinomialFromTransitionModel.h.

References bpp::BranchModelInterface::setRate(), and transitionModel().

◆ stateMap()

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

Implements bpp::BranchModelInterface.

Reimplemented in bpp::RegisterRatesSubstitutionModel.

Definition at line 40 of file AbstractWrappedModel.h.

References bpp::WrappedModelInterface::model(), and bpp::BranchModelInterface::stateMap().

Referenced by bpp::RegisterRatesSubstitutionModel::stateMap().

◆ transitionModel() [1/2]

TransitionModelInterface& bpp::MultinomialFromTransitionModel::transitionModel ( )
inlineprotected

Definition at line 92 of file MultinomialFromTransitionModel.h.

References subModel_.

Referenced by getInitValue(), getRate(), setFreq(), setFreqFromData(), and setRate().

◆ transitionModel() [2/2]

const TransitionModelInterface& bpp::MultinomialFromTransitionModel::transitionModel ( ) const
inline

Definition at line 150 of file MultinomialFromTransitionModel.h.

References subModel_.

Member Data Documentation

◆ d2Pi_

Eigen::VectorXd bpp::MultinomialFromTransitionModel::d2Pi_
private

Definition at line 68 of file MultinomialFromTransitionModel.h.

Referenced by operator=().

◆ d2Pij_dt2

const Matrix<double> * bpp::MultinomialFromTransitionModel::d2Pij_dt2
private

Definition at line 63 of file MultinomialFromTransitionModel.h.

◆ dPi_

Eigen::VectorXd bpp::MultinomialFromTransitionModel::dPi_
private

Definition at line 68 of file MultinomialFromTransitionModel.h.

Referenced by operator=().

◆ dPij_dt

const Matrix<double> * bpp::MultinomialFromTransitionModel::dPij_dt
private

Definition at line 63 of file MultinomialFromTransitionModel.h.

◆ mapFact_

std::map<Eigen::VectorXd, double, bool (*)(const Eigen::VectorXd&, const Eigen::VectorXd&)> bpp::MultinomialFromTransitionModel::mapFact_
mutableprivate

map to store constant values of multinomial

Definition at line 73 of file MultinomialFromTransitionModel.h.

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

◆ Pi_

Eigen::VectorXd bpp::MultinomialFromTransitionModel::Pi_
mutableprivate

Used return vectors.

Definition at line 68 of file MultinomialFromTransitionModel.h.

Referenced by operator=().

◆ Pij_t

const Matrix<double>* bpp::MultinomialFromTransitionModel::Pij_t
mutableprivate

Transition Matrices owned by the submodel.

These ones are for bookkeeping:

Definition at line 63 of file MultinomialFromTransitionModel.h.

◆ size_

size_t bpp::MultinomialFromTransitionModel::size_
private

Definition at line 46 of file MultinomialFromTransitionModel.h.

Referenced by operator=().

◆ subModel_

std::shared_ptr<TransitionModelInterface> bpp::MultinomialFromTransitionModel::subModel_
private

The related model.

Definition at line 39 of file MultinomialFromTransitionModel.h.

Referenced by model(), MultinomialFromTransitionModel(), operator=(), and transitionModel().

◆ tref_

double bpp::MultinomialFromTransitionModel::tref_
mutableprivate

Reference time to avoid recomuputation of transition matrix when time has not changed. If <0, it means that transition matrix should be recomputed (for ex if parameters have changed).

Definition at line 54 of file MultinomialFromTransitionModel.h.

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


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