20 for (
size_t i = 0; i < s; i++)
22 for (
size_t j = 0; j < s; j++)
24 QL(i, j) = ((i == j) ? 0. : Q(i, j));
33 for (
size_t n = 1; n < cutOff_; ++n)
36 for (
size_t p = 0; p < n; ++p)
50 for (
size_t i = 0; i < s; i++)
52 for (
size_t j = 0; j < s; j++)
64 throw Exception(
"LaplaceSubstitutionCount::getNumberOfSubstitutions: model not defined.");
66 if (length == currentLength_)
67 return m_(initialState, finalState);
68 if (length < 0.000001)
69 return initialState == finalState ? 0. : 1.;
71 computeCounts(length);
73 currentLength_ = length;
74 return m_(initialState, finalState);
82 throw Exception(
"LaplaceSubstitutionCount::getAllNumbersOfSubstitutions: model not defined.");
84 if (length == currentLength_)
85 return make_unique<RowMatrix<double>>(m_);
86 if (length < 0.000001)
88 size_t s = model_->getAlphabet()->getSize();
89 for (
size_t i = 0; i < s; i++)
91 for (
size_t j = 0; j < s; j++)
93 m_(i, j) = i == j ? 0. : 1.;
100 computeCounts(length);
103 currentLength_ = length;
105 return make_unique<RowMatrix<double>>(m_);
113 throw Exception(
"LaplaceSubstitutionCount::storeAllNumbersOfSubstitutions: model not defined.");
115 auto s = Eigen::Index(model_->getAlphabet()->getSize());
116 if (length == currentLength_)
117 mat = Eigen::MatrixXd::Zero(s, s);
119 if (length < 0.000001)
121 for (
auto i = 0; i < s; i++)
123 for (
auto j = 0; j < s; j++)
125 mat(i, j) = i == j ? 0. : 1.;
132 computeCounts(length);
135 currentLength_ = length;
139 for (
auto i = 0; i < s; i++)
141 for (
auto j = 0; j < s; j++)
143 mat(i, j) = std::isnan(m_(
size_t(i),
size_t(j))) ? 0 : m_(
size_t(i),
size_t(j));
151 shared_ptr<const SubstitutionModelInterface> model)
157 size_t n = model->alphabet().getSize();
160 if (currentLength_ > 0)
161 computeCounts(currentLength_);
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,...
void setSubstitutionModel(std::shared_ptr< const SubstitutionModelInterface > model) override
Set the substitution model associated with this count, if relevant.
void computeCounts(double length) const
double getNumberOfSubstitutions(size_t initialState, size_t finalState, double length, size_t type=1) const override
Get the number of susbstitutions on a branch, given the initial and final states, and the branch leng...
std::unique_ptr< Matrix< double > > getAllNumbersOfSubstitutions(double length, size_t type=1) const override
Get the numbers of susbstitutions on a branch, for each initial and final states, and given the branc...
size_t getNumberOfRows() const
Defines the basic types of data flow nodes.
ExtendedFloat pow(const ExtendedFloat &ef, double exp)