bpp-phyl3  3.0.0
SubstitutionModel.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_SUBSTITUTIONMODEL_H
6 #define BPP_PHYL_MODEL_SUBSTITUTIONMODEL_H
7 
8 #include <Eigen/Core>
9 
11 #include "StateMap.h"
12 
13 // From bpp-core:
14 #include <Bpp/Exceptions.h>
15 #include <Bpp/Numeric/Parameter.h>
20 
21 // From bpp-seq:
24 
25 // From the STL:
26 #include <cstdlib>
27 #include <map>
28 #include <string>
29 
30 namespace bpp
31 {
40  public virtual ParameterAliasable
41 {
42 public:
44  virtual ~BranchModelInterface() {}
45 
47 
48 public:
54  virtual std::string getName() const = 0;
55 
61  virtual const std::vector<int>& getAlphabetStates() const = 0;
62 
66  virtual const StateMapInterface& stateMap() const = 0;
67 
71  virtual std::shared_ptr<const StateMapInterface> getStateMap() const = 0;
72 
79  virtual std::vector<size_t> getModelStates(int code) const = 0;
80 
87  virtual std::vector<size_t> getModelStates(const std::string& code) const = 0;
88 
93  virtual int getAlphabetStateAsInt(size_t index) const = 0;
94 
99  virtual std::string getAlphabetStateAsChar(size_t index) const = 0;
100 
104  virtual const Alphabet& alphabet() const = 0;
105 
109  virtual std::shared_ptr<const Alphabet> getAlphabet() const = 0;
110 
111 
116  virtual const FrequencySetInterface& frequencySet() const = 0;
117 
126  virtual size_t getNumberOfStates() const = 0;
127 
141  virtual double getInitValue(size_t i, int state) const = 0;
142 
152  virtual const Eigen::VectorXd& Lik_t(const Eigen::VectorXd& values, double t) const = 0;
153  virtual const Eigen::VectorXd& dLik_dt(const Eigen::VectorXd& values, double t) const = 0;
154  virtual const Eigen::VectorXd& d2Lik_dt2(const Eigen::VectorXd& values, double t) const = 0;
155 
159  virtual double getRate() const = 0;
160 
165  virtual void setRate(double rate) = 0;
166 
167  virtual void addRateParameter() = 0;
168 };
169 
170 
188  public virtual BranchModelInterface
189 {
190 private:
191 
192 public:
195 
197 
198 public:
203  virtual double freq(size_t i) const = 0;
204 
209  virtual double Pij_t(size_t i, size_t j, double t) const = 0;
210 
216  virtual double dPij_dt(size_t i, size_t j, double t) const = 0;
217 
223  virtual double d2Pij_dt2(size_t i, size_t j, double t) const = 0;
224 
229  virtual const Vdouble& getFrequencies() const = 0;
230 
235  virtual bool computeFrequencies() const = 0;
236 
241  virtual void computeFrequencies(bool yn) = 0;
242 
247  virtual const Matrix<double>& getPij_t(double t) const = 0;
248 
254  virtual const Matrix<double>& getdPij_dt(double t) const = 0;
255 
261  virtual const Matrix<double>& getd2Pij_dt2(double t) const = 0;
262 
270  virtual const Eigen::VectorXd& Lik_t(const Eigen::VectorXd& values, double t) const = 0;
271 
272  virtual const Eigen::VectorXd& dLik_dt(const Eigen::VectorXd& values, double t) const = 0;
273 
274  virtual const Eigen::VectorXd& d2Lik_dt2(const Eigen::VectorXd& values, double t) const = 0;
275 
288  virtual void setFreqFromData(const SequenceDataInterface& data, double pseudoCount = 0) = 0;
289 
295  virtual void setFreq(std::map<int, double>& frequencies) = 0;
296 
297 protected:
298  virtual Vdouble& getFrequencies_() = 0;
299 
303 };
304 
305 
402  public virtual TransitionModelInterface
403 {
404 public:
407 
408  SubstitutionModelInterface* clone() const override = 0;
409 
410 protected:
414  // virtual void updateMatrices() = 0;
415 
416 public:
422  virtual double Qij(size_t i, size_t j) const = 0;
423 
439  virtual const Matrix<double>& generator() const = 0;
440 
446  virtual const Matrix<double>& exchangeabilityMatrix() const = 0;
447 
453  virtual double Sij(size_t i, size_t j) const = 0;
454 
458  virtual void enableEigenDecomposition(bool yn) = 0;
459 
463  virtual bool enableEigenDecomposition() = 0;
464 
468  virtual const Vdouble& getEigenValues() const = 0;
469 
473  virtual const Vdouble& getIEigenValues() const = 0;
474 
478  virtual bool isDiagonalizable() const = 0;
479 
483  virtual bool isNonSingular() const = 0;
484 
489  virtual const Matrix<double>& getRowLeftEigenVectors() const = 0;
490 
495  virtual const Matrix<double>& getColumnRightEigenVectors() const = 0;
496 
501  virtual void setScalable(bool scalable) = 0;
502 
506  virtual bool isScalable() const = 0;
507 
516  virtual double getScale() const = 0;
517 
524  virtual void setScale(double scale) = 0;
525 
529  virtual void normalize() = 0;
530 
535  virtual void setDiagonal() = 0;
536 };
537 
538 
551  public virtual SubstitutionModelInterface
552 {
553 public:
556 
558 };
559 } // end of namespace bpp.
560 #endif // BPP_PHYL_MODEL_SUBSTITUTIONMODEL_H
Virtual class of a Transition Model related to a given SubstitutionModel.
Interface for all Branch models.
virtual int getAlphabetStateAsInt(size_t index) const =0
virtual std::vector< size_t > getModelStates(const std::string &code) const =0
Get the state in the model corresponding to a particular state in the alphabet.
BranchModelInterface * clone() const =0
virtual const Eigen::VectorXd & d2Lik_dt2(const Eigen::VectorXd &values, double t) const =0
virtual const FrequencySetInterface & frequencySet() const =0
virtual const std::vector< int > & getAlphabetStates() const =0
virtual std::string getAlphabetStateAsChar(size_t index) const =0
virtual std::vector< size_t > getModelStates(int code) const =0
Get the state in the model corresponding to a particular state in the alphabet.
virtual void setRate(double rate)=0
Set the rate of the model (must be positive).
virtual size_t getNumberOfStates() const =0
Get the number of states.
virtual std::string getName() const =0
Get the name of the model.
virtual double getRate() const =0
Get the rate.
virtual std::shared_ptr< const Alphabet > getAlphabet() const =0
virtual std::shared_ptr< const StateMapInterface > getStateMap() const =0
virtual double getInitValue(size_t i, int state) const =0
virtual void addRateParameter()=0
virtual const Eigen::VectorXd & Lik_t(const Eigen::VectorXd &values, double t) const =0
virtual const StateMapInterface & stateMap() const =0
virtual const Alphabet & alphabet() const =0
virtual const Eigen::VectorXd & dLik_dt(const Eigen::VectorXd &values, double t) const =0
Parametrize a set of state frequencies.
Definition: FrequencySet.h:29
SubModel taken from a MixedTransitionModel, kept in the context of the MixedTransitionModel (see From...
Interface for reversible substitution models.
ReversibleSubstitutionModelInterface * clone() const override=0
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:25
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.
SubstitutionModelInterface * clone() const override=0
virtual double getScale() const =0
Get the scalar product of diagonal elements of the generator and the frequencies vector....
virtual bool enableEigenDecomposition()=0
Tell if eigenValues and Vectors must be computed.
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.
Interface for all transition models.
virtual const Eigen::VectorXd & dLik_dt(const Eigen::VectorXd &values, double t) const =0
virtual const Eigen::VectorXd & d2Lik_dt2(const Eigen::VectorXd &values, double t) const =0
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
TransitionModelInterface * clone() 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 void computeFrequencies(bool yn)=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
virtual const Eigen::VectorXd & Lik_t(const Eigen::VectorXd &values, double t) const =0
Defines the basic types of data flow nodes.
std::vector< double > Vdouble