bpp-phyl3  3.0.0
AbstractWrappedModel.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_ABSTRACTWRAPPEDMODEL_H
6 #define BPP_PHYL_MODEL_ABSTRACTWRAPPEDMODEL_H
7 
10 
11 #include "WrappedModel.h"
13 
14 namespace bpp
15 {
22  public virtual AbstractParameterAliasable,
23  public virtual WrappedModelInterface
24 {
25 public:
26  AbstractWrappedModel(const std::string& prefix) :
28  {}
29 
30  virtual ~AbstractWrappedModel() {}
31 
32 public:
38  const std::vector<int>& getAlphabetStates() const override { return model().getAlphabetStates(); }
39 
40  const StateMapInterface& stateMap() const override { return model().stateMap(); }
41 
42  std::shared_ptr<const StateMapInterface> getStateMap() const override { return model().getStateMap(); }
43 
44  int getAlphabetStateAsInt(size_t i) const override { return model().getAlphabetStateAsInt(i); }
45 
46  std::string getAlphabetStateAsChar(size_t i) const override { return model().getAlphabetStateAsChar(i); }
47 
48  std::vector<size_t> getModelStates(int code) const override { return model().getModelStates(code); }
49 
50  std::vector<size_t> getModelStates(const std::string& code) const override { return model().getModelStates(code); }
51 
52 
53  const Alphabet& alphabet() const override { return model().alphabet(); }
54 
55  std::shared_ptr<const Alphabet> getAlphabet() const override { return model().getAlphabet(); }
56 
57  size_t getNumberOfStates() const override { return model().getNumberOfStates(); }
58 
59  const FrequencySetInterface& frequencySet() const override
60  {
61  return model().frequencySet();
62  }
63 
67  virtual std::string getName() const override
68  {
69  return model().getName();
70  }
71 
72 };
73 
75  public virtual AbstractWrappedModel,
76  public virtual AbstractLkTransitionModel,
77  public virtual WrappedTransitionModelInterface
78 {
79 public:
80  AbstractWrappedTransitionModel(const std::string& prefix) :
81  AbstractWrappedModel(prefix)
82  {}
83 
84 protected:
86  {
87  return transitionModel_();
88  }
89 
91 
92 public:
93  const FrequencySetInterface& frequencySet() const override
94  {
95  return transitionModel().frequencySet();
96  }
97 
98  const BranchModelInterface& model() const override
99  {
100  return transitionModel();
101  }
102 };
103 
104 
106  public virtual AbstractWrappedTransitionModel
107 {
108 public:
109  AbstractTotallyWrappedTransitionModel(const std::string& prefix) :
111 
113 
114 public:
120  double freq(size_t i) const override { return transitionModel().freq(i); }
121 
122  double Pij_t (size_t i, size_t j, double t) const override { return transitionModel().Pij_t(i, j, t); }
123  double dPij_dt (size_t i, size_t j, double t) const override { return transitionModel().dPij_dt (i, j, t); }
124  double d2Pij_dt2(size_t i, size_t j, double t) const override { return transitionModel().d2Pij_dt2(i, j, t); }
125 
126  const Vdouble& getFrequencies() const override { return transitionModel().getFrequencies(); }
127 
128  const Matrix<double>& getPij_t(double t) const override { return transitionModel().getPij_t(t); }
129 
130  const Matrix<double>& getdPij_dt(double t) const override { return transitionModel().getdPij_dt(t); }
131 
132  const Matrix<double>& getd2Pij_dt2(double t) const override { return transitionModel().getd2Pij_dt2(t); }
133 
134  double getInitValue(size_t i, int state) const override
135  {
136  return transitionModel().getInitValue(i, state);
137  }
138 
139  double getRate() const override
140  {
141  return transitionModel().getRate();
142  }
143 
144  void setRate(double rate) override
145  {
146  return transitionModel_().setRate(rate);
147  }
148 
149  void setFreqFromData(const SequenceDataInterface& data, double pseudoCount = 0) override
150  {
151  std::map<int, double> freqs;
152  SequenceContainerTools::getFrequencies(data, freqs, pseudoCount);
153  // Re-compute generator and eigen values:
154  transitionModel_().setFreq(freqs);
155  }
156 
157  void setFreq(std::map<int, double>& frequencies) override
158  {
159  transitionModel_().setFreq(frequencies);
160  }
161 
162  bool computeFrequencies() const override
163  {
165  }
166 
171  void computeFrequencies(bool yn) override
172  {
174  }
175 
180 protected:
182  {
184  }
185 };
186 
187 
189  public virtual AbstractWrappedTransitionModel,
190  public virtual WrappedSubstitutionModelInterface
191 {
192 public:
193  AbstractWrappedSubstitutionModel(const std::string& prefix) :
195  {}
196 
198 
200  {
201  return substitutionModel();
202  }
203 
204 protected:
206  {
207  return substitutionModel_();
208  }
209 
211 };
212 
215  public virtual AbstractWrappedSubstitutionModel
216 {
217 public:
218  AbstractTotallyWrappedSubstitutionModel(const std::string& prefix) :
221  {}
222 
224 
230  double Qij(size_t i, size_t j) const { return substitutionModel().Qij(i, j); }
231 
232  const Matrix<double>& generator() const { return substitutionModel().generator(); }
233 
235 
236  double Sij(size_t i, size_t j) const { return substitutionModel().Sij(i, j); }
237 
239 
241 
243 
244  bool isNonSingular() const { return substitutionModel().isNonSingular(); }
245 
247 
249 
251 
253 
254 
258  bool isScalable() const
259  {
260  return substitutionModel().isScalable();
261  }
262 
263  void setScalable(bool scalable)
264  {
265  substitutionModel_().setScalable(scalable);
266  }
267 
268  void normalize()
269  {
271  }
272 
273  void setDiagonal()
274  {
276  }
277 
278  double getScale() const
279  {
280  return substitutionModel().getScale();
281  }
282 
283  void setScale(double scale)
284  {
285  substitutionModel_().setScale(scale);
286  }
287 
288 };
289 } // end of namespace bpp.
290 #endif // BPP_PHYL_MODEL_ABSTRACTWRAPPEDMODEL_H
Partial implementation of the TransitionModel interface, with function for likelihood computations.
void setDiagonal()
set the diagonal of the generator such that sum on each line equals 0.
void setScale(double scale)
Multiplies the current generator by the given scale.
void setScalable(bool scalable)
sets if model is scalable, ie scale can be changed. Default : true, set to false to avoid normalizati...
bool isScalable() const
returns if model is scalable
const Matrix< double > & getRowLeftEigenVectors() const
const Matrix< double > & getColumnRightEigenVectors() const
const Matrix< double > & generator() const
bool enableEigenDecomposition()
Tell if eigenValues and Vectors must be computed.
double Qij(size_t i, size_t j) const
Methods to supersede SubstitutionModel methods.
void enableEigenDecomposition(bool yn)
Set if eigenValues and Vectors must be computed.
double getScale() const
Get the scalar product of diagonal elements of the generator and the frequencies vector....
const Matrix< double > & exchangeabilityMatrix() const
AbstractTotallyWrappedSubstitutionModel(const std::string &prefix)
double getRate() const override
Get the rate.
double Pij_t(size_t i, size_t j, double t) const override
const Matrix< double > & getPij_t(double t) const override
const Vdouble & getFrequencies() const override
void setFreqFromData(const SequenceDataInterface &data, double pseudoCount=0) override
Set equilibrium frequencies equal to the frequencies estimated from the data.
double getInitValue(size_t i, int state) const override
double d2Pij_dt2(size_t i, size_t j, double t) const override
double freq(size_t i) const override
Methods to supersede TransitionModel methods.
void setFreq(std::map< int, double > &frequencies) override
Set equilibrium frequencies.
const Matrix< double > & getdPij_dt(double t) const override
const Matrix< double > & getd2Pij_dt2(double t) const override
void setRate(double rate) override
Set the rate of the model (must be positive).
AbstractTotallyWrappedTransitionModel(const std::string &prefix)
double dPij_dt(size_t i, size_t j, double t) const override
Abstract class of Wrapping model class, where all methods are redirected from model().
AbstractWrappedModel(const std::string &prefix)
std::vector< size_t > getModelStates(int code) const override
Get the state in the model corresponding to a particular state in the alphabet.
std::string getAlphabetStateAsChar(size_t i) const override
virtual std::string getName() const override
Get the name of the model.
const Alphabet & alphabet() const override
const std::vector< int > & getAlphabetStates() const override
const FrequencySetInterface & frequencySet() const override
std::shared_ptr< const StateMapInterface > getStateMap() const override
std::shared_ptr< const Alphabet > getAlphabet() const override
const StateMapInterface & stateMap() const override
size_t getNumberOfStates() const override
Get the number of states.
int getAlphabetStateAsInt(size_t i) const override
std::vector< size_t > getModelStates(const std::string &code) const override
Get the state in the model corresponding to a particular state in the alphabet.
TransitionModelInterface & transitionModel_()
const TransitionModelInterface & transitionModel() const
virtual SubstitutionModelInterface & substitutionModel_()=0
AbstractWrappedSubstitutionModel(const std::string &prefix)
const BranchModelInterface & model() const override
virtual TransitionModelInterface & transitionModel_()=0
const FrequencySetInterface & frequencySet() const override
AbstractWrappedTransitionModel(const std::string &prefix)
Interface for all Branch models.
virtual int getAlphabetStateAsInt(size_t index) 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 const StateMapInterface & stateMap() const =0
virtual const Alphabet & alphabet() const =0
Parametrize a set of state frequencies.
Definition: FrequencySet.h:29
static void getFrequencies(const SequenceContainerInterface &sc, std::map< int, double > &f, double pseudoCount=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.
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.
Interface for all transition models.
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 bool computeFrequencies() const =0
virtual const Matrix< double > & getdPij_dt(double t) const =0
Wrapping model interface.
Definition: WrappedModel.h:19
virtual const BranchModelInterface & model() const =0
virtual const SubstitutionModelInterface & substitutionModel() const =0
virtual const TransitionModelInterface & transitionModel() const =0
Defines the basic types of data flow nodes.
std::vector< double > Vdouble