7 #include <unordered_map>
16 using namespace numeric;
17 using namespace Eigen;
19 LikelihoodCalculationOnABranch::LikelihoodCalculationOnABranch(
24 numberOfSites_(likcalsp.getNumberOfSites()),
26 model_(likcalsp.getNumberOfClasses() ? likcalsp.getTreeNode(0)->getEdge(edgeId)->getModel() : 0),
27 rootPatternLinks_(likcalsp.getRootPatternLinks()),
28 rootWeights_(likcalsp.getRootWeights()),
29 catProb_(likcalsp.catProb_), vRateCatEdges_()
31 auto nbCl = likcalsp.getNumberOfClasses();
33 likcalsp.makeLikelihoodsTree();
34 for (
size_t ncl = 0; ncl < nbCl; ncl++)
36 auto tr = likcalsp.getTreeNode(ncl);
38 const auto& dagId = likcalsp.getEdgesIds(edgeId, ncl);
39 auto catEdge = make_shared<RateCategoryEdge>();
40 for (
const auto& did:dagId)
42 auto ft = likcalsp.getForwardLikelihoodTree(ncl);
43 catEdge->vBotLik_.push_back(ft->getNode(ft->getSon(did)));
44 catEdge->vTopLik_.push_back(likcalsp.getBackwardLikelihoodTree(ncl)->getEdge(did));
47 catEdge->brlen_ = likcalsp.getTreeNode(ncl)->getEdge(dagId[0])->getBrLen();
48 vRateCatEdges_.push_back(*catEdge);
50 shareParameters_(likcalsp.getParameters());
55 numberOfSites_(lik.numberOfSites_),
56 likelihoodMatrixDim_(lik.likelihoodMatrixDim_),
58 rootPatternLinks_(lik.rootPatternLinks_),
59 rootWeights_(lik.rootWeights_),
60 catProb_(lik.catProb_),
61 vRateCatEdges_(lik.vRateCatEdges_)
77 for (
size_t nCat = 0; nCat < nbCat; nCat++)
92 throw Exception(
"LikelihoodCalculationOnABranch::makeLikelihoods_: Missing model");
95 auto nbState = Eigen::Index(
stateMap().getNumberOfModelStates());
97 std::shared_ptr<ConditionalLikelihood> cond(0);
107 std::vector<std::shared_ptr<Node_DF>> vCond;
109 std::vector<NodeRef> vLikRate;
113 auto transitionMatrix = ConfiguredParametrizable::createMatrix<ConfiguredModel, TransitionMatrixFromModel, Eigen::MatrixXd>(
getContext_(), {model, rateCat.brlen_,
zero},
transitionMatrixDimension(
static_cast<size_t>(nbState)));
115 for (
size_t i = 0; i < rateCat.vBotLik_.size(); i++)
120 cond = BuildConditionalLikelihood::create (
123 if (rateCat.vBotLik_.size() > 1)
124 vCond.push_back(cond);
134 if (vCond.size() > 1)
140 vLikRate.push_back(rateCat.siteLik_);
146 vLikRate.push_back(catProb);
void cleanAllLikelihoods()
SiteLikelihoodsRef patternedSiteLikelihoods_
void setSiteLikelihoods(SiteLikelihoodsRef ll, bool shrunk=false)
static std::shared_ptr< Self > create(Context &c, const Dimension< T > &dim)
Build a new ConstantOne node of the given dimension.
Context for dataflow node construction.
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new Convert node with the given output dimensions.
LikelihoodCalculationOnABranch(Context &context, LikelihoodCalculationSingleProcess &likcalsp, uint edgeId)
ValueRef< RowLik > expandVector(ValueRef< RowLik > vector)
const StateMapInterface & stateMap() const
size_t getNumberOfDistinctSites() const
void cleanAllLikelihoods()
std::shared_ptr< ConfiguredModel > model_
AllRatesSiteLikelihoods getSiteLikelihoodsForAllClasses(bool shrunk=false)
Output array (Classes X Sites) of likelihoods for all sites & classes.
std::vector< RateCategoryEdge > vRateCatEdges_
std::shared_ptr< SiteWeights > rootWeights_
The frequency of each site.
MatrixDimension likelihoodMatrixDim_
std::shared_ptr< ConfiguredModel > getModel()
RowLik getSiteLikelihoodsForAClass(size_t nCat, bool shrunk=false)
Get site likelihoods for a rate category.
ValueRef< PatternType > rootPatternLinks_
ValueRef< Eigen::RowVectorXd > catProb_
size_t getNumberOfDistinctSites() const
const StateMapInterface & stateMap() const
void setLikelihoodNode(ValueRef< DataLik > ll)
static ValueRef< R > create(Context &c, NodeRefVec &&deps, const Dimension< R > &dim)
Build a new MatrixProduct node with the given output dimensions.
virtual size_t getNumberOfModelStates() const =0
static ValueRef< DataLik > create(Context &c, NodeRefVec &&deps, const Dimension< F > &mDim)
Build a new SumOfLogarithms node with the given input matrix dimensions.
T one(const Dimension< T > &)
T zero(const Dimension< T > &)
Defines the basic types of data flow nodes.
std::shared_ptr< Value< T > > ValueRef
Shared pointer alias for Value<T>.
ValueRef< RowLik > SiteLikelihoodsRef
MatrixDimension transitionMatrixDimension(std::size_t nbState)