|
1
|
|
|
"""!
|
|
2
|
|
|
|
|
3
|
|
|
@brief Cluster analysis algorithm: CHAMELEON
|
|
4
|
|
|
@details Implementation based on article:
|
|
5
|
|
|
- G.Karypis, E.Han, V.Kumar. CHAMELEON: A Hierarchical Clustering Algorithm Using Dynamic Modeling. 1999.
|
|
6
|
|
|
|
|
7
|
|
|
@authors Andrei Novikov ([email protected])
|
|
8
|
|
|
@date 2014-2017
|
|
9
|
|
|
@copyright GNU Public License
|
|
10
|
|
|
|
|
11
|
|
|
@cond GNU_PUBLIC_LICENSE
|
|
12
|
|
|
PyClustering is free software: you can redistribute it and/or modify
|
|
13
|
|
|
it under the terms of the GNU General Public License as published by
|
|
14
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
15
|
|
|
(at your option) any later version.
|
|
16
|
|
|
|
|
17
|
|
|
PyClustering is distributed in the hope that it will be useful,
|
|
18
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
19
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
20
|
|
|
GNU General Public License for more details.
|
|
21
|
|
|
|
|
22
|
|
|
You should have received a copy of the GNU General Public License
|
|
23
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
24
|
|
|
@endcond
|
|
25
|
|
|
|
|
26
|
|
|
"""
|
|
27
|
|
|
|
|
28
|
|
|
from pyclustering.utils import euclidean_distance_sqrt, knearest;
|
|
|
|
|
|
|
29
|
|
|
|
|
30
|
|
|
|
|
31
|
|
|
class chameleon:
|
|
32
|
|
|
"""!
|
|
33
|
|
|
@brief Class represents clustering algorithm CHAMELEON.
|
|
34
|
|
|
@details CHAMELEON finds the clusters in the data set by using a two phase algorithm. During the first phase,
|
|
35
|
|
|
CHAMELEON uses a graph partitioning algorithm to cluster the data items into a large number of relatively
|
|
36
|
|
|
small sub-clusters. During the second phase, it uses an agglomerative hierarchical clustering algorithm
|
|
37
|
|
|
to find the genuine clusters by repeatedly combining together these sub-clusters.
|
|
38
|
|
|
|
|
39
|
|
|
Example:
|
|
40
|
|
|
@code
|
|
41
|
|
|
NO CODE
|
|
42
|
|
|
@endcode
|
|
43
|
|
|
|
|
44
|
|
|
"""
|
|
45
|
|
|
|
|
46
|
|
|
def __init__(self, data, knearest, ccore = False):
|
|
|
|
|
|
|
47
|
|
|
self.__data = data;
|
|
48
|
|
|
self.__clusters = [];
|
|
49
|
|
|
self.__knearest = knearest;
|
|
50
|
|
|
|
|
51
|
|
|
self.__graph = [ [] for _ in range(len(data)) ];
|
|
52
|
|
|
self.__ccore = ccore;
|
|
53
|
|
|
|
|
54
|
|
|
|
|
55
|
|
|
|
|
56
|
|
|
def process(self):
|
|
57
|
|
|
self.__graph = knearest(self.__data, self.__knearest);
|
|
58
|
|
|
|
|
59
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
def get_clusters(self):
|
|
62
|
|
|
"""!
|
|
63
|
|
|
@brief Returns list of allocated clusters, each cluster contains indexes of objects in list of data.
|
|
64
|
|
|
|
|
65
|
|
|
@see process()
|
|
66
|
|
|
|
|
67
|
|
|
"""
|
|
68
|
|
|
|
|
69
|
|
|
return self.__clusters;
|
|
70
|
|
|
|
|
71
|
|
|
|