-
Notifications
You must be signed in to change notification settings - Fork 0
/
cluster.h
139 lines (117 loc) · 4.51 KB
/
cluster.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
128
129
130
131
132
133
134
135
136
137
138
139
/**
* @file cluster.h
* @brief Cluster class definition
*
* Defines the Cluster class and implements a few inline methods
*/
#ifndef CLUSTER_H
#define CLUSTER_H
#include <vector>
#include <tr1/memory>
using namespace std;
using namespace std::tr1;
/**
* @class Cluster
* Represents each cluster generated in the process.
* It holds a cluster identifier, a pointer to a vector of members,
* the maximum distance within members of the cluster, the cluster
* centroid (member with smallest max distance to other member),
* the cluster radius and a boolean flag that indicates whether or not
* the cluster has been merged into a posterior cluster.
*/
class Node; // Forward declaration of Node class
class Cluster
{
private:
int id_; // Unique identifier
vector<shared_ptr<Node> > members_; /* A vector contaning all the
elements in this cluster */
float maxDistance_; /* The maximum distance between
members of this cluster */
shared_ptr<Node> centroid_; // Member with smallest distance
// to all other members (sum)
float radius_; // largest distance from the
// centroid to a member
bool active_;
public:
/**
* Constructor
* @param id Unique identifier
* @param members Shared pointer to vector containing cluster members
* @param maxDistance Maximum distance between any two members of
* the cluster
*/
Cluster(int id, vector<shared_ptr<Node> > &members,
float maxDistance) : id_(id),members_(members),
maxDistance_(maxDistance)
{
centroid_=members_[0];
radius_=0;
active_=true;
}
/**
* Returns the cluster identifier
* @return id
*/
int getID(){return id_;};
/**
* Returns the shared pointer to the vector of cluster members
* @return members
*/
vector<shared_ptr<Node> > getMembers(){return members_;};
/**
* Returns the maximum distance between cluster members
* @return maxDistance
*/
float getMaxDistance(){return maxDistance_;};
/**
* Updates the maximum distance within the cluster
* @param maxDistance New maximum distance in the clsuter
*/
void setMaxDistance(float maxDistance){maxDistance_=maxDistance;};
/**
* Calculates the cluster centroid as the member whose maxmum
* distance to any other member is the smallest.
* It assigns the value of the cluster radius (from centroid)
* in the process.
* @param normScores A distance matrix with all the normalized
* distances between members
*/
void calcCentroid(vector< vector<float> > normScores);
/**
* Calculates the maximum distance between any two members of the
* cluster.
* @param normScores A distance matrix with all the normalized
* distances between members
*/
void calcMaxDistance(vector< vector<float> > normScores);
/**
* Returns a shared pointer to the cluster centroid
* @return centroid A shared pointer to the centroid Node
*/
shared_ptr<Node> getCentroid(){return centroid_;};
/**
* Sets the cluster centroid to a new Node
* @param centroid A shared pointer to the centroid Node
*/
void setCentroid(shared_ptr<Node> A){centroid_=A;}
/**
* Returns the cluster radius
* @return radius The maximum distance from the centroid Node to another
* member of the cluster
*/
float getRadius(){return radius_;};
/**
* Changes the status of the cluster, marking it as "new" or already
* merged into a posterior one
*/
void setStatus(){active_=!active_;};
/**
* Returns the active status. True if it has not yet been merged into a
* posterior cluster, false otherwise
* @return status Bool that indicates whether or not the cluster was
* formed in the "final round" of clustering
*/
bool getStatus(){return active_;};
};
#endif