10 void TreeLikelihoodTools::getAncestralFrequencies(
13 std::map<
int, std::vector<double>>& frequencies,
18 getAncestralFrequencies_(tl, tl.
getSiteIndex(site), currentId, currentFreqs, frequencies, alsoForLeaves);
21 void TreeLikelihoodTools::getAncestralFrequencies(
23 std::map<
int, std::vector<double>>& frequencies,
29 map<int, vector<double>> siteFrequencies;
30 for (
size_t i = 0; i < n; ++i)
35 for (
size_t i = 0; i < n; ++i)
38 getAncestralFrequencies(tl, i, siteFrequencies, alsoForLeaves);
42 frequencies = siteFrequencies;
44 for (map<
int, vector<double>>::iterator it = frequencies.begin(); it != frequencies.end(); it++)
46 VectorTools::fill(it->second, 0.);
49 map<int, vector<double>>::iterator it = frequencies.begin();
50 map<int, vector<double>>::iterator itSite = siteFrequencies.begin();
51 for (
size_t j = 0; j < frequencies.size(); ++j)
53 for (
size_t k = 0; k < ns; ++k)
55 it->second[k] += itSite->second[k] * w / sumw;
63 void TreeLikelihoodTools::getAncestralFrequencies_(
67 const std::vector<double>& ancestralFrequencies,
68 std::map<
int, std::vector<double>>& frequencies,
71 if (!tl.
tree().
isLeaf(parentId) || alsoForLeaves)
72 frequencies[parentId] = ancestralFrequencies;
74 for (
size_t i = 0; i < sonsId.size(); i++)
83 x += pijt[k][j] * ancestralFrequencies[k];
85 sonFrequencies[j] = x;
87 getAncestralFrequencies_(tl, siteIndex, sonsId[i], sonFrequencies, frequencies, alsoForLeaves);
virtual size_t getNumberOfDistinctSites() const =0
virtual unsigned int getWeight(size_t pos) const =0
The TreeLikelihood interface.
virtual size_t getNumberOfStates() const =0
virtual TreeLikelihoodData & likelihoodData()=0
virtual const std::vector< double > & getRootFrequencies(size_t siteIndex) const =0
Get the values of the frequencies for each state in the alphabet at the root node.
virtual size_t getSiteIndex(size_t site) const =0
Get the index (used for inner computations) of a given site (original alignment column).
virtual const Tree & tree() const =0
Get the tree (topology and branch lengths).
virtual VVdouble getTransitionProbabilities(int nodeId, size_t siteIndex) const =0
Retrieves all Pij(t) for a particular branch, defined by the upper node and site.
virtual std::vector< int > getSonsId(int parentId) const =0
virtual bool isLeaf(int nodeId) const =0
virtual int getRootId() const =0
Defines the basic types of data flow nodes.
std::vector< Vdouble > VVdouble