14 unique_ptr<SubstitutionModelInterface> originalModel,
21 noChangedStates_(getNumberOfStates(), getNumberOfStates()),
23 registerName_(reg.getName()),
24 vNumRegs_(vector<size_t>(1, numReg))
30 auto ialph = make_shared<IntegerAlphabet>(
alphabet().getSize() + 1);
36 for (
size_t i = 0; i <
size_; ++i)
40 for (
size_t j = 0; j <
size_; ++j)
42 chS_i[j] = (reg.
getType(i, j) != numReg);
50 unique_ptr<SubstitutionModelInterface> originalModel,
52 vector<size_t> vNumRegs) :
57 noChangedStates_(getNumberOfStates(), getNumberOfStates()),
59 registerName_(reg.getName()),
68 auto ialph = make_shared<IntegerAlphabet>(
getAlphabet()->getSize() + 1);
73 for (
size_t i = 0; i <
size_; ++i)
77 for (
size_t j = 0; j <
size_; ++j)
92 for (
size_t i = 0; i <
size_; ++i)
95 const vector<double>& gen_i = gen.
getRow(i);
98 for (
size_t j = 0; j <
size_; j++)
100 if (chS_i[j] || i == j)
125 return (gen(i, j) - ch_ijt) / ch_ist;
127 return (i == j) ? 1 : 0;
144 double si = Qch(i,
size_);
151 MatrixTools::mult<double>(Qch, Qch, Qch2);
152 double dsi = Qch2(i,
size_);
157 for (
size_t k = 0; k <
size_; ++k)
159 q2ij += Q(i, k) * Q(k, j);
162 return rate * ((-q2ij + Qch2(i, j)) / si + (Q(i, j) - Qch(i, j)) * dsi / (si * si)) / 2;
165 double si = ch_t(i,
size_);
177 double r2 = rate * rate;
183 double si = Qch(i,
size_);
189 MatrixTools::mult<double>(Q, Q, Q2);
192 MatrixTools::mult<double>(Qch, Qch, Qch2);
193 MatrixTools::mult<double>(Qch, Qch2, Qch3);
195 double dsi = Qch2(i,
size_);
196 double d2si = Qch3(i,
size_);
200 for (
size_t k = 0; k <
size_; ++k)
202 q3ij += Q2(i, k) * Q(k, j);
205 return r2 * ((Q(i, j) - Qch(i, j)) * (si * d2si / 3 - dsi * dsi / 2) + (Q2(i, j) - Qch2(i, j)) * si * dsi / 2 - (q3ij - Qch3(i, j)) * si * si / 3) / (si * si * si);
216 double si = ch_t(i,
size_);
220 double si2 = si * si;
221 double dsi = dch_dt(i,
size_);
222 double d2si = d2ch_dt2(i,
size_);
224 return (d2u * si - d2si * u) / si - 2 * dsi * du / si2 + 2 * dsi * dsi * u / (si2 * si);
237 for (
size_t i = 0; i <
size_; ++i)
241 double si = Qch(i,
size_);
244 const vector<double>& qi = Q.
getRow(i);
245 const vector<double>& qchi = Qch.
getRow(i);
247 for (
size_t j = 0; j <
size_; ++j)
249 pi_t[j] = (qi[j] - qchi[j]) / si;
253 for (
size_t j = 0; j <
size_; ++j)
255 pi_t[j] = (i == j) ? 1 : 0;
264 for (
unsigned int i = 0; i <
size_; ++i)
267 const vector<double>& origi_t = orig_t.
getRow(i);
268 const vector<double>& chi_t = ch_t.
getRow(i);
270 double si = chi_t[
size_];
277 for (
unsigned int j = 0; j <
size_; ++j)
279 pi_t[j] = (origi_t[j] - chi_t[j]) / si;
297 MatrixTools::mult<double>(Qch, Qch, Qch2);
300 MatrixTools::mult<double>(Q, Q, Q2);
302 for (
size_t i = 0; i <
size_; i++)
306 const vector<double>& qchi = Qch.
getRow(i);
307 double si = qchi[
size_];
311 const vector<double>& qi = Q.
getRow(i);
312 const vector<double>& q2i = Q2.
getRow(i);
313 const vector<double>& q2chi = Qch2.
getRow(i);
314 double dsi = q2chi[
size_];
316 for (
size_t j = 0; j <
size_; ++j)
318 dpi_t[j] = rate * ((-q2i[j] + q2chi[j]) / si + (qi[j] - qchi[j]) * dsi / (si * si)) / 2;
322 for (
auto& x : dpi_t)
335 for (
unsigned int i = 0; i <
size_; ++i)
338 const vector<double>& chi_t = ch_t.
getRow(i);
340 double si = chi_t[
size_];
343 for (
auto& x : dpi_dt)
350 const vector<double>& origi_t = orig_t.
getRow(i);
351 const vector<double>& dorigi_dt = dorig_dt.
getRow(i);
352 const vector<double>& dchi_dt = dch_dt.
getRow(i);
354 double dsi = dchi_dt[
size_];
356 for (
unsigned int j = 0; j <
size_; ++j)
358 dpi_dt[j] = ((dorigi_dt[j] - dchi_dt[j]) * si - dsi * (origi_t[j] - chi_t[j])) / (si * si);
369 double r2 = rate * rate;
377 MatrixTools::mult<double>(Qch, Qch, Qch2);
378 MatrixTools::mult<double>(Qch, Qch2, Qch3);
381 MatrixTools::mult<double>(Q, Q, Q2);
382 MatrixTools::mult<double>(Q, Q2, Q3);
384 for (
size_t i = 0; i <
size_; ++i)
388 const vector<double>& qchi = Qch.
getRow(i);
389 double si = qchi[
size_];
392 const vector<double>& qi = Q.
getRow(i);
393 const vector<double>& q2i = Q2.
getRow(i);
394 const vector<double>& q2chi = Qch2.
getRow(i);
395 const vector<double>& q3i = Q3.
getRow(i);
396 const vector<double>& q3chi = Qch3.
getRow(i);
397 double dsi = Qch2(i,
size_);
398 double d2si = Qch3(i,
size_);
400 for (
size_t j = 0; j <
size_; ++j)
402 d2pi_t[j] = -r2 * ((qi[j] - qchi[j]) * (si * d2si / 3 - dsi * dsi / 2) + (q2i[j] - q2chi[j]) * si * dsi / 2 - (q3i[j] - q3chi[j]) * si * si / 3) / (si * si * si);
406 for (
auto& x : d2pi_t)
421 for (
unsigned int i = 0; i <
size_; ++i)
424 const vector<double>& chi_t = ch_t.
getRow(i);
426 double si = chi_t[
size_];
429 for (
auto& x : d2pi_dt2)
436 const vector<double>& origi_t = orig_t.
getRow(i);
437 const vector<double>& dorigi_dt = dorig_dt.
getRow(i);
438 const vector<double>& dchi_dt = dch_dt.
getRow(i);
439 const vector<double>& d2origi_dt2 = d2orig_dt2.
getRow(i);
440 const vector<double>& d2chi_dt2 = d2ch_dt2.
getRow(i);
442 double dsi = dchi_dt[
size_];
443 double d2si = d2chi_dt2[
size_];
445 double si2 = si * si;
447 for (
unsigned int j = 0; j <
size_; ++j)
449 double d2u = d2origi_dt2[j] - d2chi_dt2[j];
450 double du = dorigi_dt[j] - dchi_dt[j];
451 double u = origi_t[j] - chi_t[j];
453 d2pi_dt2[j] = -((d2u * si - d2si * u - 2 * dsi * du) / si2 + 2 * dsi * dsi * u / (si2 * si));
Virtual class of a Transition Model related to a given SubstitutionModel.
const TransitionModelInterface & transitionModel() const override
RowMatrix< double > d2pij_t
RowMatrix< double > pij_t
These ones are for bookkeeping:
const SubstitutionModelInterface & substitutionModel() const
RowMatrix< double > dpij_t
Abstract class of Wrapping model class, where all methods are redirected from model().
const Alphabet & alphabet() const override
std::shared_ptr< const Alphabet > getAlphabet() const override
virtual double getRate() const =0
Get the rate.
double Pij_t(size_t i, size_t j, double t) const override
const Matrix< double > & getd2Pij_dt2(double t) const override
std::unique_ptr< AnonymousSubstitutionModel > modelChanged_
const Matrix< double > & getPij_t(double t) const override
OneChangeRegisterTransitionModel(std::unique_ptr< SubstitutionModelInterface > originalModel, const SubstitutionRegisterInterface ®, size_t numReg)
RowMatrix< uint > noChangedStates_
const Matrix< double > & getdPij_dt(double t) const override
double getRate() const override
Get the rate.
double d2Pij_dt2(size_t i, size_t j, double t) const override
double dPij_dt(size_t i, size_t j, double t) const override
std::vector< size_t > vNumRegs_
const std::vector< Scalar > & getRow(size_t i) const
virtual const Matrix< double > & generator() const =0
The SubstitutionRegister interface.
virtual size_t getNumberOfSubstitutionTypes() const =0
virtual size_t getType(size_t fromState, size_t toState) const =0
Get the substitution type far a given pair of model states.
virtual double Pij_t(size_t i, size_t j, double t) const =0
virtual double d2Pij_dt2(size_t i, size_t j, double t) const =0
virtual const Matrix< double > & getPij_t(double t) const =0
virtual const Matrix< double > & getd2Pij_dt2(double t) const =0
virtual double dPij_dt(size_t i, size_t j, double t) const =0
virtual const Matrix< double > & getdPij_dt(double t) const =0
Defines the basic types of data flow nodes.