bpp-phyl3 3.0.0
MixtureOfASubstitutionModel.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_MIXTUREOFASUBSTITUTIONMODEL_H
6#define BPP_PHYL_MODEL_MIXTUREOFASUBSTITUTIONMODEL_H
7
9#include <cstring> // C lib for string copy
10#include <map>
11#include <string>
12#include <vector>
13
15
16namespace bpp
17{
20{
21public:
37 std::shared_ptr<const Alphabet> alpha,
38 std::unique_ptr<SubstitutionModelInterface> model,
39 std::map<std::string, std::unique_ptr<DiscreteDistributionInterface>>& parametersDistributionsList,
40 int ffrom = -1,
41 int tto = -1) :
44 MixtureOfATransitionModel(alpha, std::move(model), parametersDistributionsList, ffrom, tto)
45 {}
46
51 {}
52
53
55 {
57 return *this;
58 }
59
60 MixtureOfASubstitutionModel* clone() const override { return new MixtureOfASubstitutionModel(*this); }
61
62protected:
63 void updateMatrices_() override
64 {
66 // setting the rates, if to_ & from_ are different from -1
67
68 if (to_ >= 0 && from_ >= 0)
69 {
70 Vdouble vd;
71 for (size_t j = 0; j < modelsContainer_.size(); ++j)
72 {
73 vd.push_back(1 / subNModel(j).Qij(static_cast<size_t>(from_), static_cast<size_t>(to_)));
74 }
75 setVRates(vd);
76 }
77 }
78
79public:
83 const SubstitutionModelInterface& subModel(const std::string& name) const
84 {
85 return dynamic_cast<const SubstitutionModelInterface&>(model(name));
86 }
87
89 {
90 return dynamic_cast<const SubstitutionModelInterface&>(nModel(i));
91 }
92};
93} // end of namespace bpp.
94#endif // BPP_PHYL_MODEL_MIXTUREOFASUBSTITUTIONMODEL_H
const TransitionModelInterface & nModel(size_t i) const override
Returns a specific model from the mixture.
virtual void setVRates(const Vdouble &vd) override
Sets the rates of the submodels to be proportional to a given vector, with the constraint that the me...
std::vector< std::shared_ptr< TransitionModelInterface > > modelsContainer_
vector of pointers to TransitionModels.
std::string getNamespace() const override
Partial implementation of the TransitionModel interface.
std::shared_ptr< const StateMapInterface > getStateMap() const override
MixtureOfASubstitutionModel(const MixtureOfASubstitutionModel &model)
MixtureOfASubstitutionModel * clone() const override
const SubstitutionModelInterface & subModel(const std::string &name) const
retrieve a pointer to the substitution model with the given name.
void updateMatrices_() override
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
MixtureOfASubstitutionModel(std::shared_ptr< const Alphabet > alpha, std::unique_ptr< SubstitutionModelInterface > model, std::map< std::string, std::unique_ptr< DiscreteDistributionInterface > > &parametersDistributionsList, int ffrom=-1, int tto=-1)
Constructor of a MixtureOfASubstitutionModel, where all the models have rate 1 and equal probability.
const SubstitutionModelInterface & subNModel(size_t i) const
MixtureOfASubstitutionModel & operator=(const MixtureOfASubstitutionModel &model)
Transition models defined as a mixture of nested substitution models.
void updateMatrices_() override
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
const TransitionModelInterface & model(const std::string &name) const override
retrieve a pointer to the submodel with the given name.
MixtureOfATransitionModel & operator=(const MixtureOfATransitionModel &)
Interface for all substitution models.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble