bpp-phyl  2.2.0
G2001.h
Go to the documentation of this file.
1 //
2 // File: G2001.h
3 // Created by: Julien Dutheil
4 // Created on: Mon Aug 07 18:31 2006
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 _G2001_H_
41 #define _G2001_H_
42 
44 
45 #include <Bpp/Numeric/Prob/DiscreteDistribution.h>
46 #include <Bpp/Numeric/Parameter.h>
47 
48 namespace bpp
49 {
63 class G2001 :
65 {
66 private:
67  DiscreteDistribution* rDist_;
68 
69  std::string nestedRatePrefix_;
70 
71 public:
81  G2001(ReversibleSubstitutionModel* model, DiscreteDistribution* rDist, double nu = 1., bool normalizeRateChanges = false) :
82  MarkovModulatedSubstitutionModel(model, static_cast<unsigned int>(rDist->getNumberOfCategories()), normalizeRateChanges, "G01."),
83  rDist_(rDist),
84  nestedRatePrefix_("rdist_" + rDist->getNamespace())
85  {
86  ratesFreq_ = std::vector<double>(nbRates_, 1. / static_cast<double>(nbRates_));
87  rDist_->setNamespace(getNamespace() + nestedRatePrefix_);
88  addParameters_(rDist_->getIndependentParameters());
89  addParameter_(new Parameter("G01.nu", nu, &Parameter::R_PLUS));
92  }
93 
94  G2001(const G2001& model) :
96  rDist_(dynamic_cast<DiscreteDistribution*>(model.rDist_->clone())),
98  {}
99 
100  G2001& operator=(const G2001& model)
101  {
103  rDist_ = dynamic_cast<DiscreteDistribution*>(model.rDist_->clone());
105  return *this;
106  }
107 
108  virtual ~G2001() { delete rDist_; }
109 
110  G2001* clone() const { return new G2001(*this); }
111 
112 public:
113  std::string getName() const { return "G01"; }
114 
120  void fireParameterChanged(const ParameterList& parameters)
121  {
122  rDist_->matchParametersValues(parameters);
124  }
125 
129  const DiscreteDistribution* getRateDistribution() const { return rDist_; }
130 
131  void setNamespace(const std::string& prefix)
132  {
134  // We also need to update the namespace of the nested distribution:
135  rDist_->setNamespace(prefix + nestedRatePrefix_);
136  }
137 
138 
139  double getRate() const { return 1.; }
140 
141  void setRate(double rate) {}
142 
144 
145 protected:
147  {
148  double nu = getParameterValue("nu");
149  for (size_t i = 0; i < nbRates_; i++)
150  {
151  rates_(i, i) = rDist_->getCategory(i);
152  for (size_t j = 0; j < nbRates_; j++)
153  {
154  if (i == j)
155  {
156  ratesExchangeability_(i, j) = -static_cast<double>(nbRates_) * nu;
157  }
158  else
159  {
160  ratesExchangeability_(i, j) = static_cast<double>(nbRates_) * nu / static_cast<double>(nbRates_ - 1);
161  }
162  }
163  }
164  }
165 };
166 } // end of namespace bpp.
167 
168 #endif // _G2001_H_
169 
virtual ~G2001()
Definition: G2001.h:108
void addRateParameter()
Definition: G2001.h:143
Galtier&#39;s 2001 covarion model.
Definition: G2001.h:63
MarkovModulatedSubstitutionModel & operator=(const MarkovModulatedSubstitutionModel &model)
Interface for reversible substitution models.
void setRate(double rate)
Set the rate of the model (must be positive).
Definition: G2001.h:141
void setNamespace(const std::string &prefix)
Definition: G2001.h:131
G2001 & operator=(const G2001 &model)
Definition: G2001.h:100
G2001(ReversibleSubstitutionModel *model, DiscreteDistribution *rDist, double nu=1., bool normalizeRateChanges=false)
Build a new G2001 substitution model.
Definition: G2001.h:81
double getRate() const
Get the rate.
Definition: G2001.h:139
DiscreteDistribution * rDist_
Definition: G2001.h:67
G2001 * clone() const
Definition: G2001.h:110
G2001(const G2001 &model)
Definition: G2001.h:94
Partial implementation of the Markov-modulated class of substitution models.
const DiscreteDistribution * getRateDistribution() const
Definition: G2001.h:129
virtual void fireParameterChanged(const ParameterList &parameters)
Tells the model that a parameter value has changed.
std::string getName() const
Get the name of the model.
Definition: G2001.h:113
std::string nestedRatePrefix_
Definition: G2001.h:69
void fireParameterChanged(const ParameterList &parameters)
Re-definition of the super-class method to update the rate distribution too.
Definition: G2001.h:120
void updateRatesModel()
Update the rates vector, generator and equilibrium frequencies.
Definition: G2001.h:146