bpp-phyl  2.2.0
bpp::MixedSubstitutionModelSet Class Reference

Substitution models manager for Mixed Substitution Models. This class inherits from SubstitutionModelSet. More...

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

+ Inheritance diagram for bpp::MixedSubstitutionModelSet:
+ Collaboration diagram for bpp::MixedSubstitutionModelSet:

Classes

class  HyperNode
 

Public Member Functions

 MixedSubstitutionModelSet (const Alphabet *alpha)
 Create a model set according to the specified alphabet. More...
 
 ~MixedSubstitutionModelSet ()
 
 MixedSubstitutionModelSet (const MixedSubstitutionModelSet &set)
 
 MixedSubstitutionModelSet (const SubstitutionModelSet &set)
 
MixedSubstitutionModelSetoperator= (const MixedSubstitutionModelSet &set)
 
MixedSubstitutionModelSetclone () const
 
void clear ()
 Resets the list of the HyperNodes. More...
 
void addEmptyHyperNode ()
 
void addHyperNode (const HyperNode &hn)
 
bool complete ()
 
void addToHyperNode (size_t nM, const Vint &vnS, int nH=-1)
 
size_t getNumberOfHyperNodes () const
 
HyperNodegetHyperNode (size_t i)
 
const HyperNodegetHyperNode (size_t i) const
 
bool hasExclusivePaths () const
 
void fireParameterChanged (const ParameterList &parameters)
 
void computeHyperNodesProbabilities ()
 
double getHyperNodeProbability (const HyperNode &hn) const
 
void setRootFrequencies (FrequenciesSet *rootFreqs)
 Sets a given FrequenciesSet for root frequencies. More...
 
size_t getNumberOfStates () const throw (Exception)
 Get the number of states associated to this model set. More...
 
size_t getNumberOfModels () const
 
bool hasMixedSubstitutionModel () const
 
const SubstitutionModelgetModel (size_t i) const throw (IndexOutOfBoundsException)
 Get one model from the set knowing its index. More...
 
SubstitutionModelgetModel (size_t i) throw (IndexOutOfBoundsException)
 
size_t getModelIndexForNode (int nodeId) const throw (Exception)
 Get the index in the set of the model associated to a particular node id. More...
 
const SubstitutionModelgetModelForNode (int nodeId) const throw (Exception)
 Get the model associated to a particular node id. More...
 
SubstitutionModelgetModelForNode (int nodeId) throw (Exception)
 
const std::vector< int > & getNodesWithModel (size_t i) const throw (IndexOutOfBoundsException)
 Get a list of nodes id for which the given model is associated. More...
 
std::vector< int > getNodesWithParameter (const std::string &name) const throw (ParameterNotFoundException)
 
void addModel (SubstitutionModel *model, const std::vector< int > &nodesId)
 Add a new model to the set, and set relationships with nodes and params. More...
 
void replaceModel (size_t modelIndex, SubstitutionModel *model) throw (Exception)
 Replace a model in the set, and all corresponding parameters. The replaced model deleted. More...
 
void listModelNames (std::ostream &out=std::cout) const
 
const FrequenciesSetgetRootFrequenciesSet () const
 
std::vector< double > getRootFrequencies () const
 
ParameterList getRootFrequenciesParameters () const
 Get the parameters corresponding to the root frequencies. More...
 
ParameterList getNodeParameters () const
 Get the parameters corresponding attached to the nodes of the tree. More...
 
ParameterList getModelParameters (size_t modelIndex) const
 Get the parameters attached to a Model. More...
 
const Alphabet * getAlphabet () const
 
virtual const std::vector< int > & getAlphabetStates () const
 
virtual const StateMapgetStateMap () const
 
virtual std::vector< size_t > getModelStates (int code) const
 
virtual std::vector< size_t > getModelStates (const std::string &code) const
 
virtual int getAlphabetStateAsInt (size_t index) const
 
virtual std::string getAlphabetStateAsChar (size_t index) const
 
bool isFullySetUpFor (const Tree &tree, bool throwEx=true) const throw (Exception)
 Check if the model set is fully specified for a given tree. More...
 

Protected Member Functions

void updateRootFrequencies ()
 
Check function.
bool checkOrphanModels (bool throwEx) const throw (Exception)
 
bool checkOrphanNodes (const Tree &tree, bool throwEx) const throw (Exception)
 
bool checkUnknownNodes (const Tree &tree, bool throwEx) const throw (Exception)
 

Protected Attributes

const Alphabet * alphabet_
 A pointer toward the common alphabet to all models in the set. More...
 
size_t nbStates_
 
std::vector< SubstitutionModel * > modelSet_
 Contains all models used in this tree. More...
 

Private Attributes

std::vector< HyperNode * > vpHyperNodes_
 

Detailed Description

Substitution models manager for Mixed Substitution Models. This class inherits from SubstitutionModelSet.

This class is done to handle specific cases of choices among the submodels of mixed substitution models. Each branch of the tree is labelled by a mixed model, and a site may be restricted to a set of submodels it is allowed to follow. These sets are defined through an hypergrap, ie a list of hypernodes.

For example, suppose there are 3 mixed models (M1,M2 and M3), with 2, 3, 4 submodels (S1, S2, ...) each.

If the sites are allowed to follow any combination of submodels (12 combinations) the corresponding hypergraph has only one hypernode: (<1,2>,<1,2,3>,<1,2,3,4>).

The hypergraph with hypernodes ((<1>,<1,2>,<1,2>),(<2>,<3>,<3,4>)) means that a site either follows 6 combinations:

M1:S1, M2:S1 or M2:S2, and M3:S1 or M3:S2.

or

M1:S2, M2:S3, and M3:S3 or M3:S4.

Actually, additional coordinates are set when there are non mixed models, with no value in them, and not used in practice.

An hypernode is valid only if each mixed model is represented at least by one submodel.

Dependency of the submodels entails constraints in the probabilities of the submodels, and definition of the hypernodes must be taken with care for the whole modelling to be possible.

In this implementation, for sake of simplification (and for reason of time), all the submodels must belong to exactly one given hypernode, but in theory more complex dependencies are possible.

Concerning the probabilities of the submodels in each hypernode, the first coordinate (ie set of submodels inside a mixed model) in the list defines the probability of each hypernode. For each coordinate (the first included), when there are several submodels, their probabilities are conditional probabilities, which means that they sum 1 and their ratio are unchanged.

For instance, for hypergraph ((<1>,<1,2>,<1,2>),(<2>,<3>,<3,4>)), the probabilities of hypernodes are the probabilities of M1:S1 and M1:S2. In the first hypernode, the probabilities of M2:S1 and M2:S2 are P(M2:S1)/(P(M2:S1)+P(M2:S2)) and P(M2:S2)/(P(M2:S1)+P(M2:S2)).

We do not certify that the probability parameters of the mixed models are all useful, and then identifiability problems may be encountered.

There is a method ("complete") that creates an additional hypernode to ensure that all submodels belong to at least an hypernode.

Definition at line 121 of file MixedSubstitutionModelSet.h.

Constructor & Destructor Documentation

◆ MixedSubstitutionModelSet() [1/3]

bpp::MixedSubstitutionModelSet::MixedSubstitutionModelSet ( const Alphabet *  alpha)
inline

Create a model set according to the specified alphabet.

Parameters
alphaThe alphabet to use for this set.

Definition at line 286 of file MixedSubstitutionModelSet.h.

Referenced by clone().

◆ ~MixedSubstitutionModelSet()

MixedSubstitutionModelSet::~MixedSubstitutionModelSet ( )

Definition at line 62 of file MixedSubstitutionModelSet.cpp.

References vpHyperNodes_.

◆ MixedSubstitutionModelSet() [2/3]

MixedSubstitutionModelSet::MixedSubstitutionModelSet ( const MixedSubstitutionModelSet set)

Definition at line 47 of file MixedSubstitutionModelSet.cpp.

References vpHyperNodes_.

◆ MixedSubstitutionModelSet() [3/3]

MixedSubstitutionModelSet::MixedSubstitutionModelSet ( const SubstitutionModelSet set)

Definition at line 57 of file MixedSubstitutionModelSet.cpp.

Member Function Documentation

◆ addEmptyHyperNode()

◆ addHyperNode()

void MixedSubstitutionModelSet::addHyperNode ( const HyperNode hn)

Definition at line 102 of file MixedSubstitutionModelSet.cpp.

References vpHyperNodes_.

◆ addModel()

void SubstitutionModelSet::addModel ( SubstitutionModel model,
const std::vector< int > &  nodesId 
)
inherited

Add a new model to the set, and set relationships with nodes and params.

Parameters
modelA pointer toward a susbstitution model, that will added to the set. Warning! The set will now be the owner of the pointer, and will destroy it if needed! Copy the model first if you don't want it to be lost!
nodesIdthe set of nodes in the tree that points toward this model. This will override any previous affectation.
Exceptions
Exceptionin case of error:
  • if the new model does not match the alphabet
  • if the new model does not have the same number of states than existing ones
  • etc.

Definition at line 135 of file SubstitutionModelSet.cpp.

References bpp::SubstitutionModelSet::alphabet_, bpp::SubstitutionModel::clone(), bpp::SubstitutionModel::getAlphabet(), bpp::SubstitutionModel::getNumberOfStates(), bpp::SubstitutionModelSet::modelParameters_, bpp::SubstitutionModelSet::modelSet_, bpp::SubstitutionModelSet::modelToNodes_, bpp::SubstitutionModelSet::nbStates_, and bpp::SubstitutionModelSet::nodeToModel_.

Referenced by bpp::SubstitutionModelSetTools::createHomogeneousModelSet(), bpp::SubstitutionModelSetTools::createNonHomogeneousModelSet(), and bpp::PhylogeneticsApplicationTools::setSubstitutionModelSet().

◆ addToHyperNode()

void MixedSubstitutionModelSet::addToHyperNode ( size_t  nM,
const Vint &  vnS,
int  nH = -1 
)

◆ checkOrphanModels()

bool SubstitutionModelSet::checkOrphanModels ( bool  throwEx) const
throw (Exception
)
protectedinherited

◆ checkOrphanNodes()

bool SubstitutionModelSet::checkOrphanNodes ( const Tree tree,
bool  throwEx 
) const
throw (Exception
)
protectedinherited

◆ checkUnknownNodes()

bool SubstitutionModelSet::checkUnknownNodes ( const Tree tree,
bool  throwEx 
) const
throw (Exception
)
protectedinherited

◆ clear()

void MixedSubstitutionModelSet::clear ( )

Resets the list of the HyperNodes.

Definition at line 70 of file MixedSubstitutionModelSet.cpp.

References bpp::SubstitutionModelSet::clear(), and vpHyperNodes_.

◆ clone()

MixedSubstitutionModelSet* bpp::MixedSubstitutionModelSet::clone ( ) const
inline

Definition at line 303 of file MixedSubstitutionModelSet.h.

References MixedSubstitutionModelSet().

◆ complete()

◆ computeHyperNodesProbabilities()

◆ fireParameterChanged()

void MixedSubstitutionModelSet::fireParameterChanged ( const ParameterList &  parameters)
virtual

To be called when a parameter has changed. Depending on parameters, this will actualize the _initialFrequencies vector or the corresponding models in the set.

Parameters
parametersThe modified parameters.

Reimplemented from bpp::SubstitutionModelSet.

Definition at line 186 of file MixedSubstitutionModelSet.cpp.

References computeHyperNodesProbabilities(), and bpp::SubstitutionModelSet::fireParameterChanged().

◆ getAlphabet()

const Alphabet* bpp::SubstitutionModelSet::getAlphabet ( ) const
inlineinherited

◆ getAlphabetStateAsChar()

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

Definition at line 445 of file SubstitutionModelSet.h.

References bpp::SubstitutionModel::getAlphabetStateAsChar(), and bpp::SubstitutionModelSet::getModel().

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

◆ getAlphabetStateAsInt()

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

Definition at line 437 of file SubstitutionModelSet.h.

References bpp::SubstitutionModel::getAlphabetStateAsInt(), and bpp::SubstitutionModelSet::getModel().

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

◆ getAlphabetStates()

virtual const std::vector<int>& bpp::SubstitutionModelSet::getAlphabetStates ( ) const
inlinevirtualinherited
Returns
The supported states of the model set, as a vector of int codes.
See also
Alphabet

Definition at line 417 of file SubstitutionModelSet.h.

References bpp::SubstitutionModel::getAlphabetStates(), and bpp::SubstitutionModelSet::getModel().

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

◆ getHyperNode() [1/2]

HyperNode& bpp::MixedSubstitutionModelSet::getHyperNode ( size_t  i)
inline

◆ getHyperNode() [2/2]

const HyperNode& bpp::MixedSubstitutionModelSet::getHyperNode ( size_t  i) const
inline

Definition at line 353 of file MixedSubstitutionModelSet.h.

References vpHyperNodes_.

◆ getHyperNodeProbability()

◆ getModel() [1/2]

◆ getModel() [2/2]

SubstitutionModel* bpp::SubstitutionModelSet::getModel ( size_t  i)
throw (IndexOutOfBoundsException
)
inlineinherited

Definition at line 257 of file SubstitutionModelSet.h.

References bpp::SubstitutionModelSet::modelSet_.

◆ getModelForNode() [1/2]

const SubstitutionModel* bpp::SubstitutionModelSet::getModelForNode ( int  nodeId) const
throw (Exception
)
inlineinherited

◆ getModelForNode() [2/2]

SubstitutionModel* bpp::SubstitutionModelSet::getModelForNode ( int  nodeId)
throw (Exception
)
inlineinherited

◆ getModelIndexForNode()

size_t bpp::SubstitutionModelSet::getModelIndexForNode ( int  nodeId) const
throw (Exception
)
inlineinherited

Get the index in the set of the model associated to a particular node id.

Parameters
nodeIdThe id of the query node.
Returns
The index of the model associated to the given node.
Exceptions
ExceptionIf no model is found for this node.

Definition at line 270 of file SubstitutionModelSet.h.

References bpp::SubstitutionModelSet::nodeToModel_.

Referenced by bpp::RNonHomogeneousMixedTreeLikelihood::computeTransitionProbabilitiesForNode().

◆ getModelParameters()

ParameterList bpp::SubstitutionModelSet::getModelParameters ( size_t  modelIndex) const
inherited

Get the parameters attached to a Model.

Parameters
modelIndexthe index of the model in the set
Returns
The parameters attached to the model.

◆ getModelStates() [1/2]

virtual std::vector<size_t> bpp::SubstitutionModelSet::getModelStates ( int  code) const
inlinevirtualinherited

◆ getModelStates() [2/2]

virtual std::vector<size_t> bpp::SubstitutionModelSet::getModelStates ( const std::string &  code) const
inlinevirtualinherited

◆ getNodeParameters()

ParameterList bpp::SubstitutionModelSet::getNodeParameters ( ) const
inlineinherited

Get the parameters corresponding attached to the nodes of the tree.

That is, all the parameters without the root frequencies.

Returns
The parameters attached to the nodes of the tree.

Definition at line 389 of file SubstitutionModelSet.h.

References bpp::SubstitutionModelSet::rootFrequencies_, and bpp::SubstitutionModelSet::stationarity_.

Referenced by bpp::DRNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousTreeLikelihood::fireParameterChanged(), and bpp::RNonHomogeneousMixedTreeLikelihood::fireParameterChanged().

◆ getNodesWithModel()

const std::vector<int>& bpp::SubstitutionModelSet::getNodesWithModel ( size_t  i) const
throw (IndexOutOfBoundsException
)
inlineinherited

Get a list of nodes id for which the given model is associated.

Parameters
iThe index of the model in the set.
Returns
A vector with the ids of the node associated to this model.
Exceptions
IndexOutOfBoundsExceptionIf the index is not valid.

Definition at line 307 of file SubstitutionModelSet.h.

References bpp::SubstitutionModelSet::modelSet_, and bpp::SubstitutionModelSet::modelToNodes_.

Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::ConstNonHomogeneousSiteModelIterator::ConstNonHomogeneousSiteModelIterator(), bpp::SubstitutionMappingTools::getNormalizationsPerBranch(), bpp::RNonHomogeneousMixedTreeLikelihood::init(), and bpp::PhylogeneticsApplicationTools::printParameters().

◆ getNodesWithParameter()

std::vector< int > SubstitutionModelSet::getNodesWithParameter ( const std::string &  name) const
throw (ParameterNotFoundException
)
inherited
Parameters
nameThe name of the parameter to look for.
Returns
The list of nodes with a model containing the specified parameter.
Exceptions
ParameterNotFoundExceptionIf no parameter with the specified name is found.

Definition at line 115 of file SubstitutionModelSet.cpp.

Referenced by bpp::DRNonHomogeneousTreeLikelihood::fireParameterChanged(), bpp::RNonHomogeneousTreeLikelihood::fireParameterChanged(), and bpp::RNonHomogeneousMixedTreeLikelihood::fireParameterChanged().

◆ getNumberOfHyperNodes()

size_t bpp::MixedSubstitutionModelSet::getNumberOfHyperNodes ( ) const
inline

◆ getNumberOfModels()

◆ getNumberOfStates()

size_t bpp::SubstitutionModelSet::getNumberOfStates ( ) const
throw (Exception
)
inlineinherited

Get the number of states associated to this model set.

Returns
The number of states.
Exceptions
Exceptionif no model is associated to the set.

Definition at line 222 of file SubstitutionModelSet.h.

References bpp::SubstitutionModelSet::nbStates_.

Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getNumberOfStates().

◆ getRootFrequencies()

◆ getRootFrequenciesParameters()

ParameterList bpp::SubstitutionModelSet::getRootFrequenciesParameters ( ) const
inlineinherited

Get the parameters corresponding to the root frequencies.

Returns
The parameters corresponding to the root frequencies.

Definition at line 374 of file SubstitutionModelSet.h.

References bpp::SubstitutionModelSet::rootFrequencies_, and bpp::SubstitutionModelSet::stationarity_.

Referenced by bpp::AbstractNonHomogeneousTreeLikelihood::getRootFrequenciesParameters().

◆ getRootFrequenciesSet()

const FrequenciesSet* bpp::SubstitutionModelSet::getRootFrequenciesSet ( ) const
inlineinherited
Returns
The set of root frequencies.

Definition at line 356 of file SubstitutionModelSet.h.

References bpp::SubstitutionModelSet::rootFrequencies_.

Referenced by bpp::PhylogeneticsApplicationTools::printParameters().

◆ getStateMap()

virtual const StateMap& bpp::SubstitutionModelSet::getStateMap ( ) const
inlinevirtualinherited

◆ hasExclusivePaths()

◆ hasMixedSubstitutionModel()

bool SubstitutionModelSet::hasMixedSubstitutionModel ( ) const
inherited

◆ isFullySetUpFor()

bool bpp::SubstitutionModelSet::isFullySetUpFor ( const Tree tree,
bool  throwEx = true 
) const
throw (Exception
)
inlineinherited

Check if the model set is fully specified for a given tree.

This include:

  • that each node as a model set up,
  • that each model in the set is attributed to a node,
  • that each parameter in the set actually correspond to a model.
  • all nodes ids in the set refer to an existing node in the tree.
Parameters
treeThe tree to check.
throwExTell if an exception have to be thrown in case of test not passed.

Definition at line 461 of file SubstitutionModelSet.h.

References bpp::SubstitutionModelSet::checkOrphanModels(), bpp::SubstitutionModelSet::checkOrphanNodes(), and bpp::SubstitutionModelSet::checkUnknownNodes().

Referenced by bpp::RNonHomogeneousMixedTreeLikelihood::RNonHomogeneousMixedTreeLikelihood().

◆ listModelNames()

void SubstitutionModelSet::listModelNames ( std::ostream &  out = std::cout) const
inherited

◆ operator=()

MixedSubstitutionModelSet & MixedSubstitutionModelSet::operator= ( const MixedSubstitutionModelSet set)

◆ replaceModel()

void SubstitutionModelSet::replaceModel ( size_t  modelIndex,
SubstitutionModel model 
)
throw (Exception
)
inherited

Replace a model in the set, and all corresponding parameters. The replaced model deleted.

Parameters
modelIndexThe index of the model in the set.
modelthe new model. This model will be owned by the Set.
Exceptions
Exceptionif a parameter becomes orphan because of the removal.

Definition at line 169 of file SubstitutionModelSet.cpp.

◆ setRootFrequencies()

◆ updateRootFrequencies()

void bpp::SubstitutionModelSet::updateRootFrequencies ( )
inlineprotectedinherited

Member Data Documentation

◆ alphabet_

const Alphabet* bpp::SubstitutionModelSet::alphabet_
protectedinherited

A pointer toward the common alphabet to all models in the set.

Definition at line 111 of file SubstitutionModelSet.h.

Referenced by bpp::SubstitutionModelSet::addModel(), bpp::SubstitutionModelSet::getAlphabet(), and bpp::SubstitutionModelSet::operator=().

◆ modelSet_

◆ nbStates_

size_t bpp::SubstitutionModelSet::nbStates_
protectedinherited

◆ vpHyperNodes_


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