bpp-phyl3  3.0.0
InMixedSubstitutionModel.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_INMIXEDSUBSTITUTIONMODEL_H
6 #define BPP_PHYL_MODEL_INMIXEDSUBSTITUTIONMODEL_H
7 
8 
10 #include "AbstractWrappedModel.h"
11 #include "MixedTransitionModel.h"
12 
13 namespace bpp
14 {
30 {
31 private:
35  std::unique_ptr<MixedTransitionModelInterface> mixedModelPtr_;
36 
41 
45  std::string mixtName_;
46 
47 public:
49  std::unique_ptr<MixedTransitionModelInterface> mixedModel,
50  const std::string& subModelName,
51  const std::string& mixtDesc);
52 
54  std::unique_ptr<MixedTransitionModelInterface> mixedModel,
55  size_t subModelNumber,
56  const std::string& mixtDesc);
57 
59 
61 
62  InMixedSubstitutionModel* clone() const override { return new InMixedSubstitutionModel(*this); }
63 
64 public:
66  {
67  return *mixedModelPtr_;
68  }
69 
71  {
72  return dynamic_cast<const SubstitutionModelInterface&>(mixedModelPtr_->nModel(subModelNumber_));
73  }
74 
75  size_t getSubModelNumber() const
76  {
77  return subModelNumber_;
78  }
79 
80  bool computeFrequencies() const override
81  {
82  return mixedModel().computeFrequencies();
83  }
84 
89  void computeFrequencies(bool yn) override
90  {
92  }
93 
94 protected:
96  {
97  return mixedModel_().getFrequencies_();
98  }
99 
101  {
102  return *mixedModelPtr_;
103  }
104 
106  {
108  }
109 
110 public:
116  double freq(size_t i) const override { return transitionModel().freq(i); }
117 
118  double Pij_t (size_t i, size_t j, double t) const override { return transitionModel().Pij_t(i, j, t); }
119  double dPij_dt (size_t i, size_t j, double t) const override { return transitionModel().dPij_dt (i, j, t); }
120  double d2Pij_dt2(size_t i, size_t j, double t) const override { return transitionModel().d2Pij_dt2(i, j, t); }
121 
122  const Vdouble& getFrequencies() const override { return transitionModel().getFrequencies(); }
123 
124  const Matrix<double>& getPij_t(double t) const override { return transitionModel().getPij_t(t); }
125 
126  const Matrix<double>& getdPij_dt(double t) const override { return transitionModel().getdPij_dt(t); }
127 
128  const Matrix<double>& getd2Pij_dt2(double t) const override { return transitionModel().getd2Pij_dt2(t); }
129 
130  double getInitValue(size_t i, int state) const override
131  {
132  return model().getInitValue(i, state);
133  }
134 
135  void setFreqFromData(const SequenceDataInterface& data, double pseudoCount = 0) override
136  {
137  mixedModel_().setFreqFromData(data, pseudoCount);
138  }
139 
140  void setFreq(std::map<int, double>& frequencies) override
141  {
142  mixedModel_().setFreq(frequencies);
143  }
144 
150  double Qij(size_t i, size_t j) const override { return substitutionModel().Qij(i, j); }
151 
152  const Matrix<double>& generator() const override { return substitutionModel().generator(); }
153 
155 
156  double Sij(size_t i, size_t j) const override { return substitutionModel().Sij(i, j); }
157 
159 
161 
162  bool isDiagonalizable() const override { return substitutionModel().isDiagonalizable(); }
163 
164  bool isNonSingular() const override { return substitutionModel().isNonSingular(); }
165 
166  const Vdouble& getEigenValues() const override { return substitutionModel().getEigenValues(); }
167 
168  const Vdouble& getIEigenValues() const override { return substitutionModel().getIEigenValues(); }
169 
171 
173 
174 
178  bool isScalable() const override
179  {
180  return substitutionModel().isScalable();
181  }
182 
183  void setScalable(bool scalable) override
184  {
185  substitutionModel_().setScalable(scalable);
186  }
187 
188 
189  double getScale() const override { return substitutionModel().getScale(); }
190 
191  void setScale(double scale) override { substitutionModel_().setScale(scale); }
192 
193 
194  void normalize() override
195  {
197  }
198 
199  void setDiagonal() override
200  {
202  }
203 
204  double getRate() const override
205  {
206  return transitionModel().getRate();
207  }
208 
209  void setRate(double rate) override
210  {
211  return mixedModel_().setRate(rate);
212  }
213 
214  void addRateParameter() override
215  {
218  }
219 
235  void fireParameterChanged(const ParameterList& parameters) override
236  {
237  mixedModel_().matchParametersValues(parameters);
238  }
239 
240  void setNamespace(const std::string& name) override
241  {
243  mixedModel_().setNamespace(name);
244  }
245 
246 
250  std::string getName() const override
251  {
252  return mixedModelPtr_->getName();
253  }
254 };
255 } // end of namespace bpp.
256 #endif // BPP_PHYL_MODEL_INMIXEDSUBSTITUTIONMODEL_H
void addParameter_(Parameter *parameter)
void setNamespace(const std::string &prefix)
std::string getNamespace() const override
const TransitionModelInterface & transitionModel() const
const BranchModelInterface & model() const override
virtual void setRate(double rate)=0
Set the rate of the model (must be positive).
virtual double getRate() const =0
Get the rate.
virtual double getInitValue(size_t i, int state) const =0
virtual void addRateParameter()=0
SubModel taken from a MixedTransitionModel, kept in the context of the MixedTransitionModel (see From...
double Pij_t(size_t i, size_t j, double t) const override
const Matrix< double > & getdPij_dt(double t) const override
std::string getName() const override
Get the name of the model.
bool isScalable() const override
returns if model is scalable
size_t subModelNumber_
the number of the submodel
const Matrix< double > & getColumnRightEigenVectors() const override
void normalize() override
Normalize the generator.
std::string mixtName_
The name of the mixture model (for io purpose).
void computeFrequencies(bool yn) override
const Vdouble & getFrequencies() const override
InMixedSubstitutionModel & operator=(const InMixedSubstitutionModel &fmsm)
InMixedSubstitutionModel * clone() const override
double freq(size_t i) const override
void setNamespace(const std::string &name) override
MixedTransitionModelInterface & mixedModel_()
double getScale() const override
Get the scalar product of diagonal elements of the generator and the frequencies vector....
const Matrix< double > & exchangeabilityMatrix() const override
const SubstitutionModelInterface & substitutionModel() const override
const Matrix< double > & getd2Pij_dt2(double t) const override
void setScalable(bool scalable) override
sets if model is scalable, ie scale can be changed. Default : true, set to false to avoid normalizati...
const MixedTransitionModelInterface & mixedModel() const
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0) override
Set equilibrium frequencies equal to the frequencies estimated from the data.
void setDiagonal() override
set the diagonal of the generator such that sum on each line equals 0.
double Qij(size_t i, size_t j) const override
Methods to supersede SubstitutionModel methods.
const Matrix< double > & generator() const override
const Matrix< double > & getRowLeftEigenVectors() const override
const Matrix< double > & getPij_t(double t) const override
void setScale(double scale) override
Multiplies the current generator by the given scale.
std::unique_ptr< MixedTransitionModelInterface > mixedModelPtr_
The MixedOfTransitionModels.
void setFreq(std::map< int, double > &frequencies) override
Set equilibrium frequencies.
double dPij_dt(size_t i, size_t j, double t) const override
const Vdouble & getIEigenValues() const override
bool computeFrequencies() const override
void setRate(double rate) override
Set the rate of the model (must be positive).
double d2Pij_dt2(size_t i, size_t j, double t) const override
double getInitValue(size_t i, int state) const override
void enableEigenDecomposition(bool yn) override
Set if eigenValues and Vectors must be computed.
bool enableEigenDecomposition() override
Tell if eigenValues and Vectors must be computed.
SubstitutionModelInterface & substitutionModel_() override
double getRate() const override
Get the rate.
const Vdouble & getEigenValues() const override
double Sij(size_t i, size_t j) const override
void fireParameterChanged(const ParameterList &parameters) override
Methods to supersede AbstractSubstitutionnModel methods.
Interface for Transition models, defined as a mixture of "simple" transition models.
virtual TransitionModelInterface & nModel_(size_t i)=0
static const std::shared_ptr< IntervalConstraint > R_PLUS_STAR
virtual bool matchParametersValues(const ParameterList &parameters)=0
virtual void setNamespace(const std::string &prefix)=0
Interface for all substitution models.
virtual const Vdouble & getIEigenValues() const =0
virtual bool isDiagonalizable() const =0
virtual void setScalable(bool scalable)=0
sets if model is scalable, ie scale can be changed. Default : true, set to false to avoid normalizati...
virtual const Matrix< double > & getColumnRightEigenVectors() const =0
virtual void enableEigenDecomposition(bool yn)=0
Set if eigenValues and Vectors must be computed.
virtual const Matrix< double > & generator() const =0
virtual void normalize()=0
Normalize the generator.
virtual double getScale() const =0
Get the scalar product of diagonal elements of the generator and the frequencies vector....
virtual double Sij(size_t i, size_t j) const =0
virtual bool isScalable() const =0
returns if model is scalable
virtual const Vdouble & getEigenValues() const =0
virtual void setDiagonal()=0
set the diagonal of the generator such that sum on each line equals 0.
virtual const Matrix< double > & getRowLeftEigenVectors() const =0
virtual bool isNonSingular() const =0
virtual const Matrix< double > & exchangeabilityMatrix() const =0
virtual void setScale(double scale)=0
Multiplies the current generator by the given scale.
virtual double Qij(size_t i, size_t j) const =0
A method for computing all necessary matrices.
virtual double Pij_t(size_t i, size_t j, double t) const =0
virtual double freq(size_t i) const =0
virtual double d2Pij_dt2(size_t i, size_t j, double t) const =0
virtual const Matrix< double > & getPij_t(double t) const =0
virtual const Vdouble & getFrequencies() const =0
virtual void setFreq(std::map< int, double > &frequencies)=0
Set equilibrium frequencies.
virtual const Matrix< double > & getd2Pij_dt2(double t) const =0
virtual double dPij_dt(size_t i, size_t j, double t) const =0
virtual Vdouble & getFrequencies_()=0
virtual void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0)=0
Set equilibrium frequencies equal to the frequencies estimated from the data.
virtual bool computeFrequencies() const =0
virtual const Matrix< double > & getdPij_dt(double t) const =0
Defines the basic types of data flow nodes.
std::vector< double > Vdouble