5 #include "../Tree/Tree.h"
17 for (std::map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
21 for (map<size_t, Node*>::iterator j = currentNodes_.begin(); j != currentNodes_.end(); j++)
24 sumDist_[id] += matrix_(
id, jd);
28 vector<size_t> bestPair(2);
30 for (map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
33 map<size_t, Node*>::iterator j = i;
35 for ( ; j != currentNodes_.end(); j++)
38 double crit = sumDist_[id] + sumDist_[jd] -
static_cast<double>(currentNodes_.size() - 2) * matrix_(
id, jd);
51 throw Exception(
"Unexpected error: no maximum criterium found.");
58 double ratio = (sumDist_[pair[0]] - sumDist_[pair[1]]) /
static_cast<double>(currentNodes_.size() - 2);
62 d[0] = std::max(.5 * (matrix_(pair[0], pair[1]) + ratio), 0.);
63 d[1] = std::max(.5 * (matrix_(pair[0], pair[1]) - ratio), 0.);
67 d[0] = .5 * (matrix_(pair[0], pair[1]) + ratio);
68 d[1] = .5 * (matrix_(pair[0], pair[1]) - ratio);
77 std::max(.5 * (matrix_(pair[0], pos) - branchLengths[0] + matrix_(pair[1], pos) - branchLengths[1]), 0.)
78 : .5 * (matrix_(pair[0], pos) - branchLengths[0] + matrix_(pair[1], pos) - branchLengths[1]);
84 map<size_t, Node* >::iterator it = currentNodes_.begin();
85 size_t i1 = it->first;
86 Node* n1 = it->second;
88 size_t i2 = it->first;
89 Node* n2 = it->second;
90 if (currentNodes_.size() == 2)
93 double d = matrix_(i1, i2) / 2;
103 size_t i3 = it->first;
104 Node* n3 = it->second;
105 double d1 = positiveLengths_ ?
106 std::max(matrix_(i1, i2) + matrix_(i1, i3) - matrix_(i2, i3), 0.)
107 : matrix_(i1, i2) + matrix_(i1, i3) - matrix_(i2, i3);
108 double d2 = positiveLengths_ ?
109 std::max(matrix_(i2, i1) + matrix_(i2, i3) - matrix_(i1, i3), 0.)
110 : matrix_(i2, i1) + matrix_(i2, i3) - matrix_(i1, i3);
111 double d3 = positiveLengths_ ?
112 std::max(matrix_(i3, i1) + matrix_(i3, i2) - matrix_(i1, i2), 0.)
113 : matrix_(i3, i1) + matrix_(i3, i2) - matrix_(i1, i2);
double computeDistancesFromPair(const std::vector< size_t > &pair, const std::vector< double > &branchLengths, size_t pos)
Actualizes the distance matrix according to a given pair and the corresponding branch lengths.
std::vector< size_t > getBestPair()
Get the best pair of nodes to agglomerate.
void finalStep(int idRoot)
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of t...
std::vector< double > computeBranchLengthsForPair(const std::vector< size_t > &pair)
Compute the branch lengths for two nodes to agglomerate.
The phylogenetic node class.
virtual void setDistanceToFather(double distance)
Set or update the distance toward the father node.
virtual void addSon(size_t pos, Node *node)
The phylogenetic tree class.
Defines the basic types of data flow nodes.