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 BSD-3-Clause
13 from pyclustering.core.ttsas_wrapper
import ttsas
as ttsas_wrapper
14 from pyclustering.core.metric_wrapper
import metric_wrapper
21 @brief Class represents TTSAS (Two-Threshold Sequential Algorithmic Scheme).
22 @details Clustering results of BSAS and MBSAS are strongly dependent on the order in which the points in data.
23 TTSAS helps to overcome this shortcoming by using two threshold parameters. The first - if the distance
24 to the nearest cluster is less than the first threshold then point is assigned to the cluster. The
25 second - if distance to the nearest cluster is greater than the second threshold then new cluster is
28 Code example of TTSAS usage:
30 from pyclustering.cluster.bsas import bsas_visualizer
31 from pyclustering.cluster.ttsas import ttsas
32 from pyclustering.samples.definitions import SIMPLE_SAMPLES
33 from pyclustering.utils import read_sample
35 # Read data sample from 'Simple03.data'.
36 sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
38 # Prepare algorithm's parameters.
42 # Create instance of TTSAS algorithm.
43 ttsas_instance = ttsas(sample, threshold1, threshold2)
44 ttsas_instance.process()
46 # Get clustering results.
47 clusters = ttsas_instance.get_clusters()
48 representatives = ttsas_instance.get_representatives()
50 # Display results using BSAS visualizer.
51 bsas_visualizer.show_clusters(sample, clusters, representatives)
54 @see pyclustering.cluster.bsas, pyclustering.cluster.mbsas
58 def __init__(self, data, threshold1, threshold2, ccore=True, **kwargs):
60 @brief Creates TTSAS algorithm.
62 @param[in] data (list): Input data that is presented as list of points (objects), each point should be represented by list or tuple.
63 @param[in] threshold1: Dissimilarity level (distance) between point and its closest cluster, if the distance is
64 less than 'threshold1' value then point is assigned to the cluster.
65 @param[in] threshold2: Dissimilarity level (distance) between point and its closest cluster, if the distance is
66 greater than 'threshold2' value then point is considered as a new cluster.
67 @param[in] ccore (bool): If True than DLL CCORE (C++ solution) will be used for solving.
68 @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'metric').
70 <b>Keyword Args:</b><br>
71 - metric (distance_metric): Metric that is used for distance calculation between two points.
79 super().
__init__(data, len(data), threshold1, ccore, **kwargs)
84 @brief Performs cluster analysis in line with rules of TTSAS algorithm.
86 @return (ttsas) Returns itself (TTSAS instance).
89 @see get_representatives()
101 def __process_by_ccore(self):
102 ccore_metric = metric_wrapper.create_instance(self.
_metric)
106 def __prcess_by_python(self):
115 def __process_objects(self, changes):
122 for i
in range(index_point, len(self.
_data)):
127 def __process_skipped_object(self, index_point):
128 point = self.
_data[index_point]
138 def __append_to_cluster(self, index_cluster, index_point, point):
139 self.
_clusters[index_cluster].append(index_point)
146 def __allocate_cluster(self, index_point, point):