43 #include <Bpp/App/ApplicationTools.h> 55 return positiveLengths_ ?
56 std::max(lambda_ * (matrix_(pair[0], pos) - branchLengths[0]) + (1 - lambda_) * (matrix_(pair[1], pos) - branchLengths[1]), 0.)
57 : lambda_ * (matrix_(pair[0], pos) - branchLengths[0]) + (1 - lambda_) * (matrix_(pair[1], pos) - branchLengths[1]);
63 for (
size_t i = 0; i < matrix_.size(); i++)
65 currentNodes_[i] = getLeafNode(static_cast<int>(i), matrix_.getName(i));
67 int idNextNode =
static_cast<int>(matrix_.size());
68 vector<double> newDist(matrix_.size());
69 vector<double> newVar(matrix_.size());
72 while (currentNodes_.size() > (rootTree_ ? 2 : 3))
75 ApplicationTools::displayGauge(matrix_.size() - currentNodes_.size(), matrix_.size() - (rootTree_ ? 2 : 3) - 1);
76 vector<size_t> bestPair = getBestPair();
77 vector<double> distances = computeBranchLengthsForPair(bestPair);
78 Node* best1 = currentNodes_[bestPair[0]];
79 Node* best2 = currentNodes_[bestPair[1]];
83 Node* parent = getParentNode(idNextNode++, best1, best2);
86 if (variance_(bestPair[0], bestPair[1]) == 0)
90 for (map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
93 if (
id != bestPair[0] &&
id != bestPair[1])
94 lambda_ += (variance_(bestPair[1],
id) - variance_(bestPair[0],
id));
96 double div = 2 *
static_cast<double>(currentNodes_.size() - 2) * variance_(bestPair[0], bestPair[1]);
105 for (map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
107 size_t id = i->first;
108 if (
id != bestPair[0] &&
id != bestPair[1])
110 newDist[id] = computeDistancesFromPair(bestPair, distances,
id);
111 newVar[id] = lambda_ * variance_(bestPair[0],
id) + (1 - lambda_) * variance_(bestPair[1],
id) - lambda_ * (1 - lambda_) * variance_(bestPair[0], bestPair[1]);
119 currentNodes_[bestPair[0]] = parent;
120 currentNodes_.erase(bestPair[1]);
121 for (map<size_t, Node*>::iterator i = currentNodes_.begin(); i != currentNodes_.end(); i++)
123 size_t id = i->first;
124 matrix_( bestPair[0],
id) = matrix_(
id, bestPair[0]) = newDist[id];
125 variance_(bestPair[0],
id) = variance_(
id, bestPair[0]) = newVar[id];
128 finalStep(idNextNode);
void computeTree()
Compute the tree corresponding to the distance matrix.
The phylogenetic node class.
virtual void setDistanceToFather(double distance)
Set or update the distance toward the father node.
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...