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 GNU Public License 10 @cond GNU_PUBLIC_LICENSE 11 PyClustering is free software: you can redistribute it and/or modify 12 it under the terms of the GNU General Public License as published by 13 the Free Software Foundation, either version 3 of the License, or 14 (at your option) any later version. 16 PyClustering is distributed in the hope that it will be useful, 17 but WITHOUT ANY WARRANTY; without even the implied warranty of 18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 GNU General Public License for more details. 21 You should have received a copy of the GNU General Public License 22 along with this program. If not, see <http://www.gnu.org/licenses/>. 28 from pyclustering.core.mbsas_wrapper
import mbsas
as mbsas_wrapper
29 from pyclustering.core.metric_wrapper
import metric_wrapper
36 @brief Class represents MBSAS (Modified Basic Sequential Algorithmic Scheme). 37 @details Interface of MBSAS algorithm is the same as for BSAS. This algorithm performs clustering in two steps. 38 The first - is determination of amount of clusters. The second - is assignment of points that were not 39 marked as a cluster representatives to clusters. 41 Code example of MBSAS usage: 43 from pyclustering.cluster.bsas import bsas_visualizer 44 from pyclustering.cluster.mbsas import mbsas 45 from pyclustering.utils import read_sample 46 from pyclustering.samples.definitions import SIMPLE_SAMPLES 48 # Read data sample from 'Simple02.data'. 49 sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE2) 51 # Prepare algorithm's parameters. 55 # Create instance of MBSAS algorithm. 56 mbsas_instance = mbsas(sample, max_clusters, threshold) 57 mbsas_instance.process() 59 # Get clustering results. 60 clusters = mbsas_instance.get_clusters() 61 representatives = mbsas_instance.get_representatives() 64 bsas_visualizer.show_clusters(sample, clusters, representatives) 67 @see pyclustering.cluster.bsas, pyclustering.cluster.ttsas 71 def __init__(self, data, maximum_clusters, threshold, ccore=True, **kwargs):
73 @brief Creates MBSAS algorithm. 75 @param[in] data (list): Input data that is presented as list of points (objects), each point should be represented by list or tuple. 76 @param[in] maximum_clusters: Maximum allowable number of clusters that can be allocated during processing. 77 @param[in] threshold: Threshold of dissimilarity (maximum distance) between points. 78 @param[in] ccore (bool): If True than DLL CCORE (C++ solution) will be used for solving. 79 @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'metric'). 81 <b>Keyword Args:</b><br> 82 - metric (distance_metric): Metric that is used for distance calculation between two points. 85 super().
__init__(data, maximum_clusters, threshold, ccore, **kwargs)
90 @brief Performs cluster analysis in line with MBSAS algorithm. 92 @return (mbsas) Returns itself (MBSAS instance). 95 @see get_representatives() 107 def __process_by_ccore(self):
108 ccore_metric = metric_wrapper.create_instance(self.
_metric)
112 def __prcess_by_python(self):
116 skipped_objects = [];
118 for i
in range(1, len(self.
_data)):
119 point = self.
_data[i];
126 skipped_objects.append(i);
128 for i
in skipped_objects:
129 point = self.
_data[i];
def __init__(self, data, maximum_clusters, threshold, ccore=True, kwargs)
Creates MBSAS algorithm.
Class represents BSAS clustering algorithm - basic sequential algorithmic scheme. ...
Cluster analysis algorithm: BSAS (Basic Sequential Algorithmic Scheme).
Class represents MBSAS (Modified Basic Sequential Algorithmic Scheme).
def process(self)
Performs cluster analysis in line with MBSAS algorithm.
def _find_nearest_cluster(self, point)
Find nearest cluster to the specified point.
def __prcess_by_python(self)
def __process_by_ccore(self)
def _update_representative(self, index_cluster, point)
Update cluster representative in line with new cluster size and added point to it.