bpp-phyl  2.1.0
 All Classes Namespaces Files Functions Variables Friends Pages
AbstractSubstitutionModel.h
Go to the documentation of this file.
1 //
2 // File: AbstractSubstitutionModel.h
3 // Created by: Julien Dutheil
4 // Created on: Tue May 27 10:31:49 2003
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 _ABSTRACTSUBSTITUTIONMODEL_H_
41 #define _ABSTRACTSUBSTITUTIONMODEL_H_
42 
43 #include "SubstitutionModel.h"
44 
47 
48 namespace bpp
49 {
77  public virtual SubstitutionModel,
78  public virtual AbstractParameterAliasable
79 {
80 protected:
85 
89  size_t size_;
90 
97  double rate_;
98 
102  std::vector<int> chars_;
103 
108 
114 
123 
130 
135 
140 
145 
151 
156 
162 
169 
175  std::vector< RowMatrix<double> > vPowGen_;
176 
183 
184 public:
185  AbstractSubstitutionModel(const Alphabet* alpha, const std::string& prefix);
186 
189  alphabet_(model.alphabet_),
190  size_(model.size_),
191  rate_(model.rate_),
192  chars_(model.chars_),
193  generator_(model.generator_),
194  freq_(model.freq_),
196  pijt_(model.pijt_),
197  dpijt_(model.dpijt_),
198  d2pijt_(model.d2pijt_),
200  eigenValues_(model.eigenValues_),
206  vPowGen_(model.vPowGen_),
207  tmpMat_(model.tmpMat_)
208  {}
209 
211  {
213  alphabet_ = model.alphabet_;
214  size_ = model.size_;
215  rate_ = model.rate_;
216  chars_ = model.chars_;
217  generator_ = model.generator_;
218  freq_ = model.freq_;
220  pijt_ = model.pijt_;
221  dpijt_ = model.dpijt_;
222  d2pijt_ = model.d2pijt_;
224  eigenValues_ = model.eigenValues_;
230  vPowGen_ = model.vPowGen_;
231  tmpMat_ = model.tmpMat_;
232  return *this;
233  }
234 
236 
237 #ifndef NO_VIRTUAL_COV
238  virtual AbstractSubstitutionModel* clone() const = 0;
239 #endif
240 
241 public:
242  const Alphabet* getAlphabet() const { return alphabet_; }
243 
244  const std::vector<int>& getAlphabetChars() const { return chars_; }
245 
246  int getAlphabetChar(size_t i) const { return chars_[i]; }
247 
248  std::vector<size_t> getModelStates(int i) const { return VectorTools::whichAll(chars_, i); }
249 
250  virtual const Vdouble& getFrequencies() const { return freq_; }
251 
252  const Matrix<double>& getGenerator() const { return generator_; }
253 
255 
256  double Sij(size_t i, size_t j) const { return exchangeability_(i, j); }
257 
258  virtual const Matrix<double>& getPij_t(double t) const;
259  virtual const Matrix<double>& getdPij_dt(double t) const;
260  virtual const Matrix<double>& getd2Pij_dt2(double t) const;
261 
262  const Vdouble& getEigenValues() const { return eigenValues_; }
263 
264  const Vdouble& getIEigenValues() const { return iEigenValues_; }
265 
266  bool isDiagonalizable() const { return isDiagonalizable_; }
267 
268  bool isNonSingular() const { return isNonSingular_; }
269 
271 
273 
274  virtual double freq(size_t i) const { return freq_[i]; }
275 
276  virtual double Qij(size_t i, size_t j) const { return generator_(i, j); }
277 
278  virtual double Pij_t (size_t i, size_t j, double t) const { return getPij_t(t) (i, j); }
279  virtual double dPij_dt (size_t i, size_t j, double t) const { return getdPij_dt(t) (i, j); }
280  virtual double d2Pij_dt2(size_t i, size_t j, double t) const { return getd2Pij_dt2(t) (i, j); }
281 
282  double getInitValue(size_t i, int state) const throw (IndexOutOfBoundsException, BadIntException);
283 
284  void setFreqFromData(const SequenceContainer& data, double pseudoCount = 0);
285 
286  virtual void setFreq(std::map<int, double>&);
287 
289 
291 
297  virtual void fireParameterChanged(const ParameterList& parameters)
298  {
300  if ((parameters.size()!=1) || (parameters[0].getName()!=getNamespace()+"rate"))
301  updateMatrices();
302  }
303 
304  void addRateParameter();
305 
306 protected:
323  virtual void updateMatrices();
324 
325 public:
326  double getScale() const;
327 
328  void setScale(double scale);
329 
330  virtual double getRate() const;
331 
332  virtual void setRate(double rate);
333 
334 
336 
337 };
338 
339 
365  public virtual AbstractSubstitutionModel,
366  public virtual ReversibleSubstitutionModel
367 {
368 public:
369  AbstractReversibleSubstitutionModel(const Alphabet* alpha, const std::string& prefix) :
371  AbstractSubstitutionModel(alpha, prefix)
372  {
373  isDiagonalizable_ = true;
374  isNonSingular_ = true;
375  }
376 
378 
379 #ifndef NO_VIRTUAL_COV
380  virtual AbstractReversibleSubstitutionModel* clone() const = 0;
381 #endif
382 
383 protected:
384 
406  virtual void updateMatrices();
407 };
408 
409 } //end of namespace bpp.
410 
411 #endif //_ABSTRACTSUBSTITUTIONMODEL_H_
412