bpp-phyl3 3.0.0
HierarchicalClustering.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_HIERARCHICALCLUSTERING_H
6#define BPP_PHYL_DISTANCE_HIERARCHICALCLUSTERING_H
7
8
10
11namespace bpp
12{
14{
15public:
17 double length;
18
19public:
21 length(0) {}
22};
23
31{
32public:
33 static const std::string COMPLETE;
34 static const std::string SINGLE;
35 static const std::string AVERAGE;
36 static const std::string MEDIAN;
37 static const std::string WARD;
38 static const std::string CENTROID;
39
40protected:
41 std::string method_;
42
43public:
50 HierarchicalClustering(const std::string& method, bool verbose = false) :
52 method_(method) {}
53 HierarchicalClustering(const std::string& method, const DistanceMatrix& matrix, bool verbose = false) :
54 AbstractAgglomerativeDistanceMethod(matrix, verbose, true),
55 method_(method)
56 {
58 }
59
61
62 HierarchicalClustering* clone() const { return new HierarchicalClustering(*this); }
63
64public:
65 std::string getName() const { return "Hierarchical clustering: " + method_; }
66
67protected:
68 std::vector<size_t> getBestPair();
69 std::vector<double> computeBranchLengthsForPair(const std::vector<size_t>& pair);
70 double computeDistancesFromPair(const std::vector<size_t>& pair, const std::vector<double>& branchLengths, size_t pos);
71 void finalStep(int idRoot);
72 virtual Node* getLeafNode(int id, const std::string& name);
73 virtual Node* getParentNode(int id, Node* son1, Node* son2);
74};
75} // end of namespace bpp.
76#endif // BPP_PHYL_DISTANCE_HIERARCHICALCLUSTERING_H
Partial implementation of the AgglomerativeDistanceMethod interface.
void computeTree() override
Compute the tree corresponding to the distance matrix.
Hierarchical clustering.
HierarchicalClustering * clone() const
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< double > computeBranchLengthsForPair(const std::vector< size_t > &pair)
Compute the branch lengths for two nodes to agglomerate.
static const std::string AVERAGE
static const std::string CENTROID
virtual Node * getLeafNode(int id, const std::string &name)
Get a leaf node.
std::vector< size_t > getBestPair()
Get the best pair of nodes to agglomerate.
static const std::string COMPLETE
HierarchicalClustering(const std::string &method, bool verbose=false)
Builds a new clustering object.
static const std::string MEDIAN
virtual Node * getParentNode(int id, Node *son1, Node *son2)
Get an inner node.
void finalStep(int idRoot)
Method called when there ar eonly three remaining node to agglomerate, and creates the root node of t...
HierarchicalClustering(const std::string &method, const DistanceMatrix &matrix, bool verbose=false)
static const std::string SINGLE
static const std::string WARD
The phylogenetic node class.
Definition: Node.h:59
Defines the basic types of data flow nodes.