-
Notifications
You must be signed in to change notification settings - Fork 1
/
GroupingMethod.h
127 lines (108 loc) · 4.16 KB
/
GroupingMethod.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef GROUPINGMETHOD_H
#define GROUPINGMETHOD_H
#include <vector>
#include <set>
#include <string>
#include <list>
#include "MethodsList.h"
#include "Structure.h"
#include "DistanceMatrix.h"
namespace cfp_internal
{
class GroupingMethod
{
public:
GroupingMethod()
{
mK = 0;
mMaxDistanceForGrouping = 0.01F;
}
std::string getName(void) const { return mName; }
virtual ~GroupingMethod() {}
void setKvalue(unsigned int aK) { mK = aK;}
void setMaxDistanceForGrouping(float aMaxDistanceForGrouping) { mMaxDistanceForGrouping = aMaxDistanceForGrouping;}
virtual void doGrouping(size_t aNumStructures, const DistanceMatrix& aDistances, std::vector< std::set<unsigned int> >& aResult) =0;
virtual bool needsK(void) const {return false;}
protected:
std::string mName;
unsigned int mK;
float mMaxDistanceForGrouping;
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class PseudoSNNGrouping : public GroupingMethod
{
public:
PseudoSNNGrouping() {mName = "Pseudo SNN";}
virtual void doGrouping(size_t aNumStructures, const DistanceMatrix& aDistances, std::vector< std::set<unsigned int> >& aResult);
void computeConnectionMatrix(size_t aNumStructures, const DistanceMatrix& aDistances, unsigned int* aConnection) const;
void doDepthFirstVisit(unsigned int aIdx, bool *aAssigned, std::set<unsigned int>& aGroups, unsigned int* aConnection, size_t aNumStructures) const;
virtual bool needsK(void) const {return true;}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class HierarchicalGrouping : public GroupingMethod
{
public:
virtual void doGrouping(size_t aNumStructures, const DistanceMatrix& aDistances, std::vector< std::set<unsigned int> >& aResult);
protected:
struct Node
{
Node() {}
Node(unsigned int i) { idx.push_back(i); }
std::vector<unsigned int> idx;
void Merge(const Node& n)
{
std::vector<unsigned int>::const_iterator ii;
for(ii=n.idx.begin(); ii != n.idx.end(); ++ii) idx.push_back(*ii);
}
void Merge(const std::list<Node>::iterator& n)
{
std::vector<unsigned int>::const_iterator ii;
for(ii=n->idx.begin(); ii != n->idx.end(); ++ii) idx.push_back(*ii);
}
};
public:
float ClusterDistanceSingleLinkage(std::list<HierarchicalGrouping::Node>::iterator& aNi,
std::list<HierarchicalGrouping::Node>::iterator& aNj,
const DistanceMatrix& aDistances) const;
float ClusterDistanceCompleteLinkage(std::list<HierarchicalGrouping::Node>::iterator& aNi,
std::list<HierarchicalGrouping::Node>::iterator& aNj,
const DistanceMatrix& aDistances) const;
protected:
float (HierarchicalGrouping::*ClusterDistance)(std::list<HierarchicalGrouping::Node>::iterator& aNi,
std::list<HierarchicalGrouping::Node>::iterator& aNj,
const DistanceMatrix& aDistances) const;
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class HierarchicalSingleLinkageGrouping : public HierarchicalGrouping
{
public:
HierarchicalSingleLinkageGrouping()
{
mName = "Hierarchical grouping (single linkage)";
ClusterDistance = &HierarchicalGrouping::ClusterDistanceSingleLinkage;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class HierarchicalCompleteLinkageGrouping : public HierarchicalGrouping
{
public:
HierarchicalCompleteLinkageGrouping()
{
mName = "Hierarchical grouping (complete linkage)";
ClusterDistance = &HierarchicalGrouping::ClusterDistanceCompleteLinkage;
}
};
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
class GroupingMethodsList : public MethodsList<GroupingMethod>
{
public:
GroupingMethodsList()
{
mMethodsList.push_back(new PseudoSNNGrouping);
mMethodsList.push_back(new HierarchicalSingleLinkageGrouping);
mMethodsList.push_back(new HierarchicalCompleteLinkageGrouping);
}
~GroupingMethodsList() {clear();}
};
}
#endif