16 double qii = substitutionModel().Qij(i, i);
19 return i == j ? 1 : 0;
25 double rate = model().getRate();
26 double v =
exp(qii * t * rate);
27 return (transitionModel().Pij_t(i, j, t) - (i == j ? v : 0)) / (1 - v);
30 return i == j ? 0 : -substitutionModel().Qij(i, j) / qii;
42 double rate = transitionModel().getRate();
45 double v =
exp(qii * t * rate);
46 return (transitionModel().dPij_dt(i, j, t) * (1 - v) + (transitionModel().Pij_t(i, j, t) - (i == j ? 1 : 0)) * qii * rate * v) / ((1 - v) * (1 - v));
51 for (
size_t k = 0; k < size_; ++k)
53 q2ij += Q(i, k) * Q(k, j);
56 return rate * (-q2ij + qii * Q(i, j)) / (2 * qii);
62 double rate = transitionModel().getRate();
65 double qii = substitutionModel().Qij(i, i);
73 double v =
exp(qii * t * rate);
76 return -((mv * transitionModel().d2Pij_dt2(i, j, t) + 2 * qii * rate * v * transitionModel().dPij_dt(i, j, t)) * mv + (transitionModel().Pij_t(i, j, t) - (i == j ? 1 : 0)) * qii * qii * rate * rate * (v + v * v)) / (mv * mv * mv);
87 double q2ik, q2ij = 0, q3ij = 0;
89 for (
size_t k = 0; k < size_; ++k)
92 for (
size_t l = 0; l < size_; ++l)
94 q2ik += Q(i, l) * Q(l, k);
99 q3ij += q2ik * Q(k, j);
102 return -rate * rate * (2 * q3ij - 3 * qii * q2ij + qii * qii * Q(i, j)) / (12 * qii);
110 double rate = transitionModel().getRate();
112 for (
unsigned int i = 0; i < size_; ++i)
114 vector<double>& pi_t = pij_t.
getRow(i);
116 double qii = Q(i, i);
119 for (
unsigned int j = 0; j < size_; ++j)
121 pi_t[j] = (i == j ? 1 : 0);
128 const vector<double>& origPij_i = origPij.
getRow(i);
130 double v =
exp(qii * t * rate);
131 for (
unsigned int j = 0; j < size_; ++j)
133 pi_t[j] = (origPij_i[j] - (i == j ? v : 0)) / (1 - v);
138 const vector<double>& Q_i = Q.
getRow(i);
139 for (
unsigned int j = 0; j < size_; ++j)
141 pi_t[j] = (i == j ? 0 : -Q_i[j] / qii);
152 double rate = transitionModel().getRate();
158 for (
unsigned int i = 0; i < size_; ++i)
160 vector<double>& dpi_t = dpij_t.
getRow(i);
161 double qii = substitutionModel().Qij(i, i);
165 for (
unsigned int j = 0; j < size_; ++j)
173 double v =
exp(qii * t * rate);
174 double mv2 = (1 - v) * (1 - v);
175 const vector<double>& origPij_i = origPij.
getRow(i);
176 const vector<double>& origdPij_i = origdPij.
getRow(i);
178 for (
unsigned int j = 0; j < size_; ++j)
180 dpi_t[j] = (origdPij_i[j] * (1 - v) + (origPij_i[j] - (i == j ? 1 : 0)) * qii * rate * v) / mv2;
190 MatrixTools::mult<double>(Q, Q, Q2);
192 for (
unsigned int i = 0; i < size_; ++i)
194 const vector<double>& Q_i = Q.
getRow(i);
195 vector<double>& dpi_t = dpij_t.getRow(i);
200 for (
unsigned int j = 0; j < size_; ++j)
207 const vector<double>& Q2_i = Q2.
getRow(i);
209 for (
unsigned int j = 0; j < size_; ++j)
211 dpi_t[j] = rate * (-Q2_i[j] + qii * Q_i[j]) / (2 * qii);
223 double rate = transitionModel().getRate();
224 double r2 = rate * rate;
232 for (
unsigned int i = 0; i < size_; ++i)
234 double qii = substitutionModel().Qij(i, i);
235 vector<double>& d2pi_t = d2pij_t.
getRow(i);
239 for (
unsigned int j = 0; j < size_; ++j)
247 double v =
exp(rate * qii * t);
249 double q2 = qii * qii;
251 double mv3 = mv * mv * mv;
252 double vpv2 = v + v * v;
254 const vector<double>& origPij_i = origPij.
getRow(i);
255 const vector<double>& origdPij_i = origdPij.
getRow(i);
256 const vector<double>& origd2Pij_i = origd2Pij.
getRow(i);
258 for (
unsigned int j = 0; j < size_; ++j)
260 d2pi_t[j] = -((mv * origd2Pij_i[j] + 2 * qii * rate * v * origdPij_i[j]) * mv + (origPij_i[j] - (i == j ? 1 : 0)) * q2 * r2 * vpv2) / mv3;
270 MatrixTools::mult<double>(Q, Q, Q2);
272 MatrixTools::mult<double>(Q, Q2, Q3);
274 for (
unsigned int i = 0; i < size_; ++i)
276 const vector<double>& Q_i = Q.
getRow(i);
278 vector<double>& d2pi_t = d2pij_t.getRow(i);
282 for (
unsigned int j = 0; j < size_; ++j)
289 const vector<double>& Q2_i = Q2.
getRow(i);
290 const vector<double>& Q3_i = Q3.
getRow(i);
292 for (
unsigned int j = 0; j < size_; ++j)
294 d2pi_t[j] = -r2 * (2 * Q3_i[j] - 3 * qii * Q2_i[j] + qii * qii * Q_i[j]) / (12 * qii);
const Matrix< double > & getPij_t(double t) const override
const Matrix< double > & getd2Pij_dt2(double t) const override
double Pij_t(size_t i, size_t j, double t) const override
double dPij_dt(size_t i, size_t j, double t) const override
const Matrix< double > & getdPij_dt(double t) const override
double d2Pij_dt2(size_t i, size_t j, double t) const override
const std::vector< double > & getRow(size_t i) const
Defines the basic types of data flow nodes.
ExtendedFloat exp(const ExtendedFloat &ef)