bpp-phyl  2.2.0
AbstractBiblioSubstitutionModel.h
Go to the documentation of this file.
1 //
2 // File: AbstractBiblioSubstitutionModel.h
3 // Created by: Laurent Guéguen
4 // Created on: vendredi 8 juillet 2011, à 20h 17
5 //
6 
7 /*
8  Copyright or © or Copr. Bio++ Development Team, (November 16, 2004)
9 
10  This software is a computer program whose purpose is to provide classes
11  for phylogenetic data analysis.
12 
13  This software is governed by the CeCILL license under French law and
14  abiding by the rules of distribution of free software. You can use,
15  modify and/ or redistribute the software under the terms of the CeCILL
16  license as circulated by CEA, CNRS and INRIA at the following URL
17  "http://www.cecill.info".
18 
19  As a counterpart to the access to the source code and rights to copy,
20  modify and redistribute granted by the license, users are provided only
21  with a limited warranty and the software's author, the holder of the
22  economic rights, and the successive licensors have only limited
23  liability.
24 
25  In this respect, the user's attention is drawn to the risks associated
26  with loading, using, modifying and/or developing or reproducing the
27  software by the user in light of its specific status of free software,
28  that may mean that it is complicated to manipulate, and that also
29  therefore means that it is reserved for developers and experienced
30  professionals having in-depth computer knowledge. Users are therefore
31  encouraged to load and test the software's suitability as regards their
32  requirements in conditions enabling the security of their systems and/or
33  data to be ensured and, more generally, to use and operate it in the
34  same conditions as regards security.
35 
36  The fact that you are presently reading this means that you have had
37  knowledge of the CeCILL license and that you accept its terms.
38  */
39 
40 #ifndef _ABSTRACTBIBLIOSUBSTITUTIONMODEL_H_
41 #define _ABSTRACTBIBLIOSUBSTITUTIONMODEL_H_
42 
43 #include "SubstitutionModel.h"
45 
46 #include <Bpp/Numeric/AbstractParameterAliasable.h>
47 
48 namespace bpp
49 {
58  public virtual SubstitutionModel,
59  public AbstractParameterAliasable
60 {
61 protected:
68  std::map<std::string, std::string> mapParNamesFromPmodel_;
69 
70  ParameterList lParPmodel_;
71 
72 public:
73  AbstractBiblioSubstitutionModel(const std::string& prefix);
74 
76 
78 
80 
81 #ifndef NO_VIRTUAL_COV
82  virtual AbstractBiblioSubstitutionModel* clone() const = 0;
83 #endif
84 
85 public:
86  virtual const SubstitutionModel& getModel() const = 0;
87 
88  /*
89  *@ brief Methods to supersede SubstitutionModel methods.
90  *
91  * @{
92  */
93 
94  const std::vector<int>& getAlphabetStates() const { return getModel().getAlphabetStates(); }
95 
96  const StateMap& getStateMap() const { return getModel().getStateMap(); }
97 
98  int getAlphabetStateAsInt(size_t i) const { return getModel().getAlphabetStateAsInt(i); }
99 
100  std::string getAlphabetStateAsChar(size_t i) const { return getModel().getAlphabetStateAsChar(i); }
101 
102  std::vector<size_t> getModelStates(int code) const { return getModel().getModelStates(code); }
103 
104  std::vector<size_t> getModelStates(const std::string& code) const { return getModel().getModelStates(code); }
105 
106  virtual double freq(size_t i) const { return getModel().freq(i); }
107 
108  virtual double Qij(size_t i, size_t j) const { return getModel().Qij(i, j); }
109 
110  virtual double Pij_t (size_t i, size_t j, double t) const { return getModel().Pij_t(i, j, t); }
111  virtual double dPij_dt (size_t i, size_t j, double t) const { return getModel().dPij_dt (i, j, t); }
112  virtual double d2Pij_dt2(size_t i, size_t j, double t) const { return getModel().d2Pij_dt2(i, j, t); }
113 
114  virtual const Vdouble& getFrequencies() const { return getModel().getFrequencies(); }
115 
116  const Matrix<double>& getGenerator() const { return getModel().getGenerator(); }
117 
118  const Matrix<double>& getExchangeabilityMatrix() const { return getModel().getExchangeabilityMatrix(); }
119 
120  double Sij(size_t i, size_t j) const { return getModel().Sij(i, j); }
121 
122  const Matrix<double>& getPij_t(double t) const { return getModel().getPij_t(t); }
123 
124  const Matrix<double>& getdPij_dt(double t) const { return getModel().getdPij_dt(t); }
125 
126  const Matrix<double>& getd2Pij_dt2(double t) const { return getModel().getd2Pij_dt2(t); }
127 
129 
131 
132  bool isDiagonalizable() const { return getModel().isDiagonalizable(); }
133 
134  bool isNonSingular() const { return getModel().isNonSingular(); }
135 
136  const Vdouble& getEigenValues() const { return getModel().getEigenValues(); }
137 
138  const Vdouble& getIEigenValues() const { return getModel().getIEigenValues(); }
139 
140  const Matrix<double>& getRowLeftEigenVectors() const { return getModel().getRowLeftEigenVectors(); }
141  const Matrix<double>& getColumnRightEigenVectors() const { return getModel().getColumnRightEigenVectors(); }
142 
143  double getRate() const { return getModel().getRate(); }
144 
145  void setRate(double rate) { return getModel().setRate(rate); }
146 
147  void addRateParameter();
148 
149  void setFreqFromData(const SequenceContainer& data, double pseudoCount = 0);
150 
151  void setFreq(std::map<int, double>& frequ);
152 
153  const Alphabet* getAlphabet() const { return getModel().getAlphabet(); }
154 
155  size_t getNumberOfStates() const { return getModel().getNumberOfStates(); }
156 
157  double getInitValue(size_t i, int state) const throw (BadIntException) { return getModel().getInitValue(i, state); }
158 
160 
161  /*
162  * @}
163  *
164  */
165 
166  /*
167  *@ brief Methods to supersede AbstractSubstitutionModel methods.
168  *
169  * @{
170  */
171 
177  virtual void fireParameterChanged(const ParameterList& parameters)
178  {
179  AbstractParameterAliasable::fireParameterChanged(parameters);
180  if (parameters.size() > 1 || (parameters.size() == 1 && parameters[0].getName() != getNamespace() + "rate")) {
181  updateMatrices();
182  }
183  }
184 
185 protected:
186  virtual void updateMatrices();
187  virtual SubstitutionModel& getModel() = 0;
188 
189 public:
190  double getScale() const { return getModel().getScale(); }
191 
192  void setScale(double scale) { getModel().setScale(scale); }
193 
194  /*
195  * @}
196  */
197 };
198 } // end of namespace bpp.
199 
200 
201 #endif // _ABSTRACTBIBLIOSUBSTITUTIONMODEL_H_
202 
Interface for all substitution models.
std::map< std::string, std::string > mapParNamesFromPmodel_
Tools to make the link between the Parameters of the object and those of pmixmodel_.
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 int getAlphabetStateAsInt(size_t index) const =0
virtual const Matrix< double > & getExchangeabilityMatrix() const =0
const Matrix< double > & getColumnRightEigenVectors() const
virtual double getInitValue(size_t i, int state) const =0
virtual const StateMap & getStateMap() const =0
size_t getNumberOfStates() const
Get the number of states.
virtual const std::vector< int > & getAlphabetStates() const =0
Partial implementation of the SubstitutionModel interface for models that are set for matching the bi...
void enableEigenDecomposition(bool yn)
Set if eigenValues and Vectors must be computed.
virtual double Qij(size_t i, size_t j) const
void setRate(double rate)
Set the rate of the model (must be positive).
virtual const FrequenciesSet * getFrequenciesSet() const
If the model owns a FrequenciesSet, returns a pointer to it, otherwise return 0.
virtual const Alphabet * getAlphabet() const =0
AbstractBiblioSubstitutionModel & operator=(const AbstractBiblioSubstitutionModel &model)
virtual double Sij(size_t i, size_t j) const =0
double getInitValue(size_t i, int state) const
const Matrix< double > & getdPij_dt(double t) const
Parametrize a set of state frequencies.
std::vector< size_t > getModelStates(int code) const
Get the state in the model corresponding to a particular state in the alphabet.
virtual void setScale(double scale)=0
Multiplies the current generator by the given scale.
virtual void setRate(double rate)=0
Set the rate of the model (must be positive).
virtual const Vdouble & getFrequencies() const =0
virtual const Matrix< double > & getd2Pij_dt2(double t) const =0
const std::vector< int > & getAlphabetStates() const
virtual AbstractBiblioSubstitutionModel * clone() const =0
virtual double dPij_dt(size_t i, size_t j, double t) const
virtual void enableEigenDecomposition(bool yn)=0
Set if eigenValues and Vectors must be computed.
virtual double d2Pij_dt2(size_t i, size_t j, double t) const =0
virtual const Vdouble & getEigenValues() const =0
const Matrix< double > & getd2Pij_dt2(double t) const
virtual const Matrix< double > & getPij_t(double t) const =0
virtual double Pij_t(size_t i, size_t j, double t) const =0
virtual double Qij(size_t i, size_t j) const =0
virtual const Matrix< double > & getGenerator() const =0
virtual bool isDiagonalizable() const =0
void setFreqFromData(const SequenceContainer &data, double pseudoCount=0)
Set equilibrium frequencies equal to the frequencies estimated from the data.
virtual void fireParameterChanged(const ParameterList &parameters)
Tells the model that a parameter value has changed.
virtual double d2Pij_dt2(size_t i, size_t j, double t) const
void setScale(double scale)
Multiplies the current generator by the given scale.
void setFreq(std::map< int, double > &frequ)
Set equilibrium frequencies.
const Matrix< double > & getRowLeftEigenVectors() const
virtual std::string getAlphabetStateAsChar(size_t index) const =0
const Matrix< double > & getPij_t(double t) const
virtual double getRate() const =0
Get the rate.
virtual const Matrix< double > & getRowLeftEigenVectors() const =0
double getScale() const
Get the scalar product of diagonal elements of the generator and the frequencies vector. If the generator is normalized, then scale=1. Otherwise each element must be multiplied by 1/scale.
virtual double freq(size_t i) const =0
virtual double getScale() const =0
Get the scalar product of diagonal elements of the generator and the frequencies vector. If the generator is normalized, then scale=1. Otherwise each element must be multiplied by 1/scale.
virtual const Matrix< double > & getdPij_dt(double t) const =0
virtual double dPij_dt(size_t i, size_t j, double t) const =0
virtual const Matrix< double > & getColumnRightEigenVectors() const =0
virtual bool isNonSingular() const =0
virtual size_t getNumberOfStates() const =0
Get the number of states.
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:58
virtual double Pij_t(size_t i, size_t j, double t) const
virtual const Vdouble & getIEigenValues() const =0
virtual const SubstitutionModel & getModel() const =0
const FrequenciesSet * getFrequenciesSet() const
If the model owns a FrequenciesSet, returns a pointer to it, otherwise return 0.
const Matrix< double > & getExchangeabilityMatrix() const
bool enableEigenDecomposition()
Tell if eigenValues and Vectors must be computed.
std::vector< size_t > getModelStates(const std::string &code) const
Get the state in the model corresponding to a particular state in the alphabet.