bpp-phyl  2.2.0
AbstractMixedSubstitutionModel.h
Go to the documentation of this file.
1 //
2 // File: MixedSubstitutionModel.h
3 // Created by: Laurent Gueguen
4 // On: vendredi 19 novembre 2010, à 15h 48
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 _ABSTRACTMIXEDSUBSTITUTIONMODEL_H_
41 #define _ABSTRACTMIXEDSUBSTITUTIONMODEL_H_
42 
43 #include "MixedSubstitutionModel.h"
45 // #include <Bpp/Seq/Alphabet.all>
46 
47 #include <vector>
48 #include <string>
49 #include <map>
50 #include <cstring> // C lib for string copy
51 
52 namespace bpp
53 {
68  public virtual MixedSubstitutionModel,
70 {
71 protected:
78  std::vector<SubstitutionModel*> modelsContainer_;
79 
83  std::vector<double> vProbas_;
84 
97  std::vector<double> vRates_;
98 
99 public:
100  AbstractMixedSubstitutionModel(const Alphabet*, StateMap* stateMap, const std::string& prefix);
101 
103 
105 
107 
108  virtual AbstractMixedSubstitutionModel* clone() const = 0;
109 
110 public:
114  virtual size_t getNumberOfModels() const
115  {
116  return modelsContainer_.size();
117  }
118 
122  virtual const SubstitutionModel* getNModel(size_t i) const
123  {
124  return modelsContainer_[i];
125  }
126 
127  virtual SubstitutionModel* getNModel(size_t i)
128  {
129  return modelsContainer_[i];
130  }
131 
135  double getNRate(size_t i) const
136  {
137  return vRates_[i];
138  }
139 
145  virtual void setRate(double rate);
146 
157  virtual void setVRates(const Vdouble& vd);
158 
164  virtual void normalizeVRates();
165 
170  const std::vector<double>& getVRates() const
171  {
172  return vRates_;
173  }
174 
179  virtual double getNProbability(size_t i) const
180  {
181  return vProbas_[i];
182  }
183 
189  virtual const std::vector<double>& getProbabilities() const
190  {
191  return vProbas_;
192  }
193 
197  virtual void setNProbability(size_t i, double prob)
198  {
199  if ((prob >= 0) && (prob <= 1))
200  vProbas_[i] = prob;
201  }
202 
207  double Qij(size_t i, size_t j) const {return 0; }
208 
214  virtual size_t getNumberOfStates() const;
215 
216  virtual const Matrix<double>& getPij_t(double t) const;
217  virtual const Matrix<double>& getdPij_dt(double t) const;
218  virtual const Matrix<double>& getd2Pij_dt2(double t) const;
219 };
220 } // end of namespace bpp.
221 
222 #endif // _ABSTRACTMIXEDSUBSTITUTIONMODEL_H_
Interface for all substitution models.
virtual const Matrix< double > & getd2Pij_dt2(double t) const
virtual AbstractMixedSubstitutionModel * clone() const =0
virtual size_t getNumberOfModels() const
returns the number of models in the mixture
virtual void setVRates(const Vdouble &vd)
Sets the rates of the submodels to be proportional to a given vector, with the constraint that the me...
virtual void normalizeVRates()
Normalizes the rates of the submodels so that the mean rate of the mixture equals rate_...
Partial implementation of the SubstitutionModel interface.
Partial implementation for Mixed Substitution models, defined as a mixture of "simple" substitution m...
double getNRate(size_t i) const
Returns the rate of a specific model from the mixture.
virtual const Matrix< double > & getdPij_dt(double t) const
virtual double getNProbability(size_t i) const
Returns the probability of a specific model from the mixture.
virtual const std::vector< double > & getProbabilities() const
Returns the vector of probabilities.
virtual const Matrix< double > & getPij_t(double t) const
AbstractMixedSubstitutionModel & operator=(const AbstractMixedSubstitutionModel &)
virtual void setNProbability(size_t i, double prob)
Sets the probability of a specific model from the mixture.
virtual void setRate(double rate)
Set the rate of the model and the submodels.
const std::vector< double > & getVRates() const
Returns the vector of all the rates of the mixture.
std::vector< double > vRates_
vector of the rates of the models.
double Qij(size_t i, size_t j) const
This function can not be applied here, so it is defined to prevent wrong usage.
virtual const SubstitutionModel * getNModel(size_t i) const
Returns a specific model from the mixture.
AbstractMixedSubstitutionModel(const Alphabet *, StateMap *stateMap, const std::string &prefix)
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:58
virtual SubstitutionModel * getNModel(size_t i)
virtual size_t getNumberOfStates() const
From SubstitutionModel interface.
std::vector< SubstitutionModel * > modelsContainer_
vector of pointers to SubstitutionModels.
std::vector< double > vProbas_
vector of the probabilities of the models
Interface for Substitution models, defined as a mixture of "simple" substitution models.