class_docstr: !
  @brief Class represents clustering algorithm CURE with KD-tree optimization.
  @details CCORE option can be used to use the pyclustering core - C/C++ shared library for processing that significantly increases performance.
  
  Here is an example how to perform cluster analysis of sample 'Lsun':
  @code
      from pyclustering.cluster import cluster_visualizer;
      from pyclustering.cluster.cure import cure;
      from pyclustering.utils import read_sample;
      from pyclustering.samples.definitions import FCPS_SAMPLES;
  
      # Input data in following format [ [0.1, 0.5], [0.3, 0.1], ... ].
      input_data = read_sample(FCPS_SAMPLES.SAMPLE_LSUN);
  
      # Allocate three clusters.
      cure_instance = cure(input_data, 3);
      cure_instance.process();
      clusters = cure_instance.get_clusters();
  
      # Visualize allocated clusters.
      visualizer = cluster_visualizer();
      visualizer.append_clusters(clusters, input_data);
      visualizer.show();
  @endcode
class_docstr_tok: ["!","@","brief","Class","represents","clustering","algorithm","CURE","with","KD-tree","optimization",".","@","details","CCORE","option","can","be","used","to","use","the","pyclustering","core","-","C\/C++","shared","library","for","processing","that","significantly","increases","performance",".","Here","is","an","example","how","to","perform","cluster","analysis","of","sample","'Lsun","'",":","@","code","from","pyclustering.cluster","import","cluster_visualizer",";","from","pyclustering.cluster.cure","import","cure",";","from","pyclustering.utils","import","read_sample",";","from","pyclustering.samples.definitions","import","FCPS_SAMPLES",";","#","Input","data","in","following","format","[","[","0.1",",","0.5","]",",","[","0.3",",","0.1","]",",","...","]",".","input_data","=","read_sample","(","FCPS_SAMPLES.SAMPLE_LSUN",")",";","#","Allocate","three","clusters",".","cure_instance","=","cure","(","input_data",",","3",")",";","cure_instance.process","(",")",";","clusters","=","cure_instance.get_clusters","(",")",";","#","Visualize","allocated","clusters",".","visualizer","=","cluster_visualizer","(",")",";","visualizer.append_clusters","(","clusters",",","input_data",")",";","visualizer.show","(",")",";","@","endcode"]
docstr: !
  @brief Performs cluster analysis using python code.
docstr_tok: ["!","@","brief","Performs","cluster","analysis","using","python","code","."]
code: def __process_by_python(self):
      """!
      @brief Performs cluster analysis using python code.
  
      """
      self.__create_queue()  # queue
      self.__create_kdtree()  # create k-d tree
  
      while len(self.__queue) > self.__number_cluster:
          cluster1 = self.__queue[
              0
          ]  # cluster that has nearest neighbor.
          cluster2 = cluster1.closest  # closest cluster.
  
          self.__queue.remove(cluster1)
          self.__queue.remove(cluster2)
  
          self.__delete_represented_points(cluster1)
          self.__delete_represented_points(cluster2)
  
          merged_cluster = self.__merge_clusters(cluster1, cluster2)
  
          self.__insert_represented_points(merged_cluster)
  
          # Pointers to clusters that should be relocated is stored here.
          cluster_relocation_requests = []
  
          # Check for the last cluster
          if len(self.__queue) > 0:
              merged_cluster.closest = self.__queue[
                  0
              ]  # arbitrary cluster from queue
              merged_cluster.distance = self.__cluster_distance(
                  merged_cluster, merged_cluster.closest
              )
  
              for item in self.__queue:
                  distance = self.__cluster_distance(
                      merged_cluster, item
                  )
                  # Check if distance between new cluster and current is the best than now.
                  if distance < merged_cluster.distance:
                      merged_cluster.closest = item
                      merged_cluster.distance = distance
  
                  # Check if current cluster has removed neighbor.
                  if (item.closest is cluster1) or (
                      item.closest is cluster2
                  ):
                      # If previous distance was less then distance to new cluster then nearest cluster should
                      # be found in the tree.
                      if item.distance < distance:
                          (
                              item.closest,
                              item.distance,
                          ) = self.__closest_cluster(item, distance)
  
                          # TODO: investigation is required. There is assumption that itself and merged cluster
                          # should be always in list of neighbors in line with specified radius. But merged cluster
                          # may not be in list due to error calculation, therefore it should be added manually.
                          if item.closest is None:
                              item.closest = merged_cluster
                              item.distance = distance
  
                      else:
                          item.closest = merged_cluster
                          item.distance = distance
  
                      cluster_relocation_requests.append(item)
  
          # New cluster and updated clusters should relocated in queue
          self.__insert_cluster(merged_cluster)
          for item in cluster_relocation_requests:
              self.__relocate_cluster(item)
  
      # Change cluster representation
      self.__clusters = [
          cure_cluster_unit.indexes
          for cure_cluster_unit in self.__queue
      ]
      self.__representors = [
          cure_cluster_unit.rep for cure_cluster_unit in self.__queue
      ]
      self.__means = [
          cure_cluster_unit.mean for cure_cluster_unit in self.__queue
      ]
  
imports: import numpy
  from pyclustering.cluster.encoder import type_encoding
  from pyclustering.utils import euclidean_distance_square
  from pyclustering.container.kdtree import kdtree
  from pyclustering.core.wrapper import ccore_library
  import pyclustering.core.cure_wrapper
label_desc: Use image node_id 4 for calling the cure obj's underlying member method code with example usage: obj.__process_by_python() without return types