bpp-phyl  2.1.0
 All Classes Namespaces Files Functions Variables Friends Pages
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 
47 
48 namespace bpp
49 {
58  public virtual SubstitutionModel,
60 {
61 protected:
68  std::map<std::string, std::string> mapParNamesFromPmodel_;
69 
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>& getAlphabetChars() const { return getModel().getAlphabetChars(); }
95 
96  int getAlphabetChar(size_t i) const { return getModel().getAlphabetChar(i); }
97 
98  std::vector<size_t> getModelStates(int i) const { return getModel().getModelStates(i); }
99 
100  virtual double freq(size_t i) const { return getModel().freq(i); }
101 
102  virtual double Qij(size_t i, size_t j) const { return getModel().Qij(i, j); }
103 
104  virtual double Pij_t (size_t i, size_t j, double t) const { return getModel().Pij_t(i, j, t); }
105  virtual double dPij_dt (size_t i, size_t j, double t) const { return getModel().dPij_dt (i, j, t); }
106  virtual double d2Pij_dt2(size_t i, size_t j, double t) const { return getModel().d2Pij_dt2(i, j, t); }
107 
108  virtual const Vdouble& getFrequencies() const { return getModel().getFrequencies(); }
109 
110  const Matrix<double>& getGenerator() const { return getModel().getGenerator(); }
111 
113 
114  double Sij(size_t i, size_t j) const { return getModel().Sij(i, j); }
115 
116  const Matrix<double>& getPij_t(double t) const { return getModel().getPij_t(t); }
117 
118  const Matrix<double>& getdPij_dt(double t) const { return getModel().getdPij_dt(t); }
119 
120  const Matrix<double>& getd2Pij_dt2(double t) const { return getModel().getd2Pij_dt2(t); }
121 
123 
125 
126  bool isDiagonalizable() const { return getModel().isDiagonalizable(); }
127 
128  bool isNonSingular() const { return getModel().isNonSingular(); }
129 
130  const Vdouble& getEigenValues() const { return getModel().getEigenValues(); }
131 
132  const Vdouble& getIEigenValues() const { return getModel().getIEigenValues(); }
133 
136 
137  double getRate() const { return getModel().getRate(); }
138 
139  void setRate(double rate) { return getModel().setRate(rate); }
140 
141  void addRateParameter();
142 
143  void setFreqFromData(const SequenceContainer& data, double pseudoCount = 0);
144 
145  void setFreq(std::map<int, double>& frequ);
146 
147  const Alphabet* getAlphabet() const { return getModel().getAlphabet(); }
148 
149  size_t getNumberOfStates() const { return getModel().getNumberOfStates(); }
150 
151  double getInitValue(size_t i, int state) const throw (BadIntException) { return getModel().getInitValue(i, state); }
152 
154 
155  /*
156  * @}
157  *
158  */
159 
160  /*
161  *@ brief Methods to supersede AbstractSubstitutionModel methods.
162  *
163  * @{
164  */
165 
171  virtual void fireParameterChanged(const ParameterList& parameters)
172  {
174  if (parameters.size() > 1 || (parameters.size() == 1 && parameters[0].getName() != getNamespace() + "rate")) {
175  updateMatrices();
176  }
177  }
178 
179 protected:
180  virtual void updateMatrices();
181  virtual SubstitutionModel& getModel() = 0;
182 
183 public:
184  double getScale() const { return getModel().getScale(); }
185 
186  void setScale(double scale) { getModel().setScale(scale); }
187 
188  /*
189  * @}
190  */
191 };
192 } // end of namespace bpp.
193 
194 
195 #endif // _ABSTRACTBIBLIOSUBSTITUTIONMODEL_H_
196