13vector<size_t> MarginalAncestralReconstruction::getAncestralStatesForNode(uint nodeId,
VVdouble& probs,
bool sample)
const
17 auto vv =
likelihood_->getLikelihoodsAtNode(nodeId)->targetValue();
21 for (uint i = 0; i < static_cast<uint>(
nbSites_); ++i)
23 copyEigenToBpp(vv.col(i) / vv.col(i).sum(), probs[
static_cast<size_t>(i)]);
28 for (
size_t i = 0; i <
nbSites_; ++i)
30 const auto& coli = probs[i];
46 for (
size_t i = 0; i <
nbSites_; ++i)
48 vv.col(Eigen::Index(i)).maxCoeff(&pos);
57 map<uint, vector<size_t>> ancestors;
76 for (
size_t i = 0; i <
nbSites_; ++i)
78 allStates[i] = stateMap.getAlphabetStateAsInt(states[i]);
84 for (
size_t i = 0; i <
nbSites_; ++i)
86 allStates[i] = stateMap.getAlphabetStateAsInt(states[i]);
90 return make_unique<Sequence>(name, allStates,
alphabet_);
94 const std::shared_ptr<PhyloNode> node,
95 map<uint, vector<size_t>>& ancestors,
98 if (
tree_->isLeaf(node))
103 const Sequence& seq = sc.sequence(node->getName());
104 vector<size_t>* v = &ancestors[
tree_->getNodeIndex(node)];
105 v->resize(seq.
size());
110 for (
size_t i = 0; i < seq.
size(); ++i)
112 (*v)[i] = stateMap.getModelStates(seq[i])[0];
123 vector<shared_ptr<PhyloNode>> vsons =
tree_->getSons(node);
125 for (
size_t i = 0; i < vsons.size(); i++)
134 auto asc = make_unique<AlignedSequenceContainer>(
alphabet_);
135 vector<shared_ptr<PhyloNode>> inNodes =
tree_->getAllInnerNodes();
136 for (
size_t i = 0; i < inNodes.size(); ++i)
139 asc->addSequence(seq->getName(), seq);
virtual size_t size() const=0
void recursiveMarginalAncestralStates(const std::shared_ptr< PhyloNode > node, std::map< uint, std::vector< size_t > > &ancestors, AlignmentDataInterface &data) const
std::shared_ptr< const Alphabet > alphabet_
std::shared_ptr< const ParametrizablePhyloTree > tree_
std::unique_ptr< Sequence > getAncestralSequenceForNode(uint nodeId, VVdouble *probs, bool sample) const
Get an ancestral sequence for a given node.
std::shared_ptr< LikelihoodCalculationSingleProcess > likelihood_
std::map< uint, std::vector< size_t > > getAllAncestralStates() const override
Get all ancestral states for all nodes.
std::unique_ptr< AlignedSequenceContainer > getAncestralSequences() const override
Get all the ancestral sequences for all nodes.
std::vector< size_t > getAncestralStatesForNode(uint nodeId, VVdouble &probs, bool sample) const
Get ancestral states for a given node as a vector of int.
std::string toString(T t)
Defines the basic types of data flow nodes.
template void copyEigenToBpp(const ExtendedFloatMatrixXd &eigenMatrix, std::vector< std::vector< double > > &bppMatrix)
std::vector< Vdouble > VVdouble