12vector<size_t> LegacyMarginalAncestralStateReconstruction::getAncestralStatesForNode(
int nodeId,
VVdouble& probs,
bool sample)
const
34 likelihood_->computeLikelihoodAtNode(nodeId, larray);
42 Vdouble* larray_i_c = &(*larray_i)[c];
45 (*probs_i)[x] += (*larray_i_c)[x] *
r_[c] /
l_[i];
54 cumProb += (*probs_i)[j];
71 map<int, vector<size_t>> ancestors;
81 const vector<size_t>& rootPatternLinks =
likelihood_->likelihoodData().getRootArrayPositions();
83 vector<size_t> states;
90 for (
size_t i = 0; i <
nbSites_; i++)
92 allStates[i] = model->getAlphabetStateAsInt(states[rootPatternLinks[i]]);
93 (*probs)[i] = patternedProbs[rootPatternLinks[i]];
99 for (
size_t i = 0; i <
nbSites_; i++)
101 allStates[i] = model->getAlphabetStateAsInt(states[rootPatternLinks[i]]);
104 std::shared_ptr<const Alphabet> alpha =
alphabet_;
105 return make_unique<Sequence>(name, allStates, alpha);
110 map<
int, vector<size_t>>& ancestors,
116 vector<size_t>* v = &ancestors[node->
getId()];
117 v->resize(seq.
size());
122 for (
size_t i = 0; i < seq.
size(); i++)
124 (*v)[i] = model->getModelStates(seq[i])[0];
139 unique_ptr<SiteContainerInterface> asc = make_unique<AlignedSequenceContainer>(
alphabet_);
140 vector<int> ids =
tree_.getInnerNodesId();
141 for (
size_t i = 0; i < ids.size(); i++)
144 asc->addSequence(seq->getName(), seq);
virtual size_t size() const=0
std::shared_ptr< const DRTreeLikelihoodInterface > likelihood_
std::shared_ptr< const Alphabet > alphabet_
std::map< int, std::vector< size_t > > getAllAncestralStates() const override
Get all ancestral states for all nodes.
std::unique_ptr< SiteContainerInterface > getAncestralSequences() const override
Get all the ancestral sequences for all nodes.
std::unique_ptr< Sequence > getAncestralSequenceForNode(int nodeId, VVdouble *probs, bool sample) const
Get the ancestral sequence for a given node.
std::vector< size_t > getAncestralStatesForNode(int nodeId, VVdouble &probs, bool sample) const
Get ancestral states for a given node as a vector of int.
void recursiveMarginalAncestralStates(const Node *node, std::map< int, std::vector< size_t > > &ancestors, AlignedSequenceContainer &data) const
TreeTemplate< Node > tree_
The phylogenetic node class.
virtual std::string getName() const
Get the name associated to this node, if there is one, otherwise throw a NodeException.
virtual int getId() const
Get the node's id.
virtual const Node * getSon(size_t pos) const
virtual bool isLeaf() const
virtual size_t getNumberOfSons() const
const SequenceType & sequence(const std::string &sequenceKey) const override
std::string toString(T t)
Defines the basic types of data flow nodes.
std::vector< double > Vdouble
std::vector< VVdouble > VVVdouble
std::vector< Vdouble > VVdouble