class_docstr: !
  @brief Class implements G-Means clustering algorithm.
  @details The G-means algorithm starts with a small number of centers, and grows the number of centers.
            Each iteration of the G-Means algorithm splits into two those centers whose data appear not to come from a
            Gaussian distribution. G-means repeatedly makes decisions based on a statistical test for the data
            assigned to each center.
  
  Implementation based on the paper @cite inproceedings::cluster::gmeans::1.
  
  @image html gmeans_example_clustering.png "G-Means clustering results on most common data-sets."
  
  Example #1. In this example, G-Means starts analysis from single cluster.
  @code
      from pyclustering.cluster import cluster_visualizer
      from pyclustering.cluster.gmeans import gmeans
      from pyclustering.utils import read_sample
      from pyclustering.samples.definitions import FCPS_SAMPLES
  
      # Read sample 'Lsun' from file.
      sample = read_sample(FCPS_SAMPLES.SAMPLE_LSUN)
  
      # Create instance of G-Means algorithm. By default the algorithm starts search from a single cluster.
      gmeans_instance = gmeans(sample).process()
  
      # Extract clustering results: clusters and their centers
      clusters = gmeans_instance.get_clusters()
      centers = gmeans_instance.get_centers()
  
      # Print total sum of metric errors
      print("Total WCE:", gmeans_instance.get_total_wce())
  
      # Visualize clustering results
      visualizer = cluster_visualizer()
      visualizer.append_clusters(clusters, sample)
      visualizer.show()
  @endcode
  
  Example #2. Sometimes G-Means might find local optimum. `repeat` value can be used to increase probability to
  find global optimum. Argument `repeat` defines how many times K-Means clustering with K-Means++
  initialization should be run in order to find optimal clusters.
  @code
      # Read sample 'Tetra' from file.
      sample = read_sample(FCPS_SAMPLES.SAMPLE_TETRA)
  
      # Create instance of G-Means algorithm. By default algorithm start search from single cluster.
      gmeans_instance = gmeans(sample, repeat=10).process()
  
      # Extract clustering results: clusters and their centers
      clusters = gmeans_instance.get_clusters()
  
      # Visualize clustering results
      visualizer = cluster_visualizer()
      visualizer.append_clusters(clusters, sample)
      visualizer.show()
  @endcode
  
  In case of requirement to have labels instead of default representation of clustering results `CLUSTER_INDEX_LIST_SEPARATION`:
  @code
      from pyclustering.cluster.gmeans import gmeans
      from pyclustering.cluster.encoder import type_encoding, cluster_encoder
      from pyclustering.samples.definitions import SIMPLE_SAMPLES
      from pyclustering.utils import read_sample
  
      data = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1)
  
      gmeans_instance = gmeans(data).process()
      clusters = gmeans_instance.get_clusters()
  
      # Change cluster representation from default to labeling.
      encoder = cluster_encoder(type_encoding.CLUSTER_INDEX_LIST_SEPARATION, clusters, data)
      encoder.set_encoding(type_encoding.CLUSTER_INDEX_LABELING)
      labels = encoder.get_clusters()
  
      print(labels)   # Display labels
  @endcode
  
  There is an output of the code above:
  @code
      [0, 0, 0, 0, 0, 1, 1, 1, 1, 1]
  @endcode
class_docstr_tok: ["!","@","brief","Class","implements","G-Means","clustering","algorithm",".","@","details","The","G-means","algorithm","starts","with","a","small","number","of","centers",",","and","grows","the","number","of","centers",".","Each","iteration","of","the","G-Means","algorithm","splits","into","two","those","centers","whose","data","appear","not","to","come","from","a","Gaussian","distribution",".","G-means","repeatedly","makes","decisions","based","on","a","statistical","test","for","the","data","assigned","to","each","center",".","Implementation","based","on","the","paper","@","cite","inproceedings",":",":cluster",":",":gmeans",":",":1",".","@","image","html","gmeans_example_clustering.png","``","G-Means","clustering","results","on","most","common","data-sets",".","''","Example","#","1",".","In","this","example",",","G-Means","starts","analysis","from","single","cluster",".","@","code","from","pyclustering.cluster","import","cluster_visualizer","from","pyclustering.cluster.gmeans","import","gmeans","from","pyclustering.utils","import","read_sample","from","pyclustering.samples.definitions","import","FCPS_SAMPLES","#","Read","sample","'Lsun","'","from","file",".","sample","=","read_sample","(","FCPS_SAMPLES.SAMPLE_LSUN",")","#","Create","instance","of","G-Means","algorithm",".","By","default","the","algorithm","starts","search","from","a","single","cluster",".","gmeans_instance","=","gmeans","(","sample",")",".process","(",")","#","Extract","clustering","results",":","clusters","and","their","centers","clusters","=","gmeans_instance.get_clusters","(",")","centers","=","gmeans_instance.get_centers","(",")","#","Print","total","sum","of","metric","errors","print","(","``","Total","WCE",":","''",",","gmeans_instance.get_total_wce","(",")",")","#","Visualize","clustering","results","visualizer","=","cluster_visualizer","(",")","visualizer.append_clusters","(","clusters",",","sample",")","visualizer.show","(",")","@","endcode","Example","#","2",".","Sometimes","G-Means","might","find","local","optimum",".","`","repeat","`","value","can","be","used","to","increase","probability","to","find","global","optimum",".","Argument","`","repeat","`","defines","how","many","times","K-Means","clustering","with","K-Means++","initialization","should","be","run","in","order","to","find","optimal","clusters",".","@","code","#","Read","sample","'Tetra","'","from","file",".","sample","=","read_sample","(","FCPS_SAMPLES.SAMPLE_TETRA",")","#","Create","instance","of","G-Means","algorithm",".","By","default","algorithm","start","search","from","single","cluster",".","gmeans_instance","=","gmeans","(","sample",",","repeat=10",")",".process","(",")","#","Extract","clustering","results",":","clusters","and","their","centers","clusters","=","gmeans_instance.get_clusters","(",")","#","Visualize","clustering","results","visualizer","=","cluster_visualizer","(",")","visualizer.append_clusters","(","clusters",",","sample",")","visualizer.show","(",")","@","endcode","In","case","of","requirement","to","have","labels","instead","of","default","representation","of","clustering","results","`","CLUSTER_INDEX_LIST_SEPARATION","`",":","@","code","from","pyclustering.cluster.gmeans","import","gmeans","from","pyclustering.cluster.encoder","import","type_encoding",",","cluster_encoder","from","pyclustering.samples.definitions","import","SIMPLE_SAMPLES","from","pyclustering.utils","import","read_sample","data","=","read_sample","(","SIMPLE_SAMPLES.SAMPLE_SIMPLE1",")","gmeans_instance","=","gmeans","(","data",")",".process","(",")","clusters","=","gmeans_instance.get_clusters","(",")","#","Change","cluster","representation","from","default","to","labeling",".","encoder","=","cluster_encoder","(","type_encoding.CLUSTER_INDEX_LIST_SEPARATION",",","clusters",",","data",")","encoder.set_encoding","(","type_encoding.CLUSTER_INDEX_LABELING",")","labels","=","encoder.get_clusters","(",")","print","(","labels",")","#","Display","labels","@","endcode","There","is","an","output","of","the","code","above",":","@","code","[","0",",","0",",","0",",","0",",","0",",","1",",","1",",","1",",","1",",","1","]","@","endcode"]
docstr: !
  @brief Initializes G-Means algorithm.
  
  @param[in] data (array_like): Input data that is presented as array of points (objects), each point should be
              represented by array_like data structure.
  @param[in] k_init (uint): Initial amount of centers (by default started search from 1).
  @param[in] ccore (bool): Defines whether CCORE library (C/C++ part of the library) should be used instead of
              Python code.
  @param[in] **kwargs: Arbitrary keyword arguments (available arguments: `tolerance`, `repeat`, `k_max`, `random_state`).
  
  <b>Keyword Args:</b><br>
      - tolerance (double): tolerance (double): Stop condition for each K-Means iteration: if maximum value of
         change of centers of clusters is less than tolerance than algorithm will stop processing.
      - repeat (unit): How many times K-Means should be run to improve parameters (by default is 3).
         With larger 'repeat' values suggesting higher probability of finding global optimum.
      - k_max (uint): Maximum amount of cluster that might be allocated. The argument is considered as a stop
         condition. When the maximum amount is reached then algorithm stops processing. By default the maximum
         amount of clusters is not restricted (`k_max` is -1).
      - random_state (int): Seed for random state (by default is `None`, current system time is used).
docstr_tok: ["!","@","brief","Initializes","G-Means","algorithm",".","@","param","[","in","]","data","(","array_like",")",":","Input","data","that","is","presented","as","array","of","points","(","objects",")",",","each","point","should","be","represented","by","array_like","data","structure",".","@","param","[","in","]","k_init","(","uint",")",":","Initial","amount","of","centers","(","by","default","started","search","from","1",")",".","@","param","[","in","]","ccore","(","bool",")",":","Defines","whether","CCORE","library","(","C\/C++","part","of","the","library",")","should","be","used","instead","of","Python","code",".","@","param","[","in","]","*","*","kwargs",":","Arbitrary","keyword","arguments","(","available","arguments",":","`","tolerance","`",",","`","repeat","`",",","`","k_max","`",",","`","random_state","`",")",".","<","b",">","Keyword","Args",":","<","\/b",">","<","br",">","-","tolerance","(","double",")",":","tolerance","(","double",")",":","Stop","condition","for","each","K-Means","iteration",":","if","maximum","value","of","change","of","centers","of","clusters","is","less","than","tolerance","than","algorithm","will","stop","processing",".","-","repeat","(","unit",")",":","How","many","times","K-Means","should","be","run","to","improve","parameters","(","by","default","is","3",")",".","With","larger","'repeat","'","values","suggesting","higher","probability","of","finding","global","optimum",".","-","k_max","(","uint",")",":","Maximum","amount","of","cluster","that","might","be","allocated",".","The","argument","is","considered","as","a","stop","condition",".","When","the","maximum","amount","is","reached","then","algorithm","stops","processing",".","By","default","the","maximum","amount","of","clusters","is","not","restricted","(","`","k_max","`","is","-1",")",".","-","random_state","(","int",")",":","Seed","for","random","state","(","by","default","is","`","None","`",",","current","system","time","is","used",")","."]
code: def __init__(self, data, k_init=1, ccore=True, **kwargs):
      """!
      @brief Initializes G-Means algorithm.
  
      @param[in] data (array_like): Input data that is presented as array of points (objects), each point should be
                  represented by array_like data structure.
      @param[in] k_init (uint): Initial amount of centers (by default started search from 1).
      @param[in] ccore (bool): Defines whether CCORE library (C/C++ part of the library) should be used instead of
                  Python code.
      @param[in] **kwargs: Arbitrary keyword arguments (available arguments: `tolerance`, `repeat`, `k_max`, `random_state`).
  
      <b>Keyword Args:</b><br>
          - tolerance (double): tolerance (double): Stop condition for each K-Means iteration: if maximum value of
             change of centers of clusters is less than tolerance than algorithm will stop processing.
          - repeat (unit): How many times K-Means should be run to improve parameters (by default is 3).
             With larger 'repeat' values suggesting higher probability of finding global optimum.
          - k_max (uint): Maximum amount of cluster that might be allocated. The argument is considered as a stop
             condition. When the maximum amount is reached then algorithm stops processing. By default the maximum
             amount of clusters is not restricted (`k_max` is -1).
          - random_state (int): Seed for random state (by default is `None`, current system time is used).
  
      """
      self.__data = data
      self.__k_init = k_init
  
      self.__clusters = []
      self.__centers = []
      self.__total_wce = 0.0
      self.__ccore = ccore
  
      self.__tolerance = kwargs.get("tolerance", 0.001)
      self.__repeat = kwargs.get("repeat", 3)
      self.__k_max = kwargs.get("k_max", -1)
      self.__random_state = kwargs.get("random_state", None)
  
      if self.__ccore is True:
          self.__ccore = ccore_library.workable()
  
      self._verify_arguments()
  
imports: import numpy
  import scipy.stats
  from pyclustering.core.gmeans_wrapper import gmeans
  from pyclustering.core.wrapper import ccore_library
  from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer
  from pyclustering.cluster.encoder import type_encoding
  from pyclustering.cluster.kmeans import kmeans
  from pyclustering.utils import distance_metric, type_metric
label_desc: Use image node_id 1 to create a new gmeans object  with example: obj = gmeans(data, k_init, ccore)