bpp-phyl3 3.0.0
OneJumpSubstitutionCount.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>> OneJumpSubstitutionCount::getAllNumbersOfSubstitutions(double length, size_t type) const
11{
12 if (!model_)
13 throw Exception("OneJumpSubstitutionCount::getAllNumberOfSubstitutions: model not defined.");
14
15 tmp_ = model_->getPij_t(length);
16 size_t n = model_->getNumberOfStates();
17 auto probs = make_unique<LinearMatrix<double>>(n, n);
18 for (size_t i = 0; i < n; ++i)
19 {
20 for (size_t j = 0; j < n; ++j)
21 {
22 (*probs)(i, j) = (i == j ? 1. - tmp_(i, j) : 1.);
23 }
24 }
25 return probs;
26}
27
28void OneJumpSubstitutionCount::storeAllNumbersOfSubstitutions(double length, size_t type, Eigen::MatrixXd& mat) const
29{
30 if (!model_)
31 throw Exception("OneJumpSubstitutionCount::storeNumberOfSubstitutions: model not defined.");
32
33 tmp_ = model_->getPij_t(length);
34 auto n = Eigen::Index(model_->getNumberOfStates());
35
36 mat.resize(n, n);
37 for (auto i = 0; i < n; i++)
38 {
39 for (auto j = 0; j < n; j++)
40 {
41 mat(i, j) = (i == j ? 1. - tmp_(size_t(i), size_t(j)) : 1.);
42 }
43 }
44}
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,...
Defines the basic types of data flow nodes.