bpp-phyl3 3.0.0
AbstractMixedTransitionModel.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_ABSTRACTMIXEDTRANSITIONMODEL_H
6#define BPP_PHYL_MODEL_ABSTRACTMIXEDTRANSITIONMODEL_H
7
9#include <cstring> // C lib for string copy
10#include <map>
11#include <string>
12#include <vector>
13
16
17namespace bpp
18{
31 public virtual MixedTransitionModelInterface,
32 public virtual AbstractTransitionModel
33{
34protected:
41 std::vector< std::shared_ptr<TransitionModelInterface>> modelsContainer_;
42
46 std::vector<double> vProbas_;
47
60 std::vector<double> vRates_;
61
62public:
64 std::shared_ptr<const Alphabet>,
65 std::shared_ptr<const StateMapInterface> stateMap,
66 const std::string& prefix);
67
69
71
72 virtual AbstractMixedTransitionModel* clone() const override = 0;
73
74public:
78 virtual size_t getNumberOfModels() const override
79 {
80 return modelsContainer_.size();
81 }
82
86 const TransitionModelInterface& nModel(size_t i) const override
87 {
88 return *modelsContainer_[i];
89 }
90
91 std::shared_ptr<const TransitionModelInterface> getNModel(size_t i) const override
92 {
93 return modelsContainer_[i];
94 }
95
99 double getNRate(size_t i) const override
100 {
101 return vRates_[i];
102 }
103
108 virtual void setRate(double rate) override;
109
118 virtual void setVRates(const Vdouble& vd) override;
119
124 virtual void normalizeVRates() override;
125
129 const std::vector<double>& getVRates() const override
130 {
131 return vRates_;
132 }
133
138 virtual double getNProbability(size_t i) const override
139 {
140 return vProbas_[i];
141 }
142
147 virtual const std::vector<double>& getProbabilities() const override
148 {
149 return vProbas_;
150 }
151
155 virtual void setNProbability(size_t i, double prob) override
156 {
157 if (prob < 0)
158 prob = 0;
159 if (prob > 1)
160 prob = 1;
161
162 vProbas_[i] = prob;
163 }
164
168 virtual const Matrix<double>& getPij_t(double t) const override;
169 virtual const Matrix<double>& getdPij_dt(double t) const override;
170 virtual const Matrix<double>& getd2Pij_dt2(double t) const override;
171
176 bool computeFrequencies() const override
177 {
178 return modelsContainer_[0]->computeFrequencies();
179 }
180
184 void computeFrequencies(bool yn) override
185 {
186 for (auto& sm : modelsContainer_)
187 {
188 sm->computeFrequencies(yn);
189 }
190 }
191
192 void setFreq(std::map<int, double>& frequ) override
193 {
194 for (auto& sm : modelsContainer_)
195 {
196 sm->setFreq(frequ);
197 }
198 }
199
200 void setFreqFromData(const SequenceDataInterface& data, double pseudoCount) override
201 {
202 std::map<int, double> freqs;
203 SequenceContainerTools::getFrequencies(data, freqs, pseudoCount);
204 setFreq(freqs);
205 }
206
207protected:
209 {
210 return *modelsContainer_[i];
211 }
212};
213} // end of namespace bpp.
214#endif // BPP_PHYL_MODEL_ABSTRACTMIXEDTRANSITIONMODEL_H
Partial implementation for Mixed Transition models, defined as a mixture of "simple" substitution mod...
virtual const Matrix< double > & getdPij_dt(double t) const override
const TransitionModelInterface & nModel(size_t i) const override
Returns a specific model from the mixture.
void computeFrequencies(bool yn) override
Set if equilibrium frequencies should be computed.
AbstractMixedTransitionModel(std::shared_ptr< const Alphabet >, std::shared_ptr< const StateMapInterface > stateMap, const std::string &prefix)
virtual const std::vector< double > & getProbabilities() const override
Returns the vector of probabilities.
double getNRate(size_t i) const override
Returns the rate of a specific model from the mixture.
std::shared_ptr< const TransitionModelInterface > getNModel(size_t i) const override
std::vector< double > vProbas_
vector of the probabilities of the models
virtual size_t getNumberOfModels() const override
returns the number of models in the mixture
virtual void setRate(double rate) override
Set the rate of the model and the submodels.
virtual const Matrix< double > & getd2Pij_dt2(double t) const override
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...
virtual void normalizeVRates() override
Normalizes the rates of the submodels so that the mean rate of the mixture equals rate_.
AbstractMixedTransitionModel & operator=(const AbstractMixedTransitionModel &)
virtual AbstractMixedTransitionModel * clone() const override=0
void setFreq(std::map< int, double > &frequ) override
Set equilibrium frequencies.
std::vector< double > vRates_
vector of the rates of the models.
TransitionModelInterface & nModel_(size_t i) override
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount) override
Set equilibrium frequencies equal to the frequencies estimated from the data.
const std::vector< double > & getVRates() const override
Returns the vector of all the rates of the mixture.
virtual const Matrix< double > & getPij_t(double t) const override
From TransitionModel interface.
virtual void setNProbability(size_t i, double prob) override
Sets the probability of a specific model from the mixture.
virtual double getNProbability(size_t i) const override
Returns the probability of a specific model from the mixture.
std::vector< std::shared_ptr< TransitionModelInterface > > modelsContainer_
vector of pointers to TransitionModels.
Partial implementation of the TransitionModel interface.
const StateMapInterface & stateMap() const override
Interface for Transition models, defined as a mixture of "simple" transition models.
static void getFrequencies(const SequenceContainerInterface &sc, std::map< int, double > &f, double pseudoCount=0)
Interface for all transition models.
Defines the basic types of data flow nodes.
std::vector< double > Vdouble