14 throw Exception(
"BackwardLikelihoodTree::makeBackwardLikelihoodAtEdge: forwardTree_ is missing.");
16 auto edgeForward = forwardTree_->getEdge(edgeIndex);
17 auto fatherIndex = forwardTree_->getFatherOfEdge(edgeIndex);
18 auto fatherForward = forwardTree_->getNode(fatherIndex);
21 auto backNode = hasNode(fatherIndex)
22 ? getNode(fatherIndex)
23 : makeBackwardLikelihoodAtNode(fatherIndex);
25 auto fatherNode = forwardTree_->getProcessTree()->getNode(fatherIndex);
29 if (fatherNode->isSpeciation())
32 auto edgeIds = forwardTree_->getOutgoingEdges(fatherIndex);
35 for (
auto eId : edgeIds)
38 deps.push_back(forwardTree_->getEdge(eId));
40 deps.push_back(backNode);
42 backwardEdge = SpeciationBackward::create (context_, std::move (deps), likelihoodMatrixDim_);
44 else if (fatherNode->isMixture())
46 backwardEdge = backNode;
49 throw Exception(
"BackwardLikelihoodTree::makeBackwardLikelihoodAtEdge : event not recognized for node " +
TextTools::toString(fatherNode->getSpeciesIndex()));
52 if (!hasEdge(backwardEdge))
54 associateEdge(backwardEdge, forwardTree_->getEdgeGraphid(edgeForward));
55 setEdgeIndex(backwardEdge, edgeIndex);
65 throw Exception(
"BackwardLikelihoodTree::makeBackwardLikelihoodAtNode: forwardTree_ is missing.");
67 auto forwardNode = forwardTree_->getNode(nodeIndex);
69 if (nodeIndex == forwardTree_->getRootIndex())
70 return setRootFrequencies(rFreqs_);
73 const auto edgesIndexes = forwardTree_->getIncomingEdges(nodeIndex);
79 for (
const auto& edgeIndex:edgesIndexes)
81 auto backEdge = hasEdge(edgeIndex)
83 : makeBackwardLikelihoodAtEdge(edgeIndex);
85 auto iedge = forwardTree_->getEdge(edgeIndex);
87 const auto processEdge = forwardTree_->getProcessTree()->getEdge(edgeIndex);
89 const auto brprob = processEdge->getProba();
93 if (processEdge->getBrLen())
95 auto transitionMatrix = processEdge->getTransitionMatrix();
103 backLikeEdge = BackwardProportion::create(context_, {brprob, backEdge}, likelihoodMatrixDim_);
105 throw Exception(
"BackwardLikelihoodTree::makeBackwardLikelihoodAtNode : missing information on edge " +
TextTools::toString(processEdge->getSpeciesIndex()));
107 if (edgesIndexes.size() == 1)
109 backwardNode = backLikeEdge;
113 deps.push_back(backLikeEdge);
121 if (!hasNode(backwardNode))
123 associateNode(backwardNode, forwardTree_->getNodeGraphid(forwardNode));
124 setNodeIndex(backwardNode, nodeIndex);
AssociationGraphObserver< N, E >::EdgeIndex EdgeIndex
AssociationGraphObserver< N, E >::NodeIndex NodeIndex
BackwardLikelihoodAboveRef makeBackwardLikelihoodAtEdge(PhyloTree::EdgeIndex index)
ConditionalLikelihoodRef makeBackwardLikelihoodAtNode(PhyloTree::NodeIndex index)
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseAdd node with the given output dimensions.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new MatrixProduct node with the given output dimensions.
std::string toString(T t)
Defines the basic types of data flow nodes.
ValueRef< MatrixLik > ConditionalLikelihoodRef
std::vector< NodeRef > NodeRefVec
Alias for a dependency vector (of NodeRef).
ValueRef< MatrixLik > BackwardLikelihoodAboveRef