bpp-phyl3 3.0.0
NeighborJoining.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: The Bio++ Development Group
2//
3// SPDX-License-Identifier: CECILL-2.1
4
5#ifndef BPP_PHYL_DISTANCE_NEIGHBORJOINING_H
6#define BPP_PHYL_DISTANCE_NEIGHBORJOINING_H
7
8
10
11namespace bpp
12{
21{
22protected:
23 std::vector<double> sumDist_;
25
26public:
34 NeighborJoining(bool rooted = false, bool positiveLengths = false, bool verbose = true) :
36 sumDist_(),
37 positiveLengths_(false)
38 {}
39
48 NeighborJoining(const DistanceMatrix& matrix, bool rooted = false, bool positiveLengths = false, bool verbose = true) :
49 AbstractAgglomerativeDistanceMethod(matrix, verbose, rooted),
50 sumDist_(),
51 positiveLengths_(positiveLengths)
52 {
53 sumDist_.resize(matrix.size());
55 }
56
57 virtual ~NeighborJoining() {}
58
59 NeighborJoining* clone() const { return new NeighborJoining(*this); }
60
61public:
62 std::string getName() const { return "NJ"; }
63
64 virtual void setDistanceMatrix(const DistanceMatrix& matrix)
65 {
67 sumDist_.resize(matrix.size());
68 }
69
70 virtual void outputPositiveLengths(bool yn) { positiveLengths_ = yn; }
71
72protected:
73 std::vector<size_t> getBestPair();
74 std::vector<double> computeBranchLengthsForPair(const std::vector<size_t>& pair);
75 double computeDistancesFromPair(const std::vector<size_t>& pair, const std::vector<double>& branchLengths, size_t pos);
76 void finalStep(int idRoot);
77};
78} // end of namespace bpp.
79#endif // BPP_PHYL_DISTANCE_NEIGHBORJOINING_H
Partial implementation of the AgglomerativeDistanceMethod interface.
virtual void setDistanceMatrix(const DistanceMatrix &matrix) override
Set the distance matrix to use.
void computeTree() override
Compute the tree corresponding to the distance matrix.
std::size_t size() const
The neighbor joining distance method.
NeighborJoining(const DistanceMatrix &matrix, bool rooted=false, bool positiveLengths=false, bool verbose=true)
Create a new NeighborJoining object instance and compute a tree from a distance matrix.
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.
NeighborJoining * clone() const
virtual void setDistanceMatrix(const DistanceMatrix &matrix)
Set the distance matrix to use.
std::vector< double > sumDist_
std::vector< size_t > getBestPair()
Get the best pair of nodes to agglomerate.
std::string getName() const
NeighborJoining(bool rooted=false, bool positiveLengths=false, bool verbose=true)
Create a new NeighborJoining object instance, without performing any computation.
void finalStep(int idRoot)
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of t...
virtual void outputPositiveLengths(bool yn)
std::vector< double > computeBranchLengthsForPair(const std::vector< size_t > &pair)
Compute the branch lengths for two nodes to agglomerate.
Defines the basic types of data flow nodes.