bpp-phyl3 3.0.0
BackwardLikelihoodTree.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_LIKELIHOOD_DATAFLOW_BACKWARDLIKELIHOODTREE_H
6#define BPP_PHYL_LIKELIHOOD_DATAFLOW_BACKWARDLIKELIHOODTREE_H
7
8
12
13namespace bpp
14{
15// using RowLik = Eigen::Matrix<double, 1, Eigen::Dynamic>;
16// using MatrixLik = Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic>;
17
18
29
42
57
68
69// Upper Likelihood in nodes
72
73// Upper Likelihood at top of edges
76
77// using FullLikelihood = Value<Patterned<MatrixLik>>;
78
80/* All the computations are set in a DataFlow context */
81
82class BackwardLikelihoodTree : public AssociationDAGlobalGraphObserver<ConditionalLikelihood, BackwardLikelihoodAbove>
83{
85
90private:
92 Eigen::Index nbState_;
93 Eigen::Index nbSite_;
94 std::shared_ptr<ForwardLikelihoodTree> forwardTree_;
95 std::shared_ptr<ProcessTree> processTree_;
99
100public:
102 std::shared_ptr<ForwardLikelihoodTree> forwardTree,
103 std::shared_ptr<ProcessTree> tree,
105 const StateMapInterface& statemap,
106 Eigen::Index nbSite) :
107 DAClass(forwardTree->getGraph()),
108 context_(c), nbState_(Eigen::Index(statemap.getNumberOfModelStates())), nbSite_(nbSite), forwardTree_(forwardTree), processTree_(tree), rFreqs_(rFreqs), likelihoodMatrixDim_(conditionalLikelihoodDimension (nbState_, nbSite_)), statemap_(statemap)
109 {}
110
112 {
115
116 associateNode(r2, forwardTree_->getNodeGraphid(forwardTree_->getRoot()));
117 setNodeIndex(r2, forwardTree_->getRootIndex());
118 return r2;
119 }
120
121private:
122 /*
123 * @brief Compute joined likelihood BEFORE reading edge on the
124 * backward process (ie at top of the edge).
125 *
126 */
127
129
130 /*
131 * @brief Compute joined likelihood at node on the backward
132 * process (ie with the bottom of the edges getting to the node
133 * from upward).
134 *
135 */
136
138
139 /*
140 * @brief the LikehoodArrays
141 *
142 * Beware: nodeIds are in the DAG, not the ids of the PhyloTree.
143 *
144 * Set in private to avoid bad usage, access through
145 * LikelihoodCalculationSingleProcess.
146 */
148 {
149 if (!hasNode(nodeId))
151
152 return getNode(nodeId);
153 }
154
156};
157} // end of namespace bpp.
158#endif // BPP_PHYL_LIKELIHOOD_DATAFLOW_BACKWARDLIKELIHOODTREE_H
const std::shared_ptr< DAGraphImpl > getGraph() const
AssociationGraphObserver< N, E >::EdgeIndex EdgeIndex
AssociationGraphObserver< N, E >::NodeIndex NodeIndex
virtual std::shared_ptr< N > getNode(NodeIndex nodeIndex) const=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 bool hasNode(NodeIndex nodeIndex) const=0
BackwardLikelihoodTree(Context &c, std::shared_ptr< ForwardLikelihoodTree > forwardTree, std::shared_ptr< ProcessTree > tree, ValueRef< Eigen::RowVectorXd > rFreqs, const StateMapInterface &statemap, Eigen::Index nbSite)
const StateMapInterface & statemap_
std::shared_ptr< ForwardLikelihoodTree > forwardTree_
BackwardLikelihoodAboveRef makeBackwardLikelihoodAtEdge(PhyloTree::EdgeIndex index)
ValueRef< Eigen::RowVectorXd > rFreqs_
ConditionalLikelihoodRef setRootFrequencies(const ValueRef< Eigen::RowVectorXd > rootFreqs)
ConditionalLikelihoodRef getBackwardLikelihoodArray(PhyloTree::NodeIndex nodeId)
ConditionalLikelihoodRef makeBackwardLikelihoodAtNode(PhyloTree::NodeIndex index)
std::shared_ptr< ProcessTree > processTree_
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new CWiseFill node.
Definition: DataFlowCWise.h:95
Context for dataflow node construction.
Definition: DataFlow.h:527
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new Convert node with the given output dimensions.
Map the states of a given alphabet which have a model state.
Definition: StateMap.h:25
Defines the basic types of data flow nodes.
std::shared_ptr< Value< T > > ValueRef
Shared pointer alias for Value<T>.
Definition: DataFlow.h:84
ValueRef< MatrixLik > ConditionalLikelihoodRef
MatrixDimension conditionalLikelihoodDimension(Eigen::Index nbState, Eigen::Index nbSite)
ValueRef< MatrixLik > BackwardLikelihoodAboveRef
Basic matrix dimension type.