~ubuntu-branches/ubuntu/raring/libbpp-phyl/raring

« back to all changes in this revision

Viewing changes to src/Bpp/Phyl/Model/MixtureOfSubstitutionModels.h

  • Committer: Bazaar Package Importer
  • Author(s): Julien Dutheil
  • Date: 2011-06-09 11:00:00 UTC
  • Revision ID: james.westby@ubuntu.com-20110609110000-yvx78svv6w7xxgph
Tags: upstream-2.0.2
Import upstream version 2.0.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// File: MixtureOfSubstitutionModels.h
 
3
// Created by: Laurent Gueguen
 
4
// Date: lundi 13 septembre 2010, à 21h 31
 
5
//
 
6
 
 
7
/*
 
8
  Copyright or © or Copr. CNRS, (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 _MIXTUREOFSUBSTITUTIONMODELS_H_
 
41
#define _MIXTUREOFSUBSTITUTIONMODELS_H_
 
42
 
 
43
#include <Bpp/Numeric/Prob.all>
 
44
#include <Bpp/Numeric/VectorTools.h>
 
45
#include "AbstractMixedSubstitutionModel.h"
 
46
 
 
47
#include <vector>
 
48
#include <string>
 
49
#include <map>
 
50
#include <cstring> // C lib for string copy
 
51
 
 
52
namespace bpp
 
53
{
 
54
  /**
 
55
   * @brief Substitution models defined as a mixture of several
 
56
   * substitution models.
 
57
   * @author Laurent Guéguen
 
58
   *
 
59
   * All the models can be of different types (for example T92 or
 
60
   * GY94), and each model has a specific probability and rate. 
 
61
   *
 
62
   *
 
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
 
66
   * equal one. 
 
67
   *
 
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:
 
72
   * @f[
 
73
   * 1 <= i < n, p_i = (1-rp_1)*(1-rp_2)...(1-rp_{i-1})*rp_{i}
 
74
   * @f]
 
75
   * @f[
 
76
   * p_n = (1-rp_1)*(1-rp_2)...(1-rp_{n-1})
 
77
   * @f]
 
78
   * and
 
79
   * @f[
 
80
   * \forall 1 <= i < n, rp_i = \frac{p_i}{1-(p_1+...+p_{i-1})}
 
81
   * @f]
 
82
   * where @f$p_i@f$ stands for the probability of model @f$i@f$.
 
83
   *
 
84
   *
 
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:
 
89
   * @f[
 
90
   * 1 <= i < n, \rho_i = (1-r_1)*(1-r_2)...(1-r_{i-1})*\frac{r_{i}}{p_i} 
 
91
   * @f]
 
92
   * @f[
 
93
   * \rho_n = \frac{(1-r_1)*(1-r_2)*...*(1-r_{n-1})}{p_n}
 
94
   * @f]
 
95
   * and
 
96
   * @f[
 
97
   * \forall 1 <= i < n, r_i = \frac{\rho_i*p_i}{1-(p_1*\rho_1+...+p_{i-1}*\rho_{i-1})} < 1.
 
98
   * @f]
 
99
   *
 
100
   * For example:
 
101
   *
 
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)
 
105
   *
 
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.
 
109
   *
 
110
   *
 
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
 
115
   * of the model.
 
116
 
 
117
   */
 
118
 
 
119
  class MixtureOfSubstitutionModels :
 
120
    public AbstractMixedSubstitutionModel
 
121
  {
 
122
  public:
 
123
 
 
124
    /*
 
125
     *@brief Constructor of a MixtureOfSubstitutionModels, where all
 
126
     *the models have rate 1 and equal probability.
 
127
     *
 
128
     *@param alpha pointer to the Alphabet
 
129
     *@param vpModel vector of pointers to SubstitutionModels. All the
 
130
     *   SubstitutionModels are owned by the instance.
 
131
     */
 
132
    
 
133
    MixtureOfSubstitutionModels(const Alphabet* alpha,
 
134
                                std::vector<SubstitutionModel*> vpModel);
 
135
    
 
136
    /*
 
137
     *@brief Constructor of a MixtureOfSubstitutionModels.
 
138
     *
 
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
 
144
     *
 
145
     * See above the constraints on the rates and the probabilities of
 
146
     * the vectors.
 
147
     */
 
148
    
 
149
    MixtureOfSubstitutionModels(const Alphabet* alpha,
 
150
                                std::vector<SubstitutionModel*> vpModel,
 
151
                                Vdouble& vproba, Vdouble& vrate);
 
152
 
 
153
    MixtureOfSubstitutionModels(const MixtureOfSubstitutionModels&);
 
154
    
 
155
    MixtureOfSubstitutionModels& operator=(const MixtureOfSubstitutionModels&);
 
156
    
 
157
    ~MixtureOfSubstitutionModels();
 
158
    
 
159
    MixtureOfSubstitutionModels* clone() const { return new MixtureOfSubstitutionModels(*this); }
 
160
 
 
161
  public:
 
162
    std::string getName() const { return "MixtureOfSubstitutionModels"; }
 
163
 
 
164
    void updateMatrices();
 
165
  
 
166
    /**
 
167
     * @brief Sets the rates of the submodels to follow the constraint
 
168
     * that the mean rate of the mixture equals rate_.
 
169
     
 
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).
 
173
     */
 
174
 
 
175
    virtual void setVRates(Vdouble& vd);
 
176
    /**
 
177
     * @brief applies setFreq to all the models of the mixture and
 
178
     * recovers the parameters values.
 
179
     *
 
180
     **/
 
181
  
 
182
    void setFreq(std::map<int,double>&);
 
183
 
 
184
  };
 
185
} // end of namespace bpp.
 
186
 
 
187
#endif  // _MIXTUREOFSUBSTITUTIONMODELS_H_