3 @brief Cluster analysis algorithm: TTSAS (Two-Threshold 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.ttsas_wrapper
import ttsas
as ttsas_wrapper
29 from pyclustering.core.metric_wrapper
import metric_wrapper
36 @brief Class represents TTSAS (Two-Threshold Sequential Algorithmic Scheme). 37 @details Clustering results of BSAS and MBSAS are strongly dependent on the order in which the points in data. 38 TTSAS helps to overcome this shortcoming by using two threshold parameters. The first - if the distance 39 to the nearest cluster is less than the first threshold then point is assigned to the cluster. The 40 second - if distance to the nearest cluster is greater than the second threshold then new cluster is 43 Code example of TTSAS usage: 45 from pyclustering.cluster.bsas import bsas_visualizer 46 from pyclustering.cluster.ttsas import ttsas 47 from pyclustering.samples.definitions import SIMPLE_SAMPLES 48 from pyclustering.utils import read_sample 50 # Read data sample from 'Simple03.data'. 51 sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3) 53 # Prepare algorithm's parameters. 57 # Create instance of TTSAS algorithm. 58 ttsas_instance = ttsas(sample, threshold1, threshold2) 59 ttsas_instance.process() 61 # Get clustering results. 62 clusters = ttsas_instance.get_clusters() 63 representatives = ttsas_instance.get_representatives() 65 # Display results using BSAS visualizer. 66 bsas_visualizer.show_clusters(sample, clusters, representatives) 69 @see pyclustering.cluster.bsas, pyclustering.cluster.mbsas 73 def __init__(self, data, threshold1, threshold2, ccore=True, **kwargs):
75 @brief Creates TTSAS algorithm. 77 @param[in] data (list): Input data that is presented as list of points (objects), each point should be represented by list or tuple. 78 @param[in] threshold1: Dissimilarity level (distance) between point and its closest cluster, if the distance is 79 less than 'threshold1' value then point is assigned to the cluster. 80 @param[in] threshold2: Dissimilarity level (distance) between point and its closest cluster, if the distance is 81 greater than 'threshold2' value then point is considered as a new cluster. 82 @param[in] ccore (bool): If True than DLL CCORE (C++ solution) will be used for solving. 83 @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'metric'). 85 <b>Keyword Args:</b><br> 86 - metric (distance_metric): Metric that is used for distance calculation between two points. 94 super().
__init__(data, len(data), threshold1, ccore, **kwargs)
99 @brief Performs cluster analysis in line with rules of TTSAS algorithm. 101 @return (ttsas) Returns itself (TTSAS instance). 104 @see get_representatives() 116 def __process_by_ccore(self):
117 ccore_metric = metric_wrapper.create_instance(self.
_metric)
121 def __prcess_by_python(self):
130 def __process_objects(self, changes):
137 for i
in range(index_point, len(self.
_data)):
142 def __process_skipped_object(self, index_point):
143 point = self.
_data[index_point]
153 def __append_to_cluster(self, index_cluster, index_point, point):
154 self.
_clusters[index_cluster].append(index_point)
161 def __allocate_cluster(self, index_point, point):
Class represents BSAS clustering algorithm - basic sequential algorithmic scheme. ...
Cluster analysis algorithm: BSAS (Basic Sequential Algorithmic Scheme).
def __process_skipped_object(self, index_point)
Class represents TTSAS (Two-Threshold Sequential Algorithmic Scheme).
def __allocate_cluster(self, index_point, point)
def _find_nearest_cluster(self, point)
Find nearest cluster to the specified point.
def __prcess_by_python(self)
def __init__(self, data, threshold1, threshold2, ccore=True, kwargs)
Creates TTSAS algorithm.
def __process_by_ccore(self)
def __append_to_cluster(self, index_cluster, index_point, point)
def _update_representative(self, index_cluster, point)
Update cluster representative in line with new cluster size and added point to it.
def process(self)
Performs cluster analysis in line with rules of TTSAS algorithm.
def __process_objects(self, changes)