Completed
Push — master ( 0def1b...f9065b )
by Andrei
01:45
created

chameleon   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 39
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get_clusters() 0 9 1
A __init__() 0 7 2
A process() 0 2 1
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;
0 ignored issues
show
Unused Code introduced by
Unused euclidean_distance_sqrt imported from pyclustering.utils
Loading history...
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):
0 ignored issues
show
Comprehensibility Bug introduced by
knearest is re-defining a name which is already available in the outer-scope (previously defined on line 28).

It is generally a bad practice to shadow variables from the outer-scope. In most cases, this is done unintentionally and might lead to unexpected behavior:

param = 5

class Foo:
    def __init__(self, param):   # "param" would be flagged here
        self.param = param
Loading history...
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