Completed
Push — 0.8.dev ( 7407bb...c11acd )
by Andrei
53s
created

mbsas   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 26
rs 10
c 1
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B process() 0 22 5
A __init__() 0 2 1
1
"""!
2
3
@brief Cluster analysis algorithm: MBSAS (Modified Basic Sequential Algorithmic Scheme).
4
@details Implementation based on book:
5
         - Theodoridis, Koutroumbas, Konstantinos. Elsevier Academic Press - Pattern Recognition - 2nd Edition. 2003.
6
7
@authors Andrei Novikov ([email protected])
8
@date 2014-2018
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
29
from pyclustering.cluster.bsas import bsas;
30
31
32
class mbsas(bsas):
33
    def __init__(self, data, maximum_clusters, threshold, ccore=True, **kwargs):
34
        super().__init__(data, maximum_clusters, threshold, ccore, **kwargs);
35
36
    def process(self):
37
        self._clusters.append([0]);
38
        self._representatives.append(self._data[0]);
39
40
        skipped_objects = [];
41
42
        for i in range(1, len(self._data)):
43
            point = self._data[i];
44
            index_cluster, distance = self._find_nearest_cluster(point);
45
46
            if (distance > self._threshold) and (len(self._clusters) < self._amount):
47
                self._representatives.append(point);
48
                self._clusters.append([i]);
49
            else:
50
                skipped_objects.append(i);
51
52
        for i in skipped_objects:
53
            point = self._data[i];
54
            index_cluster, _ = self._find_nearest_cluster(point);
55
56
            self._clusters[index_cluster].append(i);
57
            self._update_representative(index_cluster, point);
58
59