53 for (std::map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
57 for (map<size_t, Node*>::iterator j = currentNodes_.begin(); j != currentNodes_.end(); j++)
60 sumDist_[id] += matrix_(
id, jd);
64 vector<size_t> bestPair(2);
65 double critMax = std::log(0.);
66 for (map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
69 map<size_t, Node*>::iterator j = i;
71 for ( ; j != currentNodes_.end(); j++)
74 double crit = sumDist_[id] + sumDist_[jd] -
static_cast<double>(currentNodes_.size() - 2) * matrix_(
id, jd);
85 if (critMax == std::log(0.))
87 throw Exception(
"Unexpected error: no maximum criterium found.");
94 double ratio = (sumDist_[pair[0]] - sumDist_[pair[1]]) / static_cast<double>(currentNodes_.size() - 2);
98 d[0] = std::max(.5 * (matrix_(pair[0], pair[1]) + ratio), 0.);
99 d[1] = std::max(.5 * (matrix_(pair[0], pair[1]) - ratio), 0.);
103 d[0] = .5 * (matrix_(pair[0], pair[1]) + ratio);
104 d[1] = .5 * (matrix_(pair[0], pair[1]) - ratio);
113 std::max(.5 * (matrix_(pair[0], pos) - branchLengths[0] + matrix_(pair[1], pos) - branchLengths[1]), 0.)
114 : .5 * (matrix_(pair[0], pos) - branchLengths[0] + matrix_(pair[1], pos) - branchLengths[1]);
120 map<size_t, Node* >::iterator it = currentNodes_.begin();
121 size_t i1 = it->first;
122 Node* n1 = it->second;
124 size_t i2 = it->first;
125 Node* n2 = it->second;
126 if (currentNodes_.size() == 2)
129 double d = matrix_(i1, i2) / 2;
139 size_t i3 = it->first;
140 Node* n3 = it->second;
141 double d1 = positiveLengths_ ?
142 std::max(matrix_(i1, i2) + matrix_(i1, i3) - matrix_(i2, i3), 0.)
143 : matrix_(i1, i2) + matrix_(i1, i3) - matrix_(i2, i3);
144 double d2 = positiveLengths_ ?
145 std::max(matrix_(i2, i1) + matrix_(i2, i3) - matrix_(i1, i3), 0.)
146 : matrix_(i2, i1) + matrix_(i2, i3) - matrix_(i1, i3);
147 double d3 = positiveLengths_ ?
148 std::max(matrix_(i3, i1) + matrix_(i3, i2) - matrix_(i1, i2), 0.)
149 : matrix_(i3, i1) + matrix_(i3, i2) - matrix_(i1, i2);
virtual void addSon(size_t pos, Node *node)
void finalStep(int idRoot)
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of t...
The phylogenetic tree class.
std::vector< double > computeBranchLengthsForPair(const std::vector< size_t > &pair)
Compute the branch lengths for two nodes to agglomerate.
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.
The phylogenetic node class.
virtual void setDistanceToFather(double distance)
Set or update the distance toward the father node.