3 @brief Cluster analysis algorithm: MBSAS (Modified Basic Sequential Algorithmic Scheme).
4 @details Implementation based on paper @cite book::pattern_recognition::2009.
6 @authors Andrei Novikov (pyclustering@yandex.ru)
8 @copyright BSD-3-Clause
13 from pyclustering.core.mbsas_wrapper
import mbsas
as mbsas_wrapper
14 from pyclustering.core.metric_wrapper
import metric_wrapper
21 @brief Class represents MBSAS (Modified Basic Sequential Algorithmic Scheme).
22 @details Interface of MBSAS algorithm is the same as for BSAS. This algorithm performs clustering in two steps.
23 The first - is determination of amount of clusters. The second - is assignment of points that were not
24 marked as a cluster representatives to clusters.
26 Code example of MBSAS usage:
28 from pyclustering.cluster.bsas import bsas_visualizer
29 from pyclustering.cluster.mbsas import mbsas
30 from pyclustering.utils import read_sample
31 from pyclustering.samples.definitions import SIMPLE_SAMPLES
33 # Read data sample from 'Simple02.data'.
34 sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE2)
36 # Prepare algorithm's parameters.
40 # Create instance of MBSAS algorithm.
41 mbsas_instance = mbsas(sample, max_clusters, threshold)
42 mbsas_instance.process()
44 # Get clustering results.
45 clusters = mbsas_instance.get_clusters()
46 representatives = mbsas_instance.get_representatives()
49 bsas_visualizer.show_clusters(sample, clusters, representatives)
52 @see pyclustering.cluster.bsas, pyclustering.cluster.ttsas
56 def __init__(self, data, maximum_clusters, threshold, ccore=True, **kwargs):
58 @brief Creates MBSAS algorithm.
60 @param[in] data (list): Input data that is presented as list of points (objects), each point should be represented by list or tuple.
61 @param[in] maximum_clusters: Maximum allowable number of clusters that can be allocated during processing.
62 @param[in] threshold: Threshold of dissimilarity (maximum distance) between points.
63 @param[in] ccore (bool): If True than DLL CCORE (C++ solution) will be used for solving.
64 @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'metric').
66 <b>Keyword Args:</b><br>
67 - metric (distance_metric): Metric that is used for distance calculation between two points.
70 super().
__init__(data, maximum_clusters, threshold, ccore, **kwargs)
75 @brief Performs cluster analysis in line with MBSAS algorithm.
77 @return (mbsas) Returns itself (MBSAS instance).
80 @see get_representatives()
92 def __process_by_ccore(self):
93 ccore_metric = metric_wrapper.create_instance(self.
_metric)
97 def __prcess_by_python(self):
101 skipped_objects = [];
103 for i
in range(1, len(self.
_data)):
104 point = self.
_data[i];
111 skipped_objects.append(i);
113 for i
in skipped_objects:
114 point = self.
_data[i];