bpp-phyl3 3.0.0
NaiveSubstitutionCount.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
7using namespace bpp;
8using namespace std;
9
10unique_ptr<Matrix<double>> NaiveSubstitutionCount::getAllNumbersOfSubstitutions(double length, size_t type) const
11{
12 size_t n = supportedChars_.size();
13 auto mat = make_unique<RowMatrix<double>>(n, n);
14 for (size_t i = 0; i < n; ++i)
15 {
16 for (size_t j = 0; j < n; ++j)
17 {
18 (*mat)(i, j) = (register_->getType(i, j) == type ? (weights_ ? weights_->getIndex(supportedChars_[i], supportedChars_[j]) : 1.) : 0.);
19 }
20 }
21 return mat;
22}
23
24void NaiveSubstitutionCount::storeAllNumbersOfSubstitutions(double length, size_t type, Eigen::MatrixXd& mat) const
25{
26 auto n = Eigen::Index(supportedChars_.size());
27 mat.resize(n, n);
28
29 for (auto i = 0; i < n; ++i)
30 {
31 for (auto j = 0; j < n; ++j)
32 {
33 mat(i, j) = (register_->getType(size_t(i), size_t(j)) == type ? (weights_ ? weights_->getIndex(supportedChars_[size_t(i)], supportedChars_[size_t(j)]) : 1.) : 0.);
34 }
35 }
36}
37
38
40 std::shared_ptr<const SubstitutionModelInterface> model) :
42 make_shared<TotalSubstitutionRegister>(model->getStateMap())),
43 label_(model->getNumberOfStates(), model->getNumberOfStates()),
44 supportedChars_(model->getAlphabetStates())
45{
46 size_t n = supportedChars_.size();
47 double count = 0;
48 for (size_t i = 0; i < n; ++i)
49 {
50 for (size_t j = 0; j < n; ++j)
51 {
52 if (i == j)
53 label_(i, j) = 0;
54 else
55 label_(i, j) = ++count;
56 }
57 }
58}
59
61 std::shared_ptr<const StateMapInterface> stateMap) :
63 make_shared<TotalSubstitutionRegister>(stateMap)),
64 label_(stateMap->getNumberOfModelStates(), stateMap->getNumberOfModelStates()),
65 supportedChars_(stateMap->getAlphabetStates())
66{
67 size_t n = supportedChars_.size();
68 double count = 0;
69 for (size_t i = 0; i < n; ++i)
70 {
71 for (size_t j = 0; j < n; ++j)
72 {
73 if (i == j)
74 label_(i, j) = 0;
75 else
76 label_(i, j) = ++count;
77 }
78 }
79}
Partial implementation of the SubstitutionCount interface.
std::shared_ptr< const SubstitutionRegisterInterface > register_
std::shared_ptr< const AlphabetIndex2 > weights_
LabelSubstitutionCount(std::shared_ptr< const SubstitutionModelInterface > model)
void storeAllNumbersOfSubstitutions(double length, size_t type, Eigen::MatrixXd &mat) const override
Stores the numbers of susbstitutions on a branch, for each initial and final states,...
std::size_t count(const std::string &s, const std::string &pattern)
Defines the basic types of data flow nodes.