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 Merges two clusters and returns new merged cluster. Representation points and mean points are calculated for the new cluster.
  
  @param[in] cluster1 (cure_cluster): Cluster that should be merged.
  @param[in] cluster2 (cure_cluster): Cluster that should be merged.
  
  @return (cure_cluster) New merged CURE cluster.
docstr_tok: ["!","@","brief","Merges","two","clusters","and","returns","new","merged","cluster",".","Representation","points","and","mean","points","are","calculated","for","the","new","cluster",".","@","param","[","in","]","cluster1","(","cure_cluster",")",":","Cluster","that","should","be","merged",".","@","param","[","in","]","cluster2","(","cure_cluster",")",":","Cluster","that","should","be","merged",".","@","return","(","cure_cluster",")","New","merged","CURE","cluster","."]
code: def __merge_clusters(self, cluster1, cluster2):
      """!
      @brief Merges two clusters and returns new merged cluster. Representation points and mean points are calculated for the new cluster.
  
      @param[in] cluster1 (cure_cluster): Cluster that should be merged.
      @param[in] cluster2 (cure_cluster): Cluster that should be merged.
  
      @return (cure_cluster) New merged CURE cluster.
  
      """
  
      merged_cluster = cure_cluster(None, None)
  
      merged_cluster.points = cluster1.points + cluster2.points
      merged_cluster.indexes = cluster1.indexes + cluster2.indexes
  
      # merged_cluster.mean = ( len(cluster1.points) * cluster1.mean + len(cluster2.points) * cluster2.mean ) / ( len(cluster1.points) + len(cluster2.points) );
      dimension = len(cluster1.mean)
      merged_cluster.mean = [0] * dimension
      if merged_cluster.points[1:] == merged_cluster.points[:-1]:
          merged_cluster.mean = merged_cluster.points[0]
      else:
          for index in range(dimension):
              merged_cluster.mean[index] = (
                  len(cluster1.points) * cluster1.mean[index]
                  + len(cluster2.points) * cluster2.mean[index]
              ) / (len(cluster1.points) + len(cluster2.points))
  
      temporary = list()
  
      for index in range(self.__number_represent_points):
          maximal_distance = 0
          maximal_point = None
  
          for point in merged_cluster.points:
              minimal_distance = 0
              if index == 0:
                  minimal_distance = euclidean_distance_square(
                      point, merged_cluster.mean
                  )
                  # minimal_distance = euclidean_distance_sqrt(point, merged_cluster.mean);
              else:
                  minimal_distance = min(
                      [
                          euclidean_distance_square(point, p)
                          for p in temporary
                      ]
                  )
                  # minimal_distance = cluster_distance(cure_cluster(point), cure_cluster(temporary[0]));
  
              if minimal_distance >= maximal_distance:
                  maximal_distance = minimal_distance
                  maximal_point = point
  
          if maximal_point not in temporary:
              temporary.append(maximal_point)
  
      for point in temporary:
          representative_point = [0] * dimension
          for index in range(dimension):
              representative_point[index] = point[
                  index
              ] + self.__compression * (
                  merged_cluster.mean[index] - point[index]
              )
  
          merged_cluster.rep.append(representative_point)
  
      return merged_cluster
  
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 16 for calling the cure obj's underlying member method code with example usage: obj.__merge_clusters(cluster1, cluster2) and returns: merged_cluster