2
// File: MixtureOfSubstitutionModels.h
3
// Created by: Laurent Gueguen
4
// Date: lundi 13 septembre 2010, à 21h 31
8
Copyright or © or Copr. CNRS, (November 16, 2004)
10
This software is a computer program whose purpose is to provide classes
11
for phylogenetic data analysis.
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".
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
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.
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.
40
#ifndef _MIXTUREOFSUBSTITUTIONMODELS_H_
41
#define _MIXTUREOFSUBSTITUTIONMODELS_H_
43
#include <Bpp/Numeric/Prob.all>
44
#include <Bpp/Numeric/VectorTools.h>
45
#include "AbstractMixedSubstitutionModel.h"
50
#include <cstring> // C lib for string copy
55
* @brief Substitution models defined as a mixture of several
56
* substitution models.
57
* @author Laurent Guéguen
59
* All the models can be of different types (for example T92 or
60
* GY94), and each model has a specific probability and rate.
63
* The probabilities and rates of the models are independent
64
* parameters, handled directly, under the constraint that the
65
* expectation of the rates on the distribution of the models must
68
* If there are @f$n@f$ models, @f$p_i@f$ is the probability of
69
* model i (@f$\sum_{i=1}^{n} p_i = 1@f$) and the probabilities
70
* are defined by relative probabilities parameters @f$rp_i@f$
71
* (called "relprobai") with:
73
* 1 <= i < n, p_i = (1-rp_1)*(1-rp_2)...(1-rp_{i-1})*rp_{i}
76
* p_n = (1-rp_1)*(1-rp_2)...(1-rp_{n-1})
80
* \forall 1 <= i < n, rp_i = \frac{p_i}{1-(p_1+...+p_{i-1})}
82
* where @f$p_i@f$ stands for the probability of model @f$i@f$.
85
* If there are @f$n@f$ models, @f$\rho_i@f$ is the rate and @f$p_i@f$
86
* is the probability of model i (@f$\sum_{i=1}^{n} p_i * \rho_i =
87
* 1@f$), the rates are defined by relative rates parameters
88
* @f$r_i@f$ (called "relratei") with:
90
* 1 <= i < n, \rho_i = (1-r_1)*(1-r_2)...(1-r_{i-1})*\frac{r_{i}}{p_i}
93
* \rho_n = \frac{(1-r_1)*(1-r_2)*...*(1-r_{n-1})}{p_n}
97
* \forall 1 <= i < n, r_i = \frac{\rho_i*p_i}{1-(p_1*\rho_1+...+p_{i-1}*\rho_{i-1})} < 1.
102
* Mixture(model1=HKY85(kappa=3), model2=T92(theta=0.1),
103
* model2=L95(gamma=2), relrate1=0.2, relrate2=0.9,
104
* relproba1=0.1,relproba2=0.8)
106
* define a model as a mixture of 3 different models: HKY85 has
107
* probability 0.1 and rate 2, T92 has probability 0.4 and rate 1.8,
108
* and L95 has probability 0.5 and rate 0.16.
111
* The parameters are named \c "Mixture.relrate1", \c
112
* "Mixture.relrate2", \c "Mixture.relproba1", \c
113
* "Mixture.relproba2"... in addition to the parameters of the
114
* submodels that are prefixed by "Mixture.i_", where i is the order
119
class MixtureOfSubstitutionModels :
120
public AbstractMixedSubstitutionModel
125
*@brief Constructor of a MixtureOfSubstitutionModels, where all
126
*the models have rate 1 and equal probability.
128
*@param alpha pointer to the Alphabet
129
*@param vpModel vector of pointers to SubstitutionModels. All the
130
* SubstitutionModels are owned by the instance.
133
MixtureOfSubstitutionModels(const Alphabet* alpha,
134
std::vector<SubstitutionModel*> vpModel);
137
*@brief Constructor of a MixtureOfSubstitutionModels.
139
*@param alpha pointer to the Alphabet
140
*@param vpModel vector of pointers to SubstitutionModels. All the
141
* SubstitutionModels are owned by the instance.
142
*@param vproba vector of the probabilities of the models
143
*@param vrate vector of the rates of the models
145
* See above the constraints on the rates and the probabilities of
149
MixtureOfSubstitutionModels(const Alphabet* alpha,
150
std::vector<SubstitutionModel*> vpModel,
151
Vdouble& vproba, Vdouble& vrate);
153
MixtureOfSubstitutionModels(const MixtureOfSubstitutionModels&);
155
MixtureOfSubstitutionModels& operator=(const MixtureOfSubstitutionModels&);
157
~MixtureOfSubstitutionModels();
159
MixtureOfSubstitutionModels* clone() const { return new MixtureOfSubstitutionModels(*this); }
162
std::string getName() const { return "MixtureOfSubstitutionModels"; }
164
void updateMatrices();
167
* @brief Sets the rates of the submodels to follow the constraint
168
* that the mean rate of the mixture equals rate_.
170
* @param vd a vector of positive values such that the rates of
171
* the respective submodels are in the same proportions (ie this
172
* vector does not need to be normalized).
175
virtual void setVRates(Vdouble& vd);
177
* @brief applies setFreq to all the models of the mixture and
178
* recovers the parameters values.
182
void setFreq(std::map<int,double>&);
185
} // end of namespace bpp.
187
#endif // _MIXTUREOFSUBSTITUTIONMODELS_H_