bpp-phyl3 3.0.0
G2001.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_MODEL_G2001_H
6#define BPP_PHYL_MODEL_G2001_H
7
10
12
13namespace bpp
14{
28class G2001 :
30{
31private:
32 std::unique_ptr<DiscreteDistributionInterface> rDist_;
33
34 std::string nestedRatePrefix_;
35
36public:
47 std::unique_ptr<ReversibleSubstitutionModelInterface> model,
48 std::unique_ptr<DiscreteDistributionInterface> rDist,
49 double nu = 1.,
50 bool normalizeRateChanges = false) :
51 MarkovModulatedSubstitutionModel(std::move(model), static_cast<unsigned int>(rDist->getNumberOfCategories()), normalizeRateChanges, "G01."),
52 rDist_(std::move(rDist)),
54 {
55 ratesFreq_ = std::vector<double>(nbRates_, 1. / static_cast<double>(nbRates_));
56 rDist_->setNamespace(getNamespace() + nestedRatePrefix_);
57 addParameters_(rDist_->getIndependentParameters());
58 addParameter_(new Parameter("G01.nu", nu, Parameter::R_PLUS));
61 }
62
63 G2001(const G2001& model) :
65 rDist_(model.rDist_->clone()),
67 {}
68
69 G2001& operator=(const G2001& model)
70 {
72 rDist_.reset(model.rDist_->clone());
74 return *this;
75 }
76
77 virtual ~G2001() { }
78
79 G2001* clone() const override { return new G2001(*this); }
80
81public:
82 std::string getName() const override { return "G01"; }
83
89 void fireParameterChanged(const ParameterList& parameters) override
90 {
91 rDist_->matchParametersValues(parameters);
93 }
94
99
100 void setNamespace(const std::string& prefix) override
101 {
103 // We also need to update the namespace of the nested distribution:
104 rDist_->setNamespace(prefix + nestedRatePrefix_);
105 }
106
107
108 double getRate() const override { return 1.; }
109
110 void setRate(double rate) override {}
111
112 void addRateParameter() override {}
113
114protected:
115 void updateRatesModel_() override
116 {
117 double nu = getParameterValue("nu");
118 for (size_t i = 0; i < nbRates_; ++i)
119 {
120 rates_(i, i) = rDist_->getCategory(i);
121 for (size_t j = 0; j < nbRates_; ++j)
122 {
123 if (i == j)
124 {
125 ratesExchangeability_(i, j) = -static_cast<double>(nbRates_) * nu;
126 }
127 else
128 {
129 ratesExchangeability_(i, j) = static_cast<double>(nbRates_) * nu / static_cast<double>(nbRates_ - 1);
130 }
131 }
132 }
133 }
134};
135} // end of namespace bpp.
136#endif // BPP_PHYL_MODEL_G2001_H
void addParameters_(const ParameterList &parameters)
void addParameter_(Parameter *parameter)
std::string getNamespace() const override
double getParameterValue(const std::string &name) const override
Galtier's 2001 covarion model.
Definition: G2001.h:30
G2001(const G2001 &model)
Definition: G2001.h:63
const DiscreteDistributionInterface & rateDistribution() const
Definition: G2001.h:98
std::unique_ptr< DiscreteDistributionInterface > rDist_
Definition: G2001.h:32
G2001 & operator=(const G2001 &model)
Definition: G2001.h:69
std::string nestedRatePrefix_
Definition: G2001.h:34
G2001(std::unique_ptr< ReversibleSubstitutionModelInterface > model, std::unique_ptr< DiscreteDistributionInterface > rDist, double nu=1., bool normalizeRateChanges=false)
Build a new G2001 substitution model.
Definition: G2001.h:46
virtual ~G2001()
Definition: G2001.h:77
void setRate(double rate) override
Set the rate of the model (must be positive).
Definition: G2001.h:110
void fireParameterChanged(const ParameterList &parameters) override
Re-definition of the super-class method to update the rate distribution too.
Definition: G2001.h:89
G2001 * clone() const override
Definition: G2001.h:79
void updateRatesModel_() override
Update the rates vector, generator and equilibrium frequencies.
Definition: G2001.h:115
void addRateParameter() override
Definition: G2001.h:112
double getRate() const override
Get the rate.
Definition: G2001.h:108
std::string getName() const override
Get the name of the model.
Definition: G2001.h:82
void setNamespace(const std::string &prefix) override
Definition: G2001.h:100
Partial implementation of the Markov-modulated class of substitution models.
MarkovModulatedSubstitutionModel & operator=(const MarkovModulatedSubstitutionModel &model)
virtual void fireParameterChanged(const ParameterList &parameters) override
Tells the model that a parameter value has changed.
void setNamespace(const std::string &prefix) override
static const std::shared_ptr< IntervalConstraint > R_PLUS
Defines the basic types of data flow nodes.