bpp-phyl3  3.0.0
L95.cpp
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: The Bio++ Development Group
2 //
3 // SPDX-License-Identifier: CECILL-2.1
4 
6 
7 #include "../FrequencySet/NucleotideFrequencySet.h"
8 #include "L95.h"
9 
10 // From the STL:
11 #include <cmath>
12 
13 using namespace bpp;
14 using namespace std;
15 
16 /******************************************************************************/
17 
19  shared_ptr<const NucleicAlphabet> alphabet,
20  double alpha, double beta, double gamma, double kappa, double theta) :
23  alphabet,
24  make_shared<CanonicalStateMap>(alphabet, false),
25  "L95."),
26  alpha_(alpha), beta_(beta), gamma_(gamma), kappa_(kappa), theta_(theta)
27 {
28  addParameter_(new Parameter("L95.alpha", alpha, Parameter::PROP_CONSTRAINT_IN));
30  addParameter_(new Parameter("L95.gamma", gamma, Parameter::PROP_CONSTRAINT_IN));
31  addParameter_(new Parameter("L95.kappa", kappa, make_shared<IntervalConstraint>(0, 1000, false, false, NumConstants::MILLI())));
32  addParameter_(new Parameter("L95.theta", theta, make_shared<IntervalConstraint>(0, 1, false, false, NumConstants::MILLI())));
33 
34  computeFrequencies(false);
36 }
37 
38 /******************************************************************************/
39 
41 {
42  alpha_ = getParameterValue("alpha");
43  beta_ = getParameterValue("beta");
44  gamma_ = getParameterValue("gamma");
45  kappa_ = getParameterValue("kappa");
46  theta_ = getParameterValue("theta");
47 
48  freq_[0] = (1 - theta_) / 2;
49  freq_[1] = theta_ / 2;
50  freq_[2] = theta_ / 2;
51  freq_[3] = (1 - theta_) / 2;
52 
53  // Generator matrix:
54  generator_(0, 0) = -kappa_ * theta_ - gamma_;
55  generator_(0, 1) = kappa_ * beta_ * theta_;
56  generator_(0, 2) = kappa_ * (1 - beta_) * theta_;
57  generator_(0, 3) = gamma_;
58  generator_(1, 0) = kappa_ * alpha_ * ( 1 - theta_);
59  generator_(1, 1) = -kappa_ * (1 - theta_) + gamma_ - 1;
60  generator_(1, 2) = 1 - gamma_;
61  generator_(1, 3) = kappa_ * (1 - theta_) * (1 - alpha_);
62  generator_(2, 0) = kappa_ * (1 - theta_) * (1 - alpha_);
63  generator_(2, 1) = 1 - gamma_;
64  generator_(2, 2) = -kappa_ * (1 - theta_) + gamma_ - 1;
65  generator_(2, 3) = kappa_ * alpha_ * (1 - theta_);
66  generator_(3, 0) = gamma_;
67  generator_(3, 1) = kappa_ * (1 - beta_) * theta_;
68  generator_(3, 2) = kappa_ * beta_ * theta_;
69  generator_(3, 3) = -kappa_ * theta_ - gamma_;
70 
71  setScale(1. / (2 * kappa_ * theta_ * (1 - theta_) + gamma_ + theta_ - 2 * theta_ * gamma_));
72 
74 }
75 
76 /******************************************************************************/
77 
78 void L95::setFreq(map<int, double>& freqs)
79 {
80  setParameterValue("theta", freqs[1] + freqs[2]);
82 }
83 
84 /******************************************************************************/
Specialisation abstract class for nucleotide substitution model.
void addParameter_(Parameter *parameter)
void setParameterValue(const std::string &name, double value) override
double getParameterValue(const std::string &name) const override
RowMatrix< double > generator_
The generator matrix of the model.
virtual void updateMatrices_()
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
void setScale(double scale)
Multiplies the current generator by the given scale.
Vdouble freq_
The vector of equilibrium frequencies.
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
double kappa_
Definition: L95.h:61
double beta_
Definition: L95.h:61
double alpha_
Definition: L95.h:61
void setFreq(std::map< int, double > &) override
This method is redefined to actualize the corresponding parameters theta too.
Definition: L95.cpp:78
double gamma_
Definition: L95.h:61
double theta_
Definition: L95.h:61
void updateMatrices_() override
Diagonalize the matrix, and fill the eigenValues_, iEigenValues_, leftEigenVectors_ and rightEigenVe...
Definition: L95.cpp:40
L95(std::shared_ptr< const NucleicAlphabet > alphabet, double alpha=0.5, double beta=0.5, double gamma=0.5, double kappa=1., double theta=0.5)
Definition: L95.cpp:18
static double MILLI()
static const std::shared_ptr< IntervalConstraint > PROP_CONSTRAINT_IN
Defines the basic types of data flow nodes.