pyclustering  0.10.1
pyclustring is a Python, C++ data mining library.
clique.py
1 """!
2 
3 @brief Cluster analysis algorithm: CLIQUE
4 @details Implementation based on paper @cite article::clique::1.
5 
6 @authors Andrei Novikov (pyclustering@yandex.ru)
7 @date 2014-2020
8 @copyright BSD-3-Clause
9 
10 """
11 
12 
13 import itertools
14 
15 from pyclustering.cluster import cluster_visualizer
16 from pyclustering.cluster.encoder import type_encoding
17 
18 from pyclustering.core.wrapper import ccore_library
19 
20 import pyclustering.core.clique_wrapper as wrapper
21 
22 import matplotlib
23 import matplotlib.gridspec as gridspec
24 import matplotlib.pyplot as plt
25 import matplotlib.patches as patches
26 
27 
29  """!
30  @brief Visualizer of CLIQUE algorithm's results.
31  @details CLIQUE visualizer provides visualization services that are specific for CLIQUE algorithm, for example,
32  to display grid and its density.
33 
34  """
35 
36  __maximum_density_alpha = 0.6
37 
38  @staticmethod
39  def show_grid(cells, data):
40  """!
41  @brief Show CLIQUE blocks as a grid in data space.
42  @details Each block contains points and according to this density is displayed. CLIQUE grid helps to visualize
43  grid that was used for clustering process.
44 
45  @param[in] cells (list): List of cells that is produced by CLIQUE algorithm.
46  @param[in] data (array_like): Input data that was used for clustering process.
47 
48  """
49  dimension = cells[0].dimensions
50 
51  amount_canvases = 1
52  if dimension > 1:
53  amount_canvases = int(dimension * (dimension - 1) / 2)
54 
55  figure = plt.figure()
56  grid_spec = gridspec.GridSpec(1, amount_canvases)
57 
58  pairs = list(itertools.combinations(range(dimension), 2))
59  if len(pairs) == 0: pairs = [(0, 0)]
60 
61  for index in range(amount_canvases):
62  ax = figure.add_subplot(grid_spec[index])
63  clique_visualizer.__draw_cells(ax, cells, pairs[index])
64  clique_visualizer.__draw_two_dimension_data(ax, data, pairs[index])
65 
66  plt.show()
67 
68 
69  @staticmethod
70  def show_clusters(data, clusters, noise=None):
71  """!
72  @brief Display CLIQUE clustering results.
73 
74  @param[in] data (list): Data that was used for clustering.
75  @param[in] clusters (array_like): Clusters that were allocated by the algorithm.
76  @param[in] noise (array_like): Noise that were allocated by the algorithm.
77 
78  """
79  visualizer = cluster_visualizer()
80  visualizer.append_clusters(clusters, data)
81  visualizer.append_cluster(noise or [], data, marker='x')
82  visualizer.show()
83 
84 
85  @staticmethod
86  def __draw_two_dimension_data(ax, data, pair):
87  """!
88  @brief Display data in two-dimensional canvas.
89 
90  @param[in] ax (Axis): Canvas where data should be displayed.
91  @param[in] data (list): Data points that should be displayed.
92  @param[in] pair (tuple): Pair of dimension indexes.
93 
94  """
95  ax.set_xlabel("x%d" % pair[0])
96  ax.set_ylabel("x%d" % pair[1])
97 
98  for point in data:
99  if len(data[0]) > 1:
100  ax.plot(point[pair[0]], point[pair[1]], color='red', marker='.')
101  else:
102  ax.plot(point[pair[0]], 0, color='red', marker='.')
103  ax.yaxis.set_ticklabels([])
104 
105 
106  @staticmethod
107  def __draw_cells(ax, cells, pair):
108  ax.grid(False)
109 
110  density_scale = max(len(cell.points) for cell in cells)
111  for cell in cells:
112  clique_visualizer.__draw_cell(ax, pair, cell, density_scale)
113 
114 
115  @staticmethod
116  def __draw_cell(ax, pair, cell, density_scale):
117  max_corner, min_corner = clique_visualizer.__get_rectangle_description(cell, pair)
118 
119  belong_cluster = (len(cell.points) > 0)
120 
121  if density_scale != 0.0:
122  density_scale = clique_visualizer.__maximum_density_alpha * len(cell.points) / density_scale
123 
124  face_color = matplotlib.colors.to_rgba('blue', alpha=density_scale)
125  edge_color = matplotlib.colors.to_rgba('black', alpha=1.0)
126 
127  rect = patches.Rectangle(min_corner, max_corner[0] - min_corner[0], max_corner[1] - min_corner[1],
128  fill=belong_cluster,
129  facecolor=face_color,
130  edgecolor=edge_color,
131  linewidth=0.5)
132  ax.add_patch(rect)
133  #ax.annotate(str(cell.logical_location), (min_corner[0], min_corner[1]), fontsize=6, ha='center', va='center')
134 
135 
136  @staticmethod
137  def __get_rectangle_description(cell, pair):
138  max_corner, min_corner = cell.spatial_location.get_corners()
139 
140  max_corner = [max_corner[pair[0]], max_corner[pair[1]]]
141  min_corner = [min_corner[pair[0]], min_corner[pair[1]]]
142 
143  if pair == (0, 0):
144  max_corner[1], min_corner[1] = 1.0, -1.0
145 
146  return max_corner, min_corner
147 
148 
149 
151  """!
152  @brief Geometrical description of CLIQUE block in data space.
153  @details Provides services related to spatial functionality.
154 
155  @see bang_block
156 
157  """
158 
159  def __init__(self, max_corner, min_corner):
160  """!
161  @brief Creates spatial block in data space.
162 
163  @param[in] max_corner (array_like): Maximum corner coordinates of the block.
164  @param[in] min_corner (array_like): Minimal corner coordinates of the block.
165 
166  """
167  self.__max_corner = max_corner
168  self.__min_corner = min_corner
169 
170 
171  def __str__(self):
172  """!
173  @brief Returns string block description.
174 
175  @return String representation of the block.
176 
177  """
178  return "(max: %s; min: %s)" % (self.__max_corner, self.__min_corner)
179 
180 
181  def __contains__(self, point):
182  """!
183  @brief Point is considered as contained if it lies in block (belong to it).
184 
185  @return (bool) True if point is in block, otherwise False.
186 
187  """
188  for i in range(len(point)):
189  if point[i] < self.__min_corner[i] or point[i] > self.__max_corner[i]:
190  return False
191 
192  return True
193 
194 
195  def get_corners(self):
196  """!
197  @brief Return spatial description of current block.
198 
199  @return (tuple) Pair of maximum and minimum corners (max_corner, min_corner).
200 
201  """
202  return self.__max_corner, self.__min_corner
203 
204 
205 
207  """!
208  @brief CLIQUE block contains information about its logical location in grid, spatial location in data space and
209  points that are covered by the block.
210 
211  """
212 
213  def __init__(self, logical_location=None, spatial_location=None, points=None, visited=False):
214  """!
215  @brief Initializes CLIQUE block.
216 
217  @param[in] logical_location (list): Logical location of the block in CLIQUE grid.
218  @param[in] spatial_location (spatial_block): Spatial location in data space.
219  @param[in] points (array_like): Points that belong to this block (can be obtained by method 'capture_points',
220  this parameter is used by CLIQUE in case of processing by C++ implementation when clustering
221  result are passed back to Python code.
222  @param[in] visited (bool): Marks if block is visited during clustering process.
223 
224  """
225  self.__logical_location = logical_location or []
226  self.__spatial_location = spatial_location
227  self.__points = points or []
228  self.__visited = visited
229 
230  def __str__(self):
231  """!
232  @brief Returns string representation of the block using its logical location in CLIQUE grid.
233 
234  """
235  return str(self.__logical_location)
236 
237  def __repr__(self):
238  """!
239  @brief Returns string representation of the block using its logical location in CLIQUE grid.
240 
241  """
242  return str(self.__logical_location)
243 
244  @property
245  def logical_location(self):
246  """!
247  @brief Logical location is represented by coordinates in CLIQUE grid, for example, in case of 2x2 grid blocks
248  may have following coordinates: [0, 0], [0, 1], [1, 0], [1, 1].
249  @return (list) Logical location of the block in CLIQUE grid.
250 
251  """
252  return self.__logical_location
253 
254  @logical_location.setter
255  def logical_location(self, location):
256  """!
257  @brief Assign logical location to CLIQUE block.
258 
259  @param[in] location (list): New logical location of the block in CLIQUE grid.
260 
261  """
262  self.__logical_location = location
263 
264  @property
265  def spatial_location(self):
266  """!
267  @brief Spatial location is represented by real data space coordinates.
268  @return (spatial_block) Spatial block that describes location in data space.
269 
270  """
271  return self.__spatial_location
272 
273  @spatial_location.setter
274  def spatial_location(self, location):
275  """!
276  @brief Assign spatial location to CLIQUE block.
277 
278  @param[in] location (spatial_block): New spatial location of the block.
279 
280  """
281  self.__spatial_location = location
282 
283  @property
284  def dimensions(self):
285  """!
286  @brief Amount of dimensions where CLIQUE block is located.
287  @return (uint) Amount of dimensions where CLIQUE block is located.
288 
289  """
290  return len(self.__logical_location)
291 
292  @property
293  def points(self):
294  """!
295  @brief Points that belong to the CLIQUE block.
296  @details Points are represented by indexes that correspond to points in input data space.
297 
298  @return (array_like) Points that belong to the CLIQUE block.
299 
300  @see capture_points
301 
302  """
303  return self.__points
304 
305  @property
306  def visited(self):
307  """!
308  @brief Defines whether block is visited during cluster analysis.
309  @details If cluster analysis has not been performed then value will False.
310 
311  @return (bool) True if block has been visited during processing, False otherwise.
312 
313  """
314  return self.__visited
315 
316  @visited.setter
317  def visited(self, visited):
318  """!
319  @brief Marks or unmarks block as a visited.
320  @details This setter is used by CLIQUE algorithm.
321 
322  @param[in] visited (bool): New visited state for the CLIQUE block.
323 
324  """
325  self.__visited = visited
326 
327 
328  def capture_points(self, data, point_availability):
329  """!
330  @brief Finds points that belong to this block using availability map to reduce computational complexity by
331  checking whether the point belongs to the block.
332  @details Algorithm complexity of this method is O(n).
333 
334  @param[in] data (array_like): Data where points are represented as coordinates.
335  @param[in] point_availability (array_like): Contains boolean values that denote whether point is already belong
336  to another CLIQUE block.
337 
338  """
339  for index_point in range(len(data)):
340  if (point_availability[index_point] is True) and (data[index_point] in self.__spatial_location):
341  self.__points.append(index_point)
342  point_availability[index_point] = False
343 
344 
345  def get_location_neighbors(self, edge):
346  """!
347  @brief Forms list of logical location of each neighbor for this particular CLIQUE block.
348 
349  @param[in] edge (uint): Amount of intervals in each dimension that is used for clustering process.
350 
351  @return (list) Logical location of each neighbor for this particular CLIQUE block.
352 
353  """
354  neighbors = []
355 
356  for index_dimension in range(len(self.__logical_location)):
357  if self.__logical_location[index_dimension] + 1 < edge:
358  position = self.__logical_location[:]
359  position[index_dimension] += 1
360  neighbors.append(position)
361 
362  if self.__logical_location[index_dimension] - 1 >= 0:
363  position = self.__logical_location[:]
364  position[index_dimension] -= 1
365  neighbors.append(position)
366 
367  return neighbors
368 
369 
370 
372  """!
373  @brief Coordinate iterator is used to generate logical location description for each CLIQUE block.
374  @details This class is used by CLIQUE algorithm for clustering process.
375 
376  """
377 
378  def __init__(self, dimension, intervals):
379  """!
380  @brief Initializes coordinate iterator for CLIQUE algorithm.
381 
382  @param[in] dimension (uint): Amount of dimensions in input data space.
383  @param[in] intervals (uint): Amount of intervals in each dimension.
384 
385  """
386  self.__intervals = intervals
387  self.__dimension = dimension
388  self.__coordiate = [0] * dimension
389 
390 
391  def get_coordinate(self):
392  """!
393  @brief Returns current block coordinate.
394 
395  """
396  return self.__coordiate
397 
398 
399  def increment(self):
400  """!
401  @brief Forms logical location for next block.
402 
403  """
404  for index_dimension in range(self.__dimension):
405  if self.__coordiate[index_dimension] + 1 < self.__intervals:
406  self.__coordiate[index_dimension] += 1
407  return
408  else:
409  self.__coordiate[index_dimension] = 0
410 
411  self.__coordiate = None
412 
413 
414 
415 class clique:
416  """!
417  @brief Class implements CLIQUE grid based clustering algorithm.
418  @details CLIQUE automatically finds subspaces with high-density clusters. It produces identical results
419  irrespective of the order in which the input records are presented and it does not presume any canonical
420  distribution for input data @cite article::clique::1.
421 
422  Here is an example where data in two-dimensional space is clustered using CLIQUE algorithm:
423  @code
424  from pyclustering.cluster.clique import clique, clique_visualizer
425  from pyclustering.utils import read_sample
426  from pyclustering.samples.definitions import FCPS_SAMPLES
427 
428  # read two-dimensional input data 'Target'
429  data = read_sample(FCPS_SAMPLES.SAMPLE_TARGET)
430 
431  # create CLIQUE algorithm for processing
432  intervals = 10 # defines amount of cells in grid in each dimension
433  threshold = 0 # lets consider each point as non-outlier
434  clique_instance = clique(data, intervals, threshold)
435 
436  # start clustering process and obtain results
437  clique_instance.process()
438  clusters = clique_instance.get_clusters() # allocated clusters
439  noise = clique_instance.get_noise() # points that are considered as outliers (in this example should be empty)
440  cells = clique_instance.get_cells() # CLIQUE blocks that forms grid
441 
442  print("Amount of clusters:", len(clusters))
443 
444  # visualize clustering results
445  clique_visualizer.show_grid(cells, data) # show grid that has been formed by the algorithm
446  clique_visualizer.show_clusters(data, clusters, noise) # show clustering results
447  @endcode
448 
449  In this example 6 clusters are allocated including four small cluster where each such small cluster consists of
450  three points. There are visualized clustering results - grid that has been formed by CLIQUE algorithm with
451  density and clusters itself:
452  @image html clique_clustering_target.png "Fig. 1. CLIQUE clustering results (grid and clusters itself)."
453 
454  Sometimes such small clusters should be considered as outliers taking into account fact that two clusters in the
455  central are relatively huge. To treat them as a noise threshold value should be increased:
456  @code
457  intervals = 10
458  threshold = 3 # block that contains 3 or less points is considered as a outlier as well as its points
459  clique_instance = clique(data, intervals, threshold)
460  @endcode
461 
462  Two clusters are allocated, but in this case some points in cluster-"circle" are also considered as outliers,
463  because CLIQUE operates with blocks, not with points:
464  @image html clique_clustering_with_noise.png "Fig. 2. Noise allocation by CLIQUE."
465 
466  """
467 
468  def __init__(self, data, amount_intervals, density_threshold, **kwargs):
469  """!
470  @brief Create CLIQUE clustering algorithm.
471 
472  @param[in] data (list): Input data (list of points) that should be clustered.
473  @param[in] amount_intervals (uint): Amount of intervals in each dimension that defines amount of CLIQUE blocks
474  as \f[N_{blocks} = intervals^{dimensions}\f].
475  @param[in] density_threshold (uint): Minimum number of points that should contain CLIQUE block to consider its
476  points as non-outliers.
477  @param[in] **kwargs: Arbitrary keyword arguments (available arguments: 'ccore').
478 
479  <b>Keyword Args:</b><br>
480  - ccore (bool): By default is True. If True then C++ implementation is used for cluster analysis, otherwise
481  Python implementation is used.
482 
483  """
484  self.__data = data
485  self.__amount_intervals = amount_intervals
486  self.__density_threshold = density_threshold
487 
488  self.__ccore = kwargs.get('ccore', True)
489  if self.__ccore:
490  self.__ccore = ccore_library.workable()
491 
492  self.__clusters = []
493  self.__noise = []
494 
495  self.__cells = []
496  self.__cells_map = {}
497 
498  self.__validate_arguments()
499 
500 
501  def process(self):
502  """!
503  @brief Performs clustering process in line with rules of CLIQUE clustering algorithm.
504 
505  @return (clique) Returns itself (CLIQUE instance).
506 
507  @see get_clusters()
508  @see get_noise()
509  @see get_cells()
510 
511  """
512 
513  if self.__ccore:
514  self.__process_by_ccore()
515  else:
516  self.__process_by_python()
517 
518  return self
519 
520 
521  def get_clusters(self):
522  """!
523  @brief Returns allocated clusters.
524 
525  @remark Allocated clusters are returned only after data processing (method process()). Otherwise empty list is returned.
526 
527  @return (list) List of allocated clusters, each cluster contains indexes of objects in list of data.
528 
529  @see process()
530  @see get_noise()
531 
532  """
533  return self.__clusters
534 
535 
536  def get_noise(self):
537  """!
538  @brief Returns allocated noise.
539 
540  @remark Allocated noise is returned only after data processing (method process()). Otherwise empty list is returned.
541 
542  @return (list) List of indexes that are marked as a noise.
543 
544  @see process()
545  @see get_clusters()
546 
547  """
548  return self.__noise
549 
550 
551  def get_cells(self):
552  """!
553  @brief Returns CLIQUE blocks that are formed during clustering process.
554  @details CLIQUE blocks can be used for visualization purposes. Each CLIQUE block contain its logical location
555  in grid, spatial location in data space and points that belong to block.
556 
557  @return (list) List of CLIQUE blocks.
558 
559  """
560  return self.__cells
561 
562 
564  """!
565  @brief Returns clustering result representation type that indicate how clusters are encoded.
566 
567  @return (type_encoding) Clustering result representation.
568 
569  @see get_clusters()
570 
571  """
572 
573  return type_encoding.CLUSTER_INDEX_LIST_SEPARATION
574 
575 
576  def __process_by_ccore(self):
577  """!
578  @brief Performs cluster analysis using C++ implementation of CLIQUE algorithm that is used by default if
579  user's target platform is supported.
580 
581  """
582  result = wrapper.clique(self.__data, self.__amount_intervals, self.__density_threshold)
583 
584  (self.__clusters, self.__noise, block_logical_locations, max_corners, min_corners, block_points) = result
585 
586  amount_cells = len(block_logical_locations)
587  for i in range(amount_cells):
588  self.__cells.append(clique_block(block_logical_locations[i],
589  spatial_block(max_corners[i], min_corners[i]),
590  block_points[i],
591  True))
592 
593 
594  def __process_by_python(self):
595  """!
596  @brief Performs cluster analysis using Python implementation of CLIQUE algorithm.
597 
598  """
599  self.__create_grid()
600  self.__allocate_clusters()
601 
602  self.__cells_map.clear()
603 
604 
605  def __validate_arguments(self):
606  """!
607  @brief Check input arguments of CLIQUE algorithm and if one of them is not correct then appropriate exception
608  is thrown.
609 
610  """
611 
612  if len(self.__data) == 0:
613  raise ValueError("Empty input data. Data should contain at least one point.")
614 
615  if self.__amount_intervals <= 0:
616  raise ValueError("Incorrect amount of intervals '%d'. Amount of intervals value should be greater than 0." % self.__amount_intervals)
617 
618  if self.__density_threshold < 0:
619  raise ValueError("Incorrect density threshold '%f'. Density threshold should not be negative." % self.__density_threshold)
620 
621 
622  def __allocate_clusters(self):
623  """!
624  @brief Performs cluster analysis using formed CLIQUE blocks.
625 
626  """
627  for cell in self.__cells:
628  if cell.visited is False:
629  self.__expand_cluster(cell)
630 
631 
632  def __expand_cluster(self, cell):
633  """!
634  @brief Tries to expand cluster from specified cell.
635  @details During expanding points are marked as noise or append to new cluster.
636 
637  @param[in] cell (clique_block): CLIQUE block from that cluster should be expanded.
638 
639  """
640  cell.visited = True
641 
642  if len(cell.points) <= self.__density_threshold:
643  if len(cell.points) > 0:
644  self.__noise.extend(cell.points)
645 
646  return
647 
648  cluster = cell.points[:]
649  neighbors = self.__get_neighbors(cell)
650 
651  for neighbor in neighbors:
652  if len(neighbor.points) > self.__density_threshold:
653  cluster.extend(neighbor.points)
654  neighbors += self.__get_neighbors(neighbor)
655 
656  elif len(neighbor.points) > 0:
657  self.__noise.extend(neighbor.points)
658 
659  self.__clusters.append(cluster)
660 
661 
662  def __get_neighbors(self, cell):
663  """!
664  @brief Returns neighbors for specified CLIQUE block as clique_block objects.
665 
666  @return (list) Neighbors as clique_block objects.
667 
668  """
669  neighbors = []
670  location_neighbors = cell.get_location_neighbors(self.__amount_intervals)
671 
672  for i in range(len(location_neighbors)):
673  key = self.__location_to_key(location_neighbors[i])
674  candidate_neighbor = self.__cell_map[key]
675 
676  if not candidate_neighbor.visited:
677  candidate_neighbor.visited = True
678  neighbors.append(candidate_neighbor)
679 
680  return neighbors
681 
682 
683  def __create_grid(self):
684  """!
685  @brief Creates CLIQUE grid that consists of CLIQUE blocks for clustering process.
686 
687  """
688  data_sizes, min_corner, max_corner = self.__get_data_size_derscription()
689  dimension = len(self.__data[0])
690 
691  cell_sizes = [dimension_length / self.__amount_intervals for dimension_length in data_sizes]
692 
693  self.__cells = [clique_block() for _ in range(pow(self.__amount_intervals, dimension))]
694  iterator = coordinate_iterator(dimension, self.__amount_intervals)
695 
696  point_availability = [True] * len(self.__data)
697  self.__cell_map = {}
698  for index_cell in range(len(self.__cells)):
699  logical_location = iterator.get_coordinate()
700  iterator.increment()
701 
702  self.__cells[index_cell].logical_location = logical_location[:]
703 
704  cur_max_corner, cur_min_corner = self.__get_spatial_location(logical_location, min_corner, max_corner, cell_sizes)
705  self.__cells[index_cell].spatial_location = spatial_block(cur_max_corner, cur_min_corner)
706 
707  self.__cells[index_cell].capture_points(self.__data, point_availability)
708 
709  self.__cell_map[self.__location_to_key(logical_location)] = self.__cells[index_cell]
710 
711 
712  def __location_to_key(self, location):
713  """!
714  @brief Forms key using logical location of a CLIQUE block.
715 
716  @return (string) Key for CLIQUE block map.
717 
718  """
719  return ''.join(str(e) + '.' for e in location)
720 
721 
722  def __get_spatial_location(self, logical_location, min_corner, max_corner, cell_sizes):
723  """!
724  @brief Calculates spatial location for CLIQUE block with logical coordinates defined by logical_location.
725 
726  @param[in] logical_location (list): Logical location of CLIQUE block for that spatial location should be calculated.
727  @param[in] min_corner (list): Minimum corner of an input data.
728  @param[in] max_corner (list): Maximum corner of an input data.
729  @param[in] cell_sizes (list): Size of CLIQUE block in each dimension.
730 
731  @return (list, list): Maximum and minimum corners for the specified CLIQUE block.
732 
733  """
734  cur_min_corner = min_corner[:]
735  cur_max_corner = min_corner[:]
736  dimension = len(self.__data[0])
737  for index_dimension in range(dimension):
738  cur_min_corner[index_dimension] += cell_sizes[index_dimension] * logical_location[index_dimension]
739 
740  if logical_location[index_dimension] == self.__amount_intervals - 1:
741  cur_max_corner[index_dimension] = max_corner[index_dimension]
742  else:
743  cur_max_corner[index_dimension] = cur_min_corner[index_dimension] + cell_sizes[index_dimension]
744 
745  return cur_max_corner, cur_min_corner
746 
747 
748  def __get_data_size_derscription(self):
749  """!
750  @brief Calculates input data description that is required to create CLIQUE grid.
751 
752  @return (list, list, list): Data size in each dimension, minimum and maximum corners.
753 
754  """
755  min_corner = self.__data[0][:]
756  max_corner = self.__data[0][:]
757 
758  dimension = len(self.__data[0])
759 
760  for index_point in range(1, len(self.__data)):
761  for index_dimension in range(dimension):
762  coordinate = self.__data[index_point][index_dimension]
763  if coordinate > max_corner[index_dimension]:
764  max_corner[index_dimension] = coordinate
765 
766  if coordinate < min_corner[index_dimension]:
767  min_corner[index_dimension] = coordinate
768 
769  data_sizes = [0.0] * dimension
770  for index_dimension in range(dimension):
771  data_sizes[index_dimension] = max_corner[index_dimension] - min_corner[index_dimension]
772 
773  return data_sizes, min_corner, max_corner
pyclustering.cluster.clique.clique_visualizer.show_clusters
def show_clusters(data, clusters, noise=None)
Display CLIQUE clustering results.
Definition: clique.py:70
pyclustering.cluster.clique.clique.__allocate_clusters
def __allocate_clusters(self)
Performs cluster analysis using formed CLIQUE blocks.
Definition: clique.py:622
pyclustering.cluster.clique.spatial_block
Geometrical description of CLIQUE block in data space.
Definition: clique.py:150
pyclustering.cluster.clique.clique_block.__points
__points
Definition: clique.py:227
pyclustering.cluster.clique.spatial_block.__init__
def __init__(self, max_corner, min_corner)
Creates spatial block in data space.
Definition: clique.py:159
pyclustering.cluster.clique.coordinate_iterator.__coordiate
__coordiate
Definition: clique.py:388
pyclustering.cluster.clique.clique.__amount_intervals
__amount_intervals
Definition: clique.py:485
pyclustering.cluster.clique.clique.__clusters
__clusters
Definition: clique.py:492
pyclustering.cluster.clique.coordinate_iterator
Coordinate iterator is used to generate logical location description for each CLIQUE block.
Definition: clique.py:371
pyclustering.cluster.clique.clique.get_noise
def get_noise(self)
Returns allocated noise.
Definition: clique.py:536
pyclustering.cluster.clique.spatial_block.__max_corner
__max_corner
Definition: clique.py:167
pyclustering.cluster.cluster_visualizer
Common visualizer of clusters on 1D, 2D or 3D surface.
Definition: __init__.py:370
pyclustering.cluster.clique.coordinate_iterator.get_coordinate
def get_coordinate(self)
Returns current block coordinate.
Definition: clique.py:391
pyclustering.cluster.clique.clique_block.points
def points(self)
Points that belong to the CLIQUE block.
Definition: clique.py:293
pyclustering.cluster.clique.clique.__cells_map
__cells_map
Definition: clique.py:496
pyclustering.cluster.clique.spatial_block.__contains__
def __contains__(self, point)
Point is considered as contained if it lies in block (belong to it).
Definition: clique.py:181
pyclustering.cluster.clique.spatial_block.get_corners
def get_corners(self)
Return spatial description of current block.
Definition: clique.py:195
pyclustering.cluster.clique.clique_visualizer
Visualizer of CLIQUE algorithm's results.
Definition: clique.py:28
pyclustering.cluster.clique.clique.get_clusters
def get_clusters(self)
Returns allocated clusters.
Definition: clique.py:521
pyclustering.cluster.clique.clique_block.__logical_location
__logical_location
Definition: clique.py:225
pyclustering.cluster.clique.clique.__get_neighbors
def __get_neighbors(self, cell)
Returns neighbors for specified CLIQUE block as clique_block objects.
Definition: clique.py:662
pyclustering.cluster.clique.clique_block.get_location_neighbors
def get_location_neighbors(self, edge)
Forms list of logical location of each neighbor for this particular CLIQUE block.
Definition: clique.py:345
pyclustering.cluster.clique.clique.__process_by_python
def __process_by_python(self)
Performs cluster analysis using Python implementation of CLIQUE algorithm.
Definition: clique.py:594
pyclustering.cluster.clique.clique.__process_by_ccore
def __process_by_ccore(self)
Performs cluster analysis using C++ implementation of CLIQUE algorithm that is used by default if use...
Definition: clique.py:576
pyclustering.cluster.clique.clique_block.capture_points
def capture_points(self, data, point_availability)
Finds points that belong to this block using availability map to reduce computational complexity by c...
Definition: clique.py:328
pyclustering.cluster.clique.clique_block.spatial_location
def spatial_location(self)
Spatial location is represented by real data space coordinates.
Definition: clique.py:265
pyclustering.cluster.clique.coordinate_iterator.increment
def increment(self)
Forms logical location for next block.
Definition: clique.py:399
pyclustering.cluster
pyclustering module for cluster analysis.
Definition: __init__.py:1
pyclustering.cluster.clique.clique_block.__repr__
def __repr__(self)
Returns string representation of the block using its logical location in CLIQUE grid.
Definition: clique.py:237
pyclustering.cluster.clique.clique.__noise
__noise
Definition: clique.py:493
pyclustering.cluster.clique.clique.__density_threshold
__density_threshold
Definition: clique.py:486
pyclustering.cluster.clique.clique_visualizer.show_grid
def show_grid(cells, data)
Show CLIQUE blocks as a grid in data space.
Definition: clique.py:39
pyclustering.cluster.clique.clique_block.visited
def visited(self)
Defines whether block is visited during cluster analysis.
Definition: clique.py:306
pyclustering.cluster.clique.clique.__expand_cluster
def __expand_cluster(self, cell)
Tries to expand cluster from specified cell.
Definition: clique.py:632
pyclustering.cluster.clique.clique_block
CLIQUE block contains information about its logical location in grid, spatial location in data space ...
Definition: clique.py:206
pyclustering.cluster.clique.clique.__data
__data
Definition: clique.py:484
pyclustering.cluster.clique.clique_block.dimensions
def dimensions(self)
Amount of dimensions where CLIQUE block is located.
Definition: clique.py:284
pyclustering.cluster.clique.coordinate_iterator.__init__
def __init__(self, dimension, intervals)
Initializes coordinate iterator for CLIQUE algorithm.
Definition: clique.py:378
pyclustering.cluster.clique.clique.__get_spatial_location
def __get_spatial_location(self, logical_location, min_corner, max_corner, cell_sizes)
Calculates spatial location for CLIQUE block with logical coordinates defined by logical_location.
Definition: clique.py:722
pyclustering.cluster.clique.clique.__ccore
__ccore
Definition: clique.py:488
pyclustering.cluster.clique.clique
Class implements CLIQUE grid based clustering algorithm.
Definition: clique.py:415
pyclustering.cluster.clique.clique.__cell_map
__cell_map
Definition: clique.py:697
pyclustering.cluster.clique.clique_block.__init__
def __init__(self, logical_location=None, spatial_location=None, points=None, visited=False)
Initializes CLIQUE block.
Definition: clique.py:213
pyclustering.cluster.clique.clique_block.__spatial_location
__spatial_location
Definition: clique.py:226
pyclustering.cluster.clique.clique_block.logical_location
def logical_location(self)
Logical location is represented by coordinates in CLIQUE grid, for example, in case of 2x2 grid block...
Definition: clique.py:245
pyclustering.cluster.clique.clique.__validate_arguments
def __validate_arguments(self)
Check input arguments of CLIQUE algorithm and if one of them is not correct then appropriate exceptio...
Definition: clique.py:605
pyclustering.cluster.clique.clique.get_cells
def get_cells(self)
Returns CLIQUE blocks that are formed during clustering process.
Definition: clique.py:551
pyclustering.cluster.clique.clique.get_cluster_encoding
def get_cluster_encoding(self)
Returns clustering result representation type that indicate how clusters are encoded.
Definition: clique.py:563
pyclustering.cluster.clique.coordinate_iterator.__dimension
__dimension
Definition: clique.py:387
pyclustering.cluster.clique.clique.__init__
def __init__(self, data, amount_intervals, density_threshold, **kwargs)
Create CLIQUE clustering algorithm.
Definition: clique.py:468
pyclustering.cluster.clique.clique.__cells
__cells
Definition: clique.py:495
pyclustering.cluster.clique.spatial_block.__min_corner
__min_corner
Definition: clique.py:168
pyclustering.cluster.clique.clique_block.__str__
def __str__(self)
Returns string representation of the block using its logical location in CLIQUE grid.
Definition: clique.py:230
pyclustering.cluster.clique.clique_block.__visited
__visited
Definition: clique.py:228
pyclustering.cluster.clique.coordinate_iterator.__intervals
__intervals
Definition: clique.py:386
pyclustering.cluster.clique.clique.__create_grid
def __create_grid(self)
Creates CLIQUE grid that consists of CLIQUE blocks for clustering process.
Definition: clique.py:683
pyclustering.cluster.clique.clique.__location_to_key
def __location_to_key(self, location)
Forms key using logical location of a CLIQUE block.
Definition: clique.py:712
pyclustering.cluster.clique.clique.__get_data_size_derscription
def __get_data_size_derscription(self)
Calculates input data description that is required to create CLIQUE grid.
Definition: clique.py:748
pyclustering.cluster.encoder
Module for representing clustering results.
Definition: encoder.py:1
pyclustering.cluster.clique.clique.process
def process(self)
Performs clustering process in line with rules of CLIQUE clustering algorithm.
Definition: clique.py:501
pyclustering.cluster.clique.spatial_block.__str__
def __str__(self)
Returns string block description.
Definition: clique.py:171