bpp-phyl3 3.0.0
MixtureOfATransitionModel.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_MODEL_MIXTUREOFATRANSITIONMODEL_H
6#define BPP_PHYL_MODEL_MIXTUREOFATRANSITIONMODEL_H
7
10#include <cstring> // C lib for string copy
11#include <map>
12#include <string>
13#include <vector>
14
16
17namespace bpp
18{
70{
71private:
72 std::map<std::string, std::unique_ptr<DiscreteDistributionInterface>> distributionMap_;
73
74protected:
75 int from_, to_;
76
77public:
79 std::shared_ptr<const Alphabet> alpha,
80 std::unique_ptr<TransitionModelInterface> model,
81 std::map<std::string, std::unique_ptr<DiscreteDistributionInterface>>& parametersDistributionsList,
82 int ffrom = -1, int tto = -1);
83
85
87
89
90 MixtureOfATransitionModel* clone() const override { return new MixtureOfATransitionModel(*this); }
91
92public:
93 std::string getName() const override { return "MixedModel"; }
94
98 const TransitionModelInterface& model(const std::string& name) const override
99 {
100 size_t nbmod = getNumberOfModels();
101
102 for (size_t i = 0; i < nbmod; ++i)
103 {
104 auto& model = nModel(i);
105 if (model.getName() == name)
106 return model;
107 }
108
109 throw NullPointerException("MixtureOfATransitionModel::model(). No model with the specified name.");
110 }
111
112 const TransitionModelInterface& model(size_t i) const
113 {
115 }
116
124 Vuint getSubmodelNumbers(const std::string& desc) const override;
125
131 void setFreq(std::map<int, double>&) override;
132
138 bool hasDistribution(std::string& parName) const
139 {
140 return distributionMap_.find(parName) != distributionMap_.end();
141 }
142
148 const DiscreteDistributionInterface& distribution(std::string& parName) const
149 {
150 if (distributionMap_.find(parName) != distributionMap_.end())
151 return *distributionMap_.find(parName)->second;
152 else
153 throw Exception("MixtureOfATransitionModel::distribution(). No distribution with name: '" + parName + "'.");
154 }
155
156
163 int from() const { return from_; }
164
165 int to() const { return to_; }
166
167protected:
168 void updateMatrices_() override;
169};
170} // end of namespace bpp.
171#endif // BPP_PHYL_MODEL_MIXTUREOFATRANSITIONMODEL_H
Partial implementation for Mixed Transition models, defined as a mixture of "simple" substitution mod...
const TransitionModelInterface & nModel(size_t i) const override
Returns a specific model from the mixture.
virtual size_t getNumberOfModels() const override
returns the number of models in the mixture
virtual std::string getName() const =0
Get the name of the model.
Transition models defined as a mixture of nested substitution models.
std::string getName() const override
Get the name of the model.
int from() const
Numbers of the states between which the substitution rates of all the submodels must be equal....
void updateMatrices_() override
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
Vuint getSubmodelNumbers(const std::string &desc) const override
Returns the vector of numbers of the submodels in the mixture that match a description of the paramet...
const TransitionModelInterface & model(const std::string &name) const override
retrieve a pointer to the submodel with the given name.
const TransitionModelInterface & model(size_t i) const
const DiscreteDistributionInterface & distribution(std::string &parName) const
returns the DiscreteDistribution associated with a given parameter name.
MixtureOfATransitionModel & operator=(const MixtureOfATransitionModel &)
void setFreq(std::map< int, double > &) override
sets the eq frequencies of the first nested model, and adapts the parameters at best to it (surely th...
bool hasDistribution(std::string &parName) const
Tells whether a DiscreteDistribution is associated with a given parameter name.
MixtureOfATransitionModel * clone() const override
std::map< std::string, std::unique_ptr< DiscreteDistributionInterface > > distributionMap_
MixtureOfATransitionModel(std::shared_ptr< const Alphabet > alpha, std::unique_ptr< TransitionModelInterface > model, std::map< std::string, std::unique_ptr< DiscreteDistributionInterface > > &parametersDistributionsList, int ffrom=-1, int tto=-1)
Interface for all transition models.
Defines the basic types of data flow nodes.
std::vector< unsigned int > Vuint