class_docstr: !
  @brief Class represents agglomerative algorithm for cluster analysis.
  @details Agglomerative algorithm considers each data point (object) as a separate cluster at the beginning and
            step by step finds the best pair of clusters for merge until required amount of clusters is obtained.
  
  Example of agglomerative algorithm where centroid link is used:
  @code
      from pyclustering.cluster.agglomerative import agglomerative, type_link
      from pyclustering.cluster import cluster_visualizer
      from pyclustering.samples.definitions import FCPS_SAMPLES
      from pyclustering.utils import read_sample
  
      # Sample for cluster analysis (represented by list)
      sample = read_sample(FCPS_SAMPLES.SAMPLE_TARGET)
  
      # Create object that uses python code only
      agglomerative_instance = agglomerative(sample, 6, type_link.SINGLE_LINK, ccore=True)
  
      # Cluster analysis
      agglomerative_instance.process()
  
      # Obtain results of clustering
      clusters = agglomerative_instance.get_clusters()
  
      # Visualize clustering results
      visualizer = cluster_visualizer()
      visualizer.append_clusters(clusters, sample)
      visualizer.show()
  @endcode
  
  There is example of clustering 'LSUN' sample:
  @code
      from pyclustering.cluster.agglomerative import agglomerative, type_link
      from pyclustering.cluster import cluster_visualizer
      from pyclustering.samples.definitions import FCPS_SAMPLES
      from pyclustering.utils import read_sample
  
      # sample Lsun for cluster analysis
      lsun_sample = read_sample(FCPS_SAMPLES.SAMPLE_LSUN)
  
      # create instance of the algorithm that will use ccore library (the last argument)
      agglomerative_instance = agglomerative(lsun_sample, 3, type_link.SINGLE_LINK, True)
  
      # start processing
      agglomerative_instance.process()
  
      # get result and visualize it
      lsun_clusters = agglomerative_instance.get_clusters()
      visualizer = cluster_visualizer()
      visualizer.append_clusters(lsun_clusters, lsun_sample)
      visualizer.show()
  @endcode
  
  Example of agglomerative clustering using different links:
  @image html agglomerative_lsun_clustering_single_link.png
class_docstr_tok: ["!","@","brief","Class","represents","agglomerative","algorithm","for","cluster","analysis",".","@","details","Agglomerative","algorithm","considers","each","data","point","(","object",")","as","a","separate","cluster","at","the","beginning","and","step","by","step","finds","the","best","pair","of","clusters","for","merge","until","required","amount","of","clusters","is","obtained",".","Example","of","agglomerative","algorithm","where","centroid","link","is","used",":","@","code","from","pyclustering.cluster.agglomerative","import","agglomerative",",","type_link","from","pyclustering.cluster","import","cluster_visualizer","from","pyclustering.samples.definitions","import","FCPS_SAMPLES","from","pyclustering.utils","import","read_sample","#","Sample","for","cluster","analysis","(","represented","by","list",")","sample","=","read_sample","(","FCPS_SAMPLES.SAMPLE_TARGET",")","#","Create","object","that","uses","python","code","only","agglomerative_instance","=","agglomerative","(","sample",",","6",",","type_link.SINGLE_LINK",",","ccore=True",")","#","Cluster","analysis","agglomerative_instance.process","(",")","#","Obtain","results","of","clustering","clusters","=","agglomerative_instance.get_clusters","(",")","#","Visualize","clustering","results","visualizer","=","cluster_visualizer","(",")","visualizer.append_clusters","(","clusters",",","sample",")","visualizer.show","(",")","@","endcode","There","is","example","of","clustering","'LSUN","'","sample",":","@","code","from","pyclustering.cluster.agglomerative","import","agglomerative",",","type_link","from","pyclustering.cluster","import","cluster_visualizer","from","pyclustering.samples.definitions","import","FCPS_SAMPLES","from","pyclustering.utils","import","read_sample","#","sample","Lsun","for","cluster","analysis","lsun_sample","=","read_sample","(","FCPS_SAMPLES.SAMPLE_LSUN",")","#","create","instance","of","the","algorithm","that","will","use","ccore","library","(","the","last","argument",")","agglomerative_instance","=","agglomerative","(","lsun_sample",",","3",",","type_link.SINGLE_LINK",",","True",")","#","start","processing","agglomerative_instance.process","(",")","#","get","result","and","visualize","it","lsun_clusters","=","agglomerative_instance.get_clusters","(",")","visualizer","=","cluster_visualizer","(",")","visualizer.append_clusters","(","lsun_clusters",",","lsun_sample",")","visualizer.show","(",")","@","endcode","Example","of","agglomerative","clustering","using","different","links",":","@","image","html","agglomerative_lsun_clustering_single_link.png"]
docstr: !
  @brief Merges the most similar clusters in line with centroid link type.
docstr_tok: ["!","@","brief","Merges","the","most","similar","clusters","in","line","with","centroid","link","type","."]
code: def __merge_by_centroid_link(self):
      """!
      @brief Merges the most similar clusters in line with centroid link type.
  
      """
  
      minimum_centroid_distance = float("Inf")
      indexes = None
  
      for index1 in range(0, len(self.__centers)):
          for index2 in range(index1 + 1, len(self.__centers)):
              distance = euclidean_distance_square(
                  self.__centers[index1], self.__centers[index2]
              )
              if distance < minimum_centroid_distance:
                  minimum_centroid_distance = distance
                  indexes = [index1, index2]
  
      self.__clusters[indexes[0]] += self.__clusters[indexes[1]]
      self.__centers[indexes[0]] = self.__calculate_center(
          self.__clusters[indexes[0]]
      )
  
      self.__clusters.pop(indexes[1])  # remove merged cluster.
      self.__centers.pop(indexes[1])
  
imports: from enum import IntEnum
  from pyclustering.cluster.encoder import type_encoding
  from pyclustering.utils import euclidean_distance_square
  from pyclustering.core.wrapper import ccore_library
  import pyclustering.core.agglomerative_wrapper
label_desc: Use image node_id 7 for calling the agglomerative obj's underlying member method code with example usage: obj.__merge_by_centroid_link() without return types