8 #include "../../PatternTools.h"
27 std::shared_ptr<SubstitutionModelSet> modelSet,
28 std::shared_ptr<DiscreteDistributionInterface> rDist,
30 bool reparametrizeRoot) :
35 if (!modelSet->isFullySetUpFor(
tree))
36 throw Exception(
"DRNonHomogeneousTreeLikelihood(constructor). Model set is not fully specified.");
45 std::shared_ptr<SubstitutionModelSet> modelSet,
46 std::shared_ptr<DiscreteDistributionInterface> rDist,
48 bool reparametrizeRoot) :
53 if (!modelSet->isFullySetUpFor(
tree))
54 throw Exception(
"DRNonHomogeneousTreeLikelihood(constructor). Model set is not fully specified.");
73 minusLogLik_(lik.minusLogLik_)
121 l *=
std::pow((*lik)[i], (
int)(*w)[i]);
136 la[i] = (*w)[i] *
log((*lik)[i]);
138 sort(la.begin(), la.end());
208 for (
size_t i = 0; i < tmp.size(); i++)
210 vector<int> tmpv =
modelSet_->getNodesWithParameter(tmp[i]);
214 vector<const Node*> nodes;
215 for (
size_t i = 0; i < ids.size(); i++)
219 vector<const Node*> tmpv;
221 for (
size_t i = 0; i < tmp.size(); i++)
223 if (tmp[i] ==
"BrLenRoot" || tmp[i] ==
"RootPosition")
227 tmpv.push_back(
tree_->getRootNode()->getSon(0));
228 tmpv.push_back(
tree_->getRootNode()->getSon(1));
233 tmpv.push_back(
nodes_[TextTools::to< size_t >(tmp[i].substr(5))]);
237 for (
size_t i = 0; i < nodes.size(); i++)
259 throw Exception(
"DRNonHomogeneousTreeLikelihood::getValue(). Instance is not initialized.");
277 double dLi, dLic, dLicx, numerator, denominator;
280 VVdouble* _likelihoods_father_node_i = &(*_likelihoods_father_node)[i];
285 Vdouble* _likelihoods_father_node_i_c = &(*_likelihoods_father_node_i)[c];
286 Vdouble* larray_i_c = &(*larray_i)[c];
287 VVdouble* pxy__node_c = &(*pxy__node)[c];
288 VVdouble* dpxy__node_c = &(*dpxy__node)[c];
294 Vdouble* pxy__node_c_x = &(*pxy__node_c)[x];
295 Vdouble* dpxy__node_c_x = &(*dpxy__node_c)[x];
299 numerator += (*dpxy__node_c_x)[y] * (*_likelihoods_father_node_i_c)[y];
300 denominator += (*pxy__node_c_x)[y] * (*_likelihoods_father_node_i_c)[y];
302 dLicx = denominator == 0. ? 0. : (*larray_i_c)[x] * numerator / denominator;
307 (*_dLikelihoods_node)[i] = dLi / (*rootLikelihoodsSR)[i];
315 for (
size_t k = 0; k <
nbNodes_; k++)
329 throw Exception(
"Derivatives respective to rate distribution parameters are not implemented.");
333 throw Exception(
"Derivatives respective to substitution model parameters are not implemented.");
341 if (variable ==
"BrLenRoot")
347 d1 -= (*w)[i] * (*_dLikelihoods_branch)[i];
353 d2 -= (*w)[i] * (*_dLikelihoods_branch)[i];
356 return pos * d1 + (1. - pos) * d2;
358 else if (variable ==
"RootPosition")
364 d1 -= (*w)[i] * (*_dLikelihoods_branch)[i];
370 d2 -= (*w)[i] * (*_dLikelihoods_branch)[i];
373 return len * (d1 - d2);
378 size_t brI = TextTools::to<size_t>(variable.substr(5));
384 d += (*w)[i] * (*_dLikelihoods_branch)[i];
404 double d2Li, d2Lic, d2Licx, numerator, denominator;
408 VVdouble* _likelihoods_father_node_i = &(*_likelihoods_father_node)[i];
413 Vdouble* _likelihoods_father_node_i_c = &(*_likelihoods_father_node_i)[c];
414 Vdouble* larray_i_c = &(*larray_i)[c];
415 VVdouble* pxy__node_c = &(*pxy__node)[c];
416 VVdouble* d2pxy__node_c = &(*d2pxy__node)[c];
422 Vdouble* pxy__node_c_x = &(*pxy__node_c)[x];
423 Vdouble* d2pxy__node_c_x = &(*d2pxy__node_c)[x];
427 numerator += (*d2pxy__node_c_x)[y] * (*_likelihoods_father_node_i_c)[y];
428 denominator += (*pxy__node_c_x)[y] * (*_likelihoods_father_node_i_c)[y];
430 d2Licx = denominator == 0. ? 0. : (*larray_i_c)[x] * numerator / denominator;
435 (*_d2Likelihoods_node)[i] = d2Li / (*rootLikelihoodsSR)[i];
443 for (
size_t k = 0; k <
nbNodes_; k++)
457 throw Exception(
"Derivatives respective to rate distribution parameters are not implemented.");
461 throw Exception(
"Derivatives respective to substitution model parameters are not implemented.");
472 if (variable ==
"BrLenRoot")
474 const Node* father =
tree_->getRootNode();
482 VVdouble* dLikelihoods_father_i = &dLikelihoods_father[i];
483 VVdouble* d2Likelihoods_father_i = &d2Likelihoods_father[i];
488 Vdouble* dLikelihoods_father_i_c = &(*dLikelihoods_father_i)[c];
489 Vdouble* d2Likelihoods_father_i_c = &(*d2Likelihoods_father_i)[c];
490 dLikelihoods_father_i_c->resize(
nbStates_);
491 d2Likelihoods_father_i_c->resize(
nbStates_);
494 (*dLikelihoods_father_i_c)[s] = 1.;
495 (*d2Likelihoods_father_i_c)[s] = 1.;
501 for (
size_t l = 0; l < nbNodes; l++)
519 VVdouble* _likelihoodsroot1__i = &(*_likelihoodsroot1_)[i];
520 VVdouble* _likelihoodsroot2__i = &(*_likelihoodsroot2_)[i];
521 VVdouble* dLikelihoods_father_i = &dLikelihoods_father[i];
522 VVdouble* d2Likelihoods_father_i = &d2Likelihoods_father[i];
525 Vdouble* _likelihoodsroot1__i_c = &(*_likelihoodsroot1__i)[c];
526 Vdouble* _likelihoodsroot2__i_c = &(*_likelihoodsroot2__i)[c];
527 Vdouble* dLikelihoods_father_i_c = &(*dLikelihoods_father_i)[c];
528 Vdouble* d2Likelihoods_father_i_c = &(*d2Likelihoods_father_i)[c];
529 VVdouble* d2pxy_root1__c = &(*d2pxy_root1_)[c];
530 VVdouble* d2pxy_root2__c = &(*d2pxy_root2_)[c];
531 VVdouble* dpxy_root1__c = &(*dpxy_root1_)[c];
532 VVdouble* dpxy_root2__c = &(*dpxy_root2_)[c];
533 VVdouble* pxy_root1__c = &(*pxy_root1_)[c];
534 VVdouble* pxy_root2__c = &(*pxy_root2_)[c];
537 Vdouble* d2pxy_root1__c_x = &(*d2pxy_root1__c)[x];
538 Vdouble* d2pxy_root2__c_x = &(*d2pxy_root2__c)[x];
539 Vdouble* dpxy_root1__c_x = &(*dpxy_root1__c)[x];
540 Vdouble* dpxy_root2__c_x = &(*dpxy_root2__c)[x];
541 Vdouble* pxy_root1__c_x = &(*pxy_root1__c)[x];
542 Vdouble* pxy_root2__c_x = &(*pxy_root2__c)[x];
543 double d2l1 = 0, d2l2 = 0, dl1 = 0, dl2 = 0, l1 = 0, l2 = 0;
546 d2l1 += (*d2pxy_root1__c_x)[y] * (*_likelihoodsroot1__i_c)[y];
547 d2l2 += (*d2pxy_root2__c_x)[y] * (*_likelihoodsroot2__i_c)[y];
548 dl1 += (*dpxy_root1__c_x)[y] * (*_likelihoodsroot1__i_c)[y];
549 dl2 += (*dpxy_root2__c_x)[y] * (*_likelihoodsroot2__i_c)[y];
550 l1 += (*pxy_root1__c_x)[y] * (*_likelihoodsroot1__i_c)[y];
551 l2 += (*pxy_root2__c_x)[y] * (*_likelihoodsroot2__i_c)[y];
553 double dl = pos * dl1 * l2 + (1. - pos) * dl2 * l1;
554 double d2l = pos * pos * d2l1 * l2 + (1. - pos) * (1. - pos) * d2l2 * l1 + 2 * pos * (1. - pos) * dl1 * dl2;
555 (*dLikelihoods_father_i_c)[x] *= dl;
556 (*d2Likelihoods_father_i_c)[x] *= d2l;
573 VVdouble* _likelihoods_son_i = &(*_likelihoods_son)[i];
574 VVdouble* dLikelihoods_father_i = &dLikelihoods_father[i];
575 VVdouble* d2Likelihoods_father_i = &d2Likelihoods_father[i];
578 Vdouble* _likelihoods_son_i_c = &(*_likelihoods_son_i)[c];
579 Vdouble* dLikelihoods_father_i_c = &(*dLikelihoods_father_i)[c];
580 Vdouble* d2Likelihoods_father_i_c = &(*d2Likelihoods_father_i)[c];
581 VVdouble* pxy__son_c = &(*pxy__son)[c];
585 Vdouble* pxy__son_c_x = &(*pxy__son_c)[x];
588 dl += (*pxy__son_c_x)[y] * (*_likelihoods_son_i_c)[y];
590 (*dLikelihoods_father_i_c)[x] *= dl;
591 (*d2Likelihoods_father_i_c)[x] *= dl;
598 double d2l = 0, dlx, d2lx;
601 VVdouble* dLikelihoods_father_i = &dLikelihoods_father[i];
602 VVdouble* d2Likelihoods_father_i = &d2Likelihoods_father[i];
606 Vdouble* dLikelihoods_father_i_c = &(*dLikelihoods_father_i)[c];
607 Vdouble* d2Likelihoods_father_i_c = &(*d2Likelihoods_father_i)[c];
614 d2l += (*w)[i] * (d2lx / (*rootLikelihoodsSR)[i] -
pow(dlx / (*rootLikelihoodsSR)[i], 2));
618 else if (variable ==
"RootPosition")
620 const Node* father =
tree_->getRootNode();
628 VVdouble* dLikelihoods_father_i = &dLikelihoods_father[i];
629 VVdouble* d2Likelihoods_father_i = &d2Likelihoods_father[i];
634 Vdouble* dLikelihoods_father_i_c = &(*dLikelihoods_father_i)[c];
635 Vdouble* d2Likelihoods_father_i_c = &(*d2Likelihoods_father_i)[c];
636 dLikelihoods_father_i_c->resize(
nbStates_);
637 d2Likelihoods_father_i_c->resize(
nbStates_);
640 (*dLikelihoods_father_i_c)[s] = 1.;
641 (*d2Likelihoods_father_i_c)[s] = 1.;
647 for (
size_t l = 0; l < nbNodes; l++)
665 VVdouble* _likelihoodsroot1__i = &(*_likelihoodsroot1_)[i];
666 VVdouble* _likelihoodsroot2__i = &(*_likelihoodsroot2_)[i];
667 VVdouble* dLikelihoods_father_i = &dLikelihoods_father[i];
668 VVdouble* d2Likelihoods_father_i = &d2Likelihoods_father[i];
671 Vdouble* _likelihoodsroot1__i_c = &(*_likelihoodsroot1__i)[c];
672 Vdouble* _likelihoodsroot2__i_c = &(*_likelihoodsroot2__i)[c];
673 Vdouble* dLikelihoods_father_i_c = &(*dLikelihoods_father_i)[c];
674 Vdouble* d2Likelihoods_father_i_c = &(*d2Likelihoods_father_i)[c];
675 VVdouble* d2pxy_root1__c = &(*d2pxy_root1_)[c];
676 VVdouble* d2pxy_root2__c = &(*d2pxy_root2_)[c];
677 VVdouble* dpxy_root1__c = &(*dpxy_root1_)[c];
678 VVdouble* dpxy_root2__c = &(*dpxy_root2_)[c];
679 VVdouble* pxy_root1__c = &(*pxy_root1_)[c];
680 VVdouble* pxy_root2__c = &(*pxy_root2_)[c];
683 Vdouble* d2pxy_root1__c_x = &(*d2pxy_root1__c)[x];
684 Vdouble* d2pxy_root2__c_x = &(*d2pxy_root2__c)[x];
685 Vdouble* dpxy_root1__c_x = &(*dpxy_root1__c)[x];
686 Vdouble* dpxy_root2__c_x = &(*dpxy_root2__c)[x];
687 Vdouble* pxy_root1__c_x = &(*pxy_root1__c)[x];
688 Vdouble* pxy_root2__c_x = &(*pxy_root2__c)[x];
689 double d2l1 = 0, d2l2 = 0, dl1 = 0, dl2 = 0, l1 = 0, l2 = 0;
692 d2l1 += (*d2pxy_root1__c_x)[y] * (*_likelihoodsroot1__i_c)[y];
693 d2l2 += (*d2pxy_root2__c_x)[y] * (*_likelihoodsroot2__i_c)[y];
694 dl1 += (*dpxy_root1__c_x)[y] * (*_likelihoodsroot1__i_c)[y];
695 dl2 += (*dpxy_root2__c_x)[y] * (*_likelihoodsroot2__i_c)[y];
696 l1 += (*pxy_root1__c_x)[y] * (*_likelihoodsroot1__i_c)[y];
697 l2 += (*pxy_root2__c_x)[y] * (*_likelihoodsroot2__i_c)[y];
699 double dl = len * (dl1 * l2 - dl2 * l1);
700 double d2l = len * len * (d2l1 * l2 + d2l2 * l1 - 2 * dl1 * dl2);
701 (*dLikelihoods_father_i_c)[x] *= dl;
702 (*d2Likelihoods_father_i_c)[x] *= d2l;
719 VVdouble* _likelihoods_son_i = &(*_likelihoods_son)[i];
720 VVdouble* dLikelihoods_father_i = &dLikelihoods_father[i];
721 VVdouble* d2Likelihoods_father_i = &d2Likelihoods_father[i];
724 Vdouble* _likelihoods_son_i_c = &(*_likelihoods_son_i)[c];
725 Vdouble* dLikelihoods_father_i_c = &(*dLikelihoods_father_i)[c];
726 Vdouble* d2Likelihoods_father_i_c = &(*d2Likelihoods_father_i)[c];
727 VVdouble* pxy__son_c = &(*pxy__son)[c];
731 Vdouble* pxy__son_c_x = &(*pxy__son_c)[x];
734 dl += (*pxy__son_c_x)[y] * (*_likelihoods_son_i_c)[y];
736 (*dLikelihoods_father_i_c)[x] *= dl;
737 (*d2Likelihoods_father_i_c)[x] *= dl;
744 double d2l = 0, dlx, d2lx;
747 VVdouble* dLikelihoods_father_i = &dLikelihoods_father[i];
748 VVdouble* d2Likelihoods_father_i = &d2Likelihoods_father[i];
752 Vdouble* dLikelihoods_father_i_c = &(*dLikelihoods_father_i)[c];
753 Vdouble* d2Likelihoods_father_i_c = &(*d2Likelihoods_father_i)[c];
760 d2l += (*w)[i] * (d2lx / (*rootLikelihoodsSR)[i] -
pow(dlx / (*rootLikelihoodsSR)[i], 2));
767 Vdouble* _d2Likelihoods_branch;
769 size_t brI = TextTools::to<size_t>(variable.substr(5));
776 d2l += (*w)[i] * ((*_d2Likelihoods_branch)[i] -
pow((*_dLikelihoods_branch)[i], 2));
821 for (
size_t l = 0; l < nbNodes; l++)
826 VVVdouble* _likelihoods_node_son = &(*_likelihoods_node)[son->
getId()];
834 Vdouble* _likelihoods_leaf_i = &(*_likelihoods_leaf)[i];
835 VVdouble* _likelihoods_node_son_i = &(*_likelihoods_node_son)[i];
839 Vdouble* _likelihoods_node_son_i_c = &(*_likelihoods_node_son_i)[c];
843 (*_likelihoods_node_son_i_c)[x] = (*_likelihoods_leaf_i)[x];
854 vector<const VVVdouble*> iLik(nbSons);
855 vector<const VVVdouble*> tProb(nbSons);
856 for (
size_t n = 0; n < nbSons; n++)
860 iLik[n] = &(*_likelihoods_son)[sonSon->
getId()];
876 for (
size_t n = 0; n < nbSons; n++)
886 map<int, VVVdouble>* _likelihoods_father = &
likelihoodData_->getLikelihoodArrays(father->
getId());
887 VVVdouble* _likelihoods_node_father = &(*_likelihoods_node)[father->
getId()];
900 Vdouble* _likelihoods_leaf_i = &(*_likelihoods_leaf)[i];
901 VVdouble* _likelihoods_node_father_i = &(*_likelihoods_node_father)[i];
905 Vdouble* _likelihoods_node_father_i_c = &(*_likelihoods_node_father_i)[c];
909 (*_likelihoods_node_father_i_c)[x] = (*_likelihoods_leaf_i)[x];
916 vector<const Node*> nodes;
919 for (
size_t n = 0; n < nbFatherSons; n++)
923 nodes.push_back(son);
929 size_t nbSons = nodes.size();
931 vector<const VVVdouble*> iLik(nbSons);
932 vector<const VVVdouble*> tProb(nbSons);
933 for (
size_t n = 0; n < nbSons; n++)
935 const Node* fatherSon = nodes[n];
937 iLik[n] = &(*_likelihoods_father)[fatherSon->
getId()];
956 VVdouble* _likelihoods_node_father_i = &(*_likelihoods_node_father)[i];
959 Vdouble* _likelihoods_node_father_i_c = &(*_likelihoods_node_father_i)[c];
962 (*_likelihoods_node_father_i_c)[x] *=
rootFreqs_[x];
970 for (
size_t i = 0; i < nbNodeSons; i++)
989 VVdouble* rootLikelihoods_i = &(*rootLikelihoods)[i];
990 Vdouble* leavesLikelihoods_root_i = &(*leavesLikelihoods_root)[i];
993 Vdouble* rootLikelihoods_i_c = &(*rootLikelihoods_i)[c];
996 (*rootLikelihoods_i_c)[x] = (*leavesLikelihoods_root_i)[x];
1008 vector<const VVVdouble*> iLik(nbNodes);
1009 vector<const VVVdouble*> tProb(nbNodes);
1010 for (
size_t n = 0; n < nbNodes; n++)
1014 iLik[n] = &(*likelihoods_root)[son->
getId()];
1024 VVdouble* rootLikelihoods_i = &(*rootLikelihoods)[i];
1025 Vdouble* rootLikelihoodsS_i = &(*rootLikelihoodsS)[i];
1026 (*rootLikelihoodsSR)[i] = 0;
1030 Vdouble* rootLikelihoods_i_c = &(*rootLikelihoods_i)[c];
1031 double* rootLikelihoodsS_i_c = &(*rootLikelihoodsS_i)[c];
1032 (*rootLikelihoodsS_i_c) = 0;
1036 (*rootLikelihoodsS_i_c) +=
rootFreqs_[x] * (*rootLikelihoods_i_c)[x];
1038 (*rootLikelihoodsSR)[i] += p[c] * (*rootLikelihoodsS_i_c);
1042 if ((*rootLikelihoodsSR)[i] < 0)
1043 (*rootLikelihoodsSR)[i] = 0.;
1052 int nodeId = node->
getId();
1062 VVdouble* likelihoodArray_i = &likelihoodArray[i];
1063 Vdouble* leavesLikelihoods_node_i = &(*leavesLikelihoods_node)[i];
1067 Vdouble* likelihoodArray_i_c = &(*likelihoodArray_i)[c];
1071 (*likelihoodArray_i_c)[x] = (*leavesLikelihoods_node_i)[x];
1082 VVdouble* likelihoodArray_i = &likelihoodArray[i];
1086 Vdouble* likelihoodArray_i_c = &(*likelihoodArray_i)[c];
1090 (*likelihoodArray_i_c)[x] = 1.;
1098 vector<const VVVdouble*> iLik(nbNodes);
1099 vector<const VVVdouble*> tProb(nbNodes);
1100 for (
size_t n = 0; n < nbNodes; n++)
1104 iLik[n] = &(*likelihoods_node)[son->
getId()];
1119 VVdouble* likelihoodArray_i = &likelihoodArray[i];
1122 Vdouble* likelihoodArray_i_c = &(*likelihoodArray_i)[c];
1135 const vector<const VVVdouble*>& iLik,
1136 const vector<const VVVdouble*>& tProb,
1139 size_t nbDistinctSites,
1147 for (
size_t n = 0; n < nbNodes; n++)
1152 for (
size_t i = 0; i < nbDistinctSites; i++)
1155 const VVdouble* iLik_n_i = &(*iLik_n)[i];
1158 for (
size_t c = 0; c < nbClasses; c++)
1161 const Vdouble* iLik_n_i_c = &(*iLik_n_i)[c];
1162 Vdouble* oLik_i_c = &(*oLik_i)[c];
1163 const VVdouble* pxy_n_c = &(*pxy_n)[c];
1164 for (
size_t x = 0; x < nbStates; x++)
1167 const Vdouble* pxy_n_c_x = &(*pxy_n_c)[x];
1168 double likelihood = 0;
1169 for (
size_t y = 0; y < nbStates; y++)
1171 likelihood += (*pxy_n_c_x)[y] * (*iLik_n_i_c)[y];
1174 (*oLik_i_c)[x] *= likelihood;
1184 const vector<const VVVdouble*>& iLik,
1185 const vector<const VVVdouble*>& tProb,
1190 size_t nbDistinctSites,
1198 for (
size_t n = 0; n < nbNodes; n++)
1203 for (
size_t i = 0; i < nbDistinctSites; i++)
1206 const VVdouble* iLik_n_i = &(*iLik_n)[i];
1209 for (
size_t c = 0; c < nbClasses; c++)
1212 const Vdouble* iLik_n_i_c = &(*iLik_n_i)[c];
1213 Vdouble* oLik_i_c = &(*oLik_i)[c];
1214 const VVdouble* pxy_n_c = &(*pxy_n)[c];
1215 for (
size_t x = 0; x < nbStates; x++)
1218 const Vdouble* pxy_n_c_x = &(*pxy_n_c)[x];
1219 double likelihood = 0;
1220 for (
size_t y = 0; y < nbStates; y++)
1224 likelihood += (*pxy_n_c_x)[y] * (*iLik_n_i_c)[y];
1228 (*oLik_i_c)[x] *= likelihood;
1235 for (
size_t i = 0; i < nbDistinctSites; i++)
1238 const VVdouble* iLikR_i = &(*iLikR)[i];
1241 for (
size_t c = 0; c < nbClasses; c++)
1244 const Vdouble* iLikR_i_c = &(*iLikR_i)[c];
1245 Vdouble* oLik_i_c = &(*oLik_i)[c];
1246 const VVdouble* pxyR_c = &(*tProbR)[c];
1247 for (
size_t x = 0; x < nbStates; x++)
1249 double likelihood = 0;
1250 for (
size_t y = 0; y < nbStates; y++)
1253 const Vdouble* pxyR_c_y = &(*pxyR_c)[y];
1254 likelihood += (*pxyR_c_y)[x] * (*iLikR_i_c)[y];
1257 (*oLik_i_c)[x] *= likelihood;
1267 cout <<
"Likelihoods at node " << node->
getId() <<
": " << endl;
1271 cout <<
"Array for sub-node " << subNode->
getId() << endl;
1277 cout <<
"Array for father node " << father->
getId() << endl;
1280 cout <<
" ***" << endl;
std::shared_ptr< DiscreteDistributionInterface > rateDistribution_
static void displayLikelihoodArray(const VVVdouble &likelihoodArray)
Print the likelihood array to terminal (debugging tool).
static void resetLikelihoodArray(VVVdouble &likelihoodArray)
Set all conditional likelihoods to 1.
Partial implementation for branch non-homogeneous models of the TreeLikelihood interface.
std::map< int, VVVdouble > d2pxy_
std::shared_ptr< SubstitutionModelSet > modelSet_
AbstractNonHomogeneousTreeLikelihood & operator=(const AbstractNonHomogeneousTreeLikelihood &lik)
Assignation operator.
virtual void computeAllTransitionProbabilities()
Fill the pxy_, dpxy_ and d2pxy_ arrays for all nodes.
std::map< int, VVVdouble > dpxy_
ParameterList getSubstitutionModelParameters() const override
Get the parameters associated to substitution model(s).
virtual void computeTransitionProbabilitiesForNode(const Node *node)
Fill the pxy_, dpxy_ and d2pxy_ arrays for one node.
std::map< int, const Node * > idToNode_
An index linking nodes to their id, for faster access than the getNode() method.
std::vector< Node * > nodes_
Pointer toward all nodes in the tree.
ParameterList brLenParameters_
virtual void applyParameters()
All parameters are stored in a parameter list. This function apply these parameters to the substituti...
ParameterList getRateDistributionParameters() const override
Get the parameters associated to the rate distribution.
std::map< int, VVVdouble > pxy_
std::vector< double > rootFreqs_
void setParametersValues(const ParameterList ¶meters) override
bool hasParameter(const std::string &name) const override
double getParameterValue(const std::string &name) const override
const AlignmentDataInterface & data() const
Get the dataset for which the likelihood must be evaluated.
const Tree & tree() const
Get the tree (topology and branch lengths).
std::unique_ptr< const AlignmentDataInterface > data_
std::shared_ptr< TreeTemplate< Node > > tree_
bool isInitialized() const
bool computeFirstOrderDerivatives_
bool computeSecondOrderDerivatives_
This class implements the likelihood computation for a tree using the double-recursive algorithm,...
virtual void computeSubtreeLikelihoodPostfix(const Node *node)
void resetLikelihoodArrays(const Node *node)
DRNonHomogeneousTreeLikelihood(const Tree &tree, std::shared_ptr< SubstitutionModelSet > modelSet, std::shared_ptr< DiscreteDistributionInterface > rDist, bool verbose=true, bool reparametrizeRoot=false)
Build a new DRNonHomogeneousTreeLikelihood object without data.
void setParameters(const ParameterList ¶meters)
Implements the Function interface.
double getLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const
Get the likelihood for a site knowing its rate class and its ancestral state.
void setData(const AlignmentDataInterface &sites)
Set the dataset for which the likelihood must be evaluated.
double getLogLikelihoodForASiteForARateClassForAState(size_t site, size_t rateClass, int state) const
Get the logarithm of the likelihood for a site knowing its rate class and its ancestral state.
virtual void computeTreeDLikelihoods()
std::unique_ptr< DRASDRTreeLikelihoodData > likelihoodData_
double getLogLikelihood() const
Get the logarithm of the likelihood for the whole dataset.
double getLikelihood() const
Get the likelihood for the whole dataset.
virtual void computeTreeDLikelihoodAtNode(const Node *node)
double getFirstOrderDerivative(const std::string &variable) const
virtual void displayLikelihood(const Node *node)
This method is mainly for debugging purpose.
DRNonHomogeneousTreeLikelihood & operator=(const DRNonHomogeneousTreeLikelihood &lik)
void computeTreeLikelihood()
double getLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the likelihood for a site knowing its rate class.
double getLikelihoodForASite(size_t site) const
Get the likelihood for a site.
double getLogLikelihoodForASiteForARateClass(size_t site, size_t rateClass) const
Get the logarithm of the likelihood for a site knowing its rate class.
void fireParameterChanged(const ParameterList ¶ms)
virtual void computeRootLikelihood()
virtual void computeLikelihoodAtNode_(const Node *node, VVVdouble &likelihoodArray) const
virtual void computeTreeD2Likelihoods()
virtual void computeTreeD2LikelihoodAtNode(const Node *node)
virtual void computeSubtreeLikelihoodPrefix(const Node *node)
double getSecondOrderDerivative(const std::string &variable) const
static void computeLikelihoodFromArrays(const std::vector< const VVVdouble * > &iLik, const std::vector< const VVVdouble * > &tProb, VVVdouble &oLik, size_t nbNodes, size_t nbDistinctSites, size_t nbClasses, size_t nbStates, bool reset=true)
Compute conditional likelihoods.
double getLogLikelihoodForASite(size_t site) const
Get the logarithm of the likelihood for a site.
double getValue() const
Function and NNISearchable interface.
void init_()
Method called by constructors.
The phylogenetic node class.
virtual int getId() const
Get the node's id.
virtual const Node * getSon(size_t pos) const
virtual const Node * getFather() const
Get the father of this node is there is one.
virtual bool isLeaf() const
virtual bool hasFather() const
Tell if this node has a father node.
virtual size_t getNumberOfSons() const
virtual ParameterList getCommonParametersWith(const ParameterList ¶ms) const
virtual std::vector< std::string > getParameterNames() const
Interface for phylogenetic tree objects.
std::string toString(T t)
Defines the basic types of data flow nodes.
double log(const ExtendedFloat &ef)
std::vector< double > Vdouble
ExtendedFloat pow(const ExtendedFloat &ef, double exp)
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble