9#include "../Likelihood/DataFlow/ForwardLikelihoodTree.h"
17using namespace numeric;
21void GivenDataSubstitutionProcessSiteSimulator::init()
32 const auto& dRate =
process_->getRateDistribution();
34 std::vector<DataLik> qR;
38 qR.push_back(
calcul_->getSiteLikelihoodsForAClass(i)(
pos_));
51 const auto dRoot =
process_->getRootFrequencies();
71 std::vector<DataLik> postTrans(
nbStates_);
73 for (
auto& edge : edges)
75 const auto model = edge->getModel();
84 const auto transmodel = dynamic_pointer_cast<const TransitionModelInterface>(model);
93 double brlen = dRate->getCategory(c) *
phyloTree_->getEdge(edge->getSpeciesIndex())->getLength();
95 VVdouble* cumpxy_node_c_ = &(*cumpxy_node_)[c];
104 const auto& vSub(edge->subModelNumbers());
106 if (vSub.size() == 0)
107 P = &transmodel->getPij_t(brlen);
111 throw Exception(
"SubstitutionProcessSiteSimulator::init : only 1 submodel can be used.");
113 const auto mmodel = dynamic_pointer_cast<const MixedTransitionModelInterface>(transmodel);
115 const auto model2 = mmodel->getNModel(vSub[0]);
117 P = &model2->getPij_t(brlen);
125 const auto& siteForwLik =
calcul_->getForwardLikelihoodsAtNodeForClass(
calcul_->getForwardLikelihoodTree(c)->getSon(outid), c)->targetValue().col(
pos_);
127 for (
size_t x = 0; x < size_t(
nbStates_); x++)
129 for (
size_t y = 0; y < size_t(
nbStates_); y++)
131 postTrans[y] = std::max((*P)(x, y),
NumConstants::PICO()) * siteForwLik(Eigen::Index(y));
136 for (
size_t i = 0; i < postTrans.size(); i++)
138 pT2[i] =
convert(postTrans[i]);
148 Vdouble* cumpxy_node_c_x_ = &(*cumpxy_node_c_)[x];
150 (*cumpxy_node_c_x_)[0] = (*P)(x, 0);
153 (*cumpxy_node_c_x_)[y] = (*cumpxy_node_c_x_)[y - 1] + (*P)(x, y);
163 for (
auto node:nodes)
165 if (node->isMixture())
168 std::vector<std::vector<DataLik>> vprob;
171 for (
auto edge : outEdges)
176 auto model = dynamic_pointer_cast<const MixedTransitionModelInterface>(edge->getModel());
181 const auto& vNb(edge->subModelNumbers());
186 x += model->getNProbability(nb);
194 auto forwLik =
calcul_->getForwardLikelihoodTree(c)->getEdge(outid)->targetValue().col(
pos_).sum();
195 vprob[c].push_back(x * forwLik);
202 vprob[c].push_back(x);
216 for (
size_t i = 0; i < vprob.size(); i++)
virtual std::vector< std::shared_ptr< E > > getAllEdges() const=0
virtual std::shared_ptr< N > getRoot() const=0
virtual EdgeIndex getEdgeIndex(const std::shared_ptr< E > edgeObject) const=0
virtual std::vector< std::shared_ptr< N > > getAllNodes() const=0
virtual NodeIndex getNodeIndex(const std::shared_ptr< N > nodeObject) const=0
virtual std::vector< std::shared_ptr< E > > getOutgoingEdges(const std::shared_ptr< N > node) const=0
std::shared_ptr< N > getSon(const std::shared_ptr< E > edge) const
const ExtendedFloat & sum() const
std::shared_ptr< LikelihoodCalculationSingleProcess > calcul_
std::vector< uint > vPriorBranch_
Eigen::Index pos_
Position of the copied site, in SHRUNKED data.
std::shared_ptr< const ParametrizablePhyloTree > phyloTree_
std::shared_ptr< const SubstitutionProcessInterface > process_
SPTree tree_
To store states & transition probabilities of the simulator.
bool outputInternalSites_
void outputInternalSites(bool yn) override
Sets whether we will output the internal sequences or not.
Vdouble qRates_
cumsum probas of the substitution rates
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
template void copyEigenToBpp(const ExtendedFloatMatrixXd &eigenMatrix, std::vector< std::vector< double > > &bppMatrix)
std::vector< VVdouble > VVVdouble
double convert(const bpp::ExtendedFloat &ef)
std::vector< Vdouble > VVdouble