18 const string& sequenceName,
24 Eigen::MatrixXd initCondLik ((
int)
nbState_, (
int)nbSites);
26 for (
size_t site = 0; site < nbSites; ++site)
28 for (
auto state = 0; state <
nbState_; ++state)
30 initCondLik (Eigen::Index (state), Eigen::Index (site)) =
39 shared_ptr<ProcessEdge> processEdge,
42 const auto brlen = processEdge->getBrLen();
43 const auto model = processEdge->getModel();
44 const auto nMod = processEdge->getNMod();
45 const auto brprob = processEdge->getProba();
55 if (dynamic_pointer_cast<const TransitionModelInterface>(model->targetValue()))
59 processEdge->setTransitionMatrix(transitionMatrix);
73 forwardEdge = ForwardProportion::create(
78 forwardEdge = childConditionalLikelihood;
86 link(
getRoot(), childConditionalLikelihood, forwardEdge);
90 auto spIndex = processEdge->getSpeciesIndex();
101 std::cerr <<
"E " <<
getEdgeIndex(forwardEdge) <<
" : forwardEdge " << forwardEdge << endl;
110 const auto childBranches =
processTree_->getBranches (processNode);
112 auto spIndex = processNode->getSpeciesIndex();
116 if (childBranches.empty ())
133 std::vector<ForwardLikelihoodBelowRef> depE(childBranches.size());
136 for (
size_t i = 0; i < childBranches.size (); ++i)
142 if (processNode->isSpeciation())
143 forwardNode = SpeciationForward::create(
context_, std::move(deps),
145 else if (processNode->isMixture())
149 throw Exception(
"ForwardLikelihoodTree::makeConditionalLikelihoodAtNode : event not recognized for node " +
TextTools::toString(processNode->getSpeciesIndex()));
160 bool fathmixture(
false);
164 auto fatherNode =
processTree_->getFatherOfNode (processNode);
165 fathmixture = fatherNode->isMixture();
175 for (
size_t i = 0; i < depE.size (); ++i)
179 unlink(fs.first, fs.second);
180 link(forwardNode, fs.second, depE[i]);
186 std::cerr <<
"N " <<
getNodeIndex(forwardNode) <<
" : forwardNode " << forwardNode << endl;
187 for (
size_t i = 0; i < childBranches.size (); ++i)
189 std::cerr <<
" -> E " <<
processTree_->getEdgeIndex(childBranches[i]) << std::endl;
203 DAProb(forwardTree->getGraph()), context_(forwardTree->getContext())
207 associateNode(rootProb, forwardTree->getNodeGraphid(forwardTree->getRoot()));
210 auto allIndex = forwardTree->getAllNodesIndexes();
211 std::vector<const Node_DF*> vN;
213 for (
auto id: allIndex)
216 if (forwardTree->getOutgoingEdges(
id).size() == 0)
231 auto fatherIndex = forwardTree->getFatherOfEdge(edgeIndex);
232 auto edgeForward = forwardTree->getEdge(edgeIndex);
235 auto probaNode =
hasNode(fatherIndex)
239 const auto processEdge = forwardTree->getProcessTree()->getEdge(edgeIndex);
241 const auto brprob = processEdge->getProba();
257 associateEdge(probaEdge, forwardTree->getEdgeGraphid(edgeForward));
268 const auto edgesIndexes = forwardTree->getIncomingEdges(nodeIndex);
274 auto forwardNode = forwardTree->getNode(nodeIndex);
276 for (
const auto& edgeIndex:edgesIndexes)
278 auto backEdge =
hasEdge(edgeIndex)
282 if (edgesIndexes.size() == 1)
288 deps.push_back(backEdge);
297 associateNode(probaNode, forwardTree->getNodeGraphid(forwardNode));
AssociationGraphObserver< N, E >::EdgeIndex EdgeIndex
std::pair< Nref, Nref > getNodes(Eref edge) const
AssociationGraphObserver< N, E >::NodeIndex NodeIndex
virtual std::shared_ptr< N > getNode(NodeIndex nodeIndex) const=0
virtual void link(std::shared_ptr< N > nodeObjectA, std::shared_ptr< N > nodeObjectB, std::shared_ptr< E > edgeObject=00)=0
virtual NodeIndex setNodeIndex(const std::shared_ptr< N > nodeObject, NodeIndex index)=0
virtual void associateNode(std::shared_ptr< N > nodeObject, NodeGraphid node)=0
virtual std::shared_ptr< N > getRoot() const=0
virtual EdgeIndex getEdgeIndex(const std::shared_ptr< E > edgeObject) const=0
virtual bool hasNodeIndex(const std::shared_ptr< N > nodeObject) const=0
virtual void unlink(std::shared_ptr< N > nodeObjectA, std::shared_ptr< N > nodeObjectB)=0
virtual EdgeIndex setEdgeIndex(const std::shared_ptr< E > edgeObject, EdgeIndex index)=0
virtual NodeIndex getNodeIndex(const std::shared_ptr< N > nodeObject) const=0
virtual bool hasEdgeIndex(const std::shared_ptr< E > edgeObject) const=0
virtual bool hasNode(NodeIndex nodeIndex) const=0
virtual std::shared_ptr< E > getEdge(EdgeIndex edgeIndex) const=0
virtual bool hasEdge(EdgeIndex edgeIndex) const=0
virtual void associateEdge(std::shared_ptr< E > edgeObject, EdgeGraphid edge)=0
virtual void createNode(std::shared_ptr< N > newNodeObject)=0
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 CWiseApply node.
static std::shared_ptr< Self > create(Context &c, const Dimension< T > &dim)
Build a new ConstantOne node of the given dimension.
MatrixDimension likelihoodMatrixDim_
std::shared_ptr< ProcessTree > processTree_
ConditionalLikelihoodForwardRef makeInitialConditionalLikelihood(const std::string &sequenceName, const AlignmentDataInterface &sites)
Compute ConditionalLikelihood for leaf.
const StateMapInterface & statemap_
std::map< Speciesindex, DAGindexes > mapNodesIndexes_
ForwardLikelihoodBelowRef makeForwardLikelihoodAtEdge(std::shared_ptr< ProcessEdge > edge, const AlignmentDataInterface &sites)
Compute ConditionalLikelihood after reading edge on the forward process (ie at top of the edge).
std::map< Speciesindex, DAGindexes > mapEdgesIndexes_
ConditionalLikelihoodForwardRef makeForwardLikelihoodAtNode(std::shared_ptr< ProcessNode > node, const AlignmentDataInterface &sites)
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim, size_t id=0)
Build a new Convert 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.
ProbaRef makeProbaAtNode_(PhyloTree::EdgeIndex edgeIndex, std::shared_ptr< ForwardLikelihoodTree > tree)
ProbabilityDAG(std::shared_ptr< ForwardLikelihoodTree > tree)
ProbaRef makeProbaAtEdge_(PhyloTree::EdgeIndex edgeIndex, std::shared_ptr< ForwardLikelihoodTree > tree)
computation of the probabilities with the same approach as for BackwardLikelihoodTree.
static ValueRef< T > create(Context &c, T &&value, const std::string &name)
virtual int getAlphabetStateAsInt(size_t index) const =0
virtual size_t getNumberOfSites() const=0
virtual size_t getSequencePosition(const std::string &sequenceKey) const =0
static std::shared_ptr< Self > create(Context &c, NodeRefVec &&deps, const Dimension< T > &dim)
std::string toString(T t)
T zero(const Dimension< T > &)
Defines the basic types of data flow nodes.
Dimension< TransitionFunction > transitionFunctionDimension(Eigen::Index nbState)
std::vector< uint > DAGindexes
Helper: create a map with mutable dataflow nodes for each branch of the tree. The map is indexed by b...
ValueRef< MatrixLik > ConditionalLikelihoodForwardRef
std::vector< NodeRef > NodeRefVec
Alias for a dependency vector (of NodeRef).
std::shared_ptr< Value< double > > ProbaRef
ValueRef< MatrixLik > ForwardLikelihoodBelowRef
MatrixDimension transitionMatrixDimension(std::size_t nbState)
Specialisation of Dimension<T> for floating point types.