1818from pyclustering .cluster .tests .kmedoids_templates import kmedoids_test_template
1919from pyclustering .cluster .kmedoids import kmedoids
2020
21- from pyclustering .samples .definitions import SIMPLE_SAMPLES
21+ from pyclustering .samples .definitions import SIMPLE_SAMPLES , SIMPLE_ANSWERS
2222
2323from pyclustering .utils import read_sample
2424from pyclustering .utils .metric import type_metric , distance_metric
@@ -139,7 +139,7 @@ def testClusterAllocationTheSameObjectsThreeInitialMedoidsByCore(self):
139139 kmedoids_test_template .templateClusterAllocationTheSameObjects (25 , 3 , True )
140140
141141 def testCoreInterfaceIntInputData (self ):
142- kmedoids_instance = kmedoids ([ [1 ], [2 ], [3 ], [20 ], [21 ], [22 ] ], [ 2 , 5 ], 0.025 , True )
142+ kmedoids_instance = kmedoids ([[1 ], [2 ], [3 ], [20 ], [21 ], [22 ]], [2 , 5 ], 0.025 , True )
143143 kmedoids_instance .process ()
144144 assert len (kmedoids_instance .get_clusters ()) == 2
145145
@@ -153,18 +153,21 @@ def testAllocatedRequestedClustersSampleSimple04ByCore(self):
153153
154154 def testAllocatedRequestedClustersWithTheSamePointsByCore (self ):
155155 # Bug issue #366 - Kmedoids returns incorrect number of clusters.
156- sample = [ [0.0 , 0.0 ], [0.1 , 0.1 ], [0.0 , 0.0 ], [0.1 , 0.2 ] ]
157- kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 4 , None , True )
156+ sample = [[0.0 , 0.0 ], [0.1 , 0.1 ], [0.0 , 0.0 ], [0.1 , 0.2 ]]
157+ kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 3 , None , True )
158158 kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 3 , None , True )
159159 kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 2 , None , True )
160160 kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 1 , None , True )
161161
162+ def testAllocatedRequestedClustersWithTheSamePoints2 (self ):
163+ sample = [[0.23 , 0.2 ], [- 0.1 , 0.1 ], [0.0 , 0.9 ], [0.1 , - 0.2 ], [0.8 , 0.1 ], [- 0.1 , 0.1 ], [- 0.4 , - 0.2 ], [0.0 , 0.9 ]]
164+ answers = [1 , 2 , 3 , 4 , 5 , 6 , 6 , 6 ]
165+ for expected_amount in answers :
166+ kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , expected_amount , None , True )
167+
162168 def testAllocatedRequestedClustersWithTotallyTheSamePointsByCore (self ):
163169 # Bug issue #366 - Kmedoids returns incorrect number of clusters.
164- sample = [ [0.0 , 0.0 ], [0.0 , 0.0 ], [0.0 , 0.0 ], [0.0 , 0.0 ] ]
165- kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 4 , None , True )
166- kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 3 , None , True )
167- kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 2 , None , True )
170+ sample = [[0.0 , 0.0 ], [0.0 , 0.0 ], [0.0 , 0.0 ], [0.0 , 0.0 ]]
168171 kmedoids_test_template .templateAllocateRequestedClusterAmount (sample , 1 , None , True )
169172
170173
@@ -184,3 +187,82 @@ def testItermax10Simple01(self):
184187
185188 def testItermax10Simple02 (self ):
186189 kmedoids_test_template .templateLengthProcessData (SIMPLE_SAMPLES .SAMPLE_SIMPLE2 , [3 , 12 , 20 ], [10 , 5 , 8 ], True , itermax = 10 )
190+
191+
192+ def testSimple01AnswerByCore (self ):
193+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE1 , SIMPLE_ANSWERS .ANSWER_SIMPLE1 , True , random_state = 1000 )
194+
195+ def testSimple01AnswerDistanceMatrixByCore (self ):
196+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE1 , SIMPLE_ANSWERS .ANSWER_SIMPLE1 , True , random_state = 1000 , data_type = 'distance_matrix' )
197+
198+ def testSimple02AnswerByCore (self ):
199+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE2 , SIMPLE_ANSWERS .ANSWER_SIMPLE2 , True , random_state = 1000 )
200+
201+ def testSimple02AnswerDistanceMatrixByCore (self ):
202+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE2 , SIMPLE_ANSWERS .ANSWER_SIMPLE2 , True , random_state = 1000 , data_type = 'distance_matrix' )
203+
204+ def testSimple03AnswerByCore (self ):
205+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE3 , SIMPLE_ANSWERS .ANSWER_SIMPLE3 , True , random_state = 1000 )
206+
207+ def testSimple03AnswerDistanceMatrixByCore (self ):
208+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE3 , SIMPLE_ANSWERS .ANSWER_SIMPLE3 , True , random_state = 1000 , data_type = 'distance_matrix' )
209+
210+ def testSimple04AnswerByCore (self ):
211+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE4 , SIMPLE_ANSWERS .ANSWER_SIMPLE4 , True , random_state = 1000 )
212+
213+ def testSimple04AnswerDistanceMatrixByCore (self ):
214+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE4 , SIMPLE_ANSWERS .ANSWER_SIMPLE4 , True , random_state = 1000 , data_type = 'distance_matrix' )
215+
216+ def testSimple05AnswerByCore (self ):
217+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE5 , SIMPLE_ANSWERS .ANSWER_SIMPLE5 , True , random_state = 1000 )
218+
219+ def testSimple05AnswerDistanceMatrixByCore (self ):
220+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE5 , SIMPLE_ANSWERS .ANSWER_SIMPLE5 , True , random_state = 1000 , data_type = 'distance_matrix' )
221+
222+ def testSimple06AnswerByCore (self ):
223+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE6 , SIMPLE_ANSWERS .ANSWER_SIMPLE6 , True , random_state = 1000 )
224+
225+ def testSimple06AnswerDistanceMatrixByCore (self ):
226+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE6 , SIMPLE_ANSWERS .ANSWER_SIMPLE6 , True , random_state = 1000 , data_type = 'distance_matrix' )
227+
228+ def testSimple07AnswerByCore (self ):
229+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE7 , SIMPLE_ANSWERS .ANSWER_SIMPLE7 , True , random_state = 1000 )
230+
231+ def testSimple07AnswerDistanceMatrixByCore (self ):
232+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE7 , SIMPLE_ANSWERS .ANSWER_SIMPLE7 , True , random_state = 1000 , data_type = 'distance_matrix' )
233+
234+ def testSimple08AnswerByCore (self ):
235+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE8 , SIMPLE_ANSWERS .ANSWER_SIMPLE8 , True , random_state = 1000 )
236+
237+ def testSimple08AnswerDistanceMatrixByCore (self ):
238+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE8 , SIMPLE_ANSWERS .ANSWER_SIMPLE8 , True , random_state = 1000 , data_type = 'distance_matrix' )
239+
240+ def testSimple09AnswerByCore (self ):
241+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE9 , SIMPLE_ANSWERS .ANSWER_SIMPLE9 , True , random_state = 1000 )
242+
243+ def testSimple09AnswerDistanceMatrixByCore (self ):
244+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE9 , SIMPLE_ANSWERS .ANSWER_SIMPLE9 , True , random_state = 1000 , data_type = 'distance_matrix' )
245+
246+ def testSimple10AnswerByCore (self ):
247+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE10 , SIMPLE_ANSWERS .ANSWER_SIMPLE10 , True , random_state = 1000 )
248+
249+ def testSimple10AnswerDistanceMatrixByCore (self ):
250+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE10 , SIMPLE_ANSWERS .ANSWER_SIMPLE10 , True , random_state = 1000 , data_type = 'distance_matrix' )
251+
252+ def testSimple11AnswerByCore (self ):
253+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE11 , SIMPLE_ANSWERS .ANSWER_SIMPLE11 , True , random_state = 1000 )
254+
255+ def testSimple11AnswerDistanceMatrixByCore (self ):
256+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE11 , SIMPLE_ANSWERS .ANSWER_SIMPLE11 , True , random_state = 1000 , data_type = 'distance_matrix' )
257+
258+ def testSimple12AnswerByCore (self ):
259+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE12 , SIMPLE_ANSWERS .ANSWER_SIMPLE12 , True , random_state = 1000 )
260+
261+ def testSimple12AnswerDistanceMatrixByCore (self ):
262+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE12 , SIMPLE_ANSWERS .ANSWER_SIMPLE12 , True , random_state = 1000 , data_type = 'distance_matrix' )
263+
264+ def testSimple13AnswerByCore (self ):
265+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE13 , SIMPLE_ANSWERS .ANSWER_SIMPLE13 , True , random_state = 1000 )
266+
267+ def testSimple13AnswerDistanceMatrixByCore (self ):
268+ kmedoids_test_template .clustering_with_answer (SIMPLE_SAMPLES .SAMPLE_SIMPLE13 , SIMPLE_ANSWERS .ANSWER_SIMPLE13 , True , random_state = 1000 , data_type = 'distance_matrix' )
0 commit comments