bpp-phyl3 3.0.0
D1WalkSubstitutionModel.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// From bpp-seq:
9
10using namespace bpp;
11
12#include <cmath>
13#include <map>
14
15using namespace std;
16
17/******************************************************************************/
18
19D1WalkSubstitutionModel::D1WalkSubstitutionModel(std::shared_ptr<const IntegerAlphabet> alpha, unsigned short method) :
21 AbstractReversibleSubstitutionModel(alpha, std::shared_ptr<StateMapInterface>(new CanonicalStateMap(alpha, false)), "D1Walk."),
22 freqSet_(0)
23{
24 freqSet_ = std::make_shared<FullFrequencySet>(getStateMap(), true, method);
25 freqSet_->setNamespace("D1Walk.");
26 computeFrequencies(false);
27
28 addParameters_(freqSet_->getParameters());
29 // Exchangeability Matrix:
30 for (unsigned int i = 0; i < size_ - 1; i++)
31 {
32 exchangeability_(i, i + 1) = 1;
33 }
34
35 for (unsigned int i = 1; i < size_; i++)
36 {
37 exchangeability_(i, i - 1) = 1;
38 }
39
41}
42
43/******************************************************************************/
44
46{
47 // Frequencies:
48 freq_ = freqSet_->getFrequencies();
49
51}
52
53
54/******************************************************************************/
55
56void D1WalkSubstitutionModel::setFreq(std::map<int, double>& freqs)
57{
58 for (auto i : freqs)
59 {
60 freq_[(size_t)i.first] = i.second;
61 }
62
63 freqSet_->setFrequencies(freq_);
64 // Update parameters and re-compute generator and eigen values:
65 matchParametersValues(freqSet_->getParameters());
66}
67
68/******************************************************************************/
void addParameters_(const ParameterList &parameters)
bool matchParametersValues(const ParameterList &parameters) override
Partial implementation of the ReversibleSubstitutionModel interface.
virtual void updateMatrices_() override
Compute and diagonalize the matrix, and fill the eigenValues_, leftEigenVectors_ and rightEigenVecto...
RowMatrix< double > exchangeability_
The exchangeability matrix of the model, defined as . When the model is reversible,...
size_t size_
The number of states.
Vdouble freq_
The vector of equilibrium frequencies.
std::shared_ptr< const StateMapInterface > getStateMap() const override
This class implements a state map where all resolved states are modeled.
Definition: StateMap.h:168
void setFreq(std::map< int, double > &freq) override
Set equilibrium frequencies.
std::shared_ptr< FullFrequencySet > freqSet_
The Equilibrium Frequency Set.
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:25
Defines the basic types of data flow nodes.