class_docstr: !
  @brief Class represents clustering algorithm X-Means.
  @details X-means clustering method starts with the assumption of having a minimum number of clusters, 
           and then dynamically increases them. X-means uses specified splitting criterion to control 
           the process of splitting clusters. Method K-Means++ can be used for calculation of initial centers.
           
           CCORE implementation of the algorithm uses thread pool to parallelize the clustering process.
  
  Here example how to perform cluster analysis using X-Means algorithm:
  @code
      from pyclustering.cluster import cluster_visualizer
      from pyclustering.cluster.xmeans import xmeans
      from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer
      from pyclustering.utils import read_sample
      from pyclustering.samples.definitions import SIMPLE_SAMPLES
  
      # Read sample 'simple3' from file.
      sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
  
      # Prepare initial centers - amount of initial centers defines amount of clusters from which X-Means will
      # start analysis.
      amount_initial_centers = 2
      initial_centers = kmeans_plusplus_initializer(sample, amount_initial_centers).initialize()
  
      # Create instance of X-Means algorithm. The algorithm will start analysis from 2 clusters, the maximum
      # number of clusters that can be allocated is 20.
      xmeans_instance = xmeans(sample, initial_centers, 20)
      xmeans_instance.process()
  
      # Extract clustering results: clusters and their centers
      clusters = xmeans_instance.get_clusters()
      centers = xmeans_instance.get_centers()
  
      # Print total sum of metric errors
      print("Total WCE:", xmeans_instance.get_total_wce())
  
      # Visualize clustering results
      visualizer = cluster_visualizer()
      visualizer.append_clusters(clusters, sample)
      visualizer.append_cluster(centers, None, marker='*', markersize=10)
      visualizer.show()
  @endcode
  
  Visualization of clustering results that were obtained using code above and where X-Means algorithm allocates four clusters.
  @image html xmeans_clustering_simple3.png "Fig. 1. X-Means clustering results (data 'Simple3')."
  
  By default X-Means clustering algorithm uses Bayesian Information Criterion (BIC) to approximate the correct number
  of clusters. There is an example where another criterion Minimum Noiseless Description Length (MNDL) is used in order
  to find optimal amount of clusters:
  @code
      from pyclustering.cluster import cluster_visualizer
      from pyclustering.cluster.xmeans import xmeans, splitting_type
      from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer
      from pyclustering.utils import read_sample
      from pyclustering.samples.definitions import FCPS_SAMPLES
  
      # Read sample 'Target'.
      sample = read_sample(FCPS_SAMPLES.SAMPLE_TARGET)
  
      # Prepare initial centers - amount of initial centers defines amount of clusters from which X-Means will start analysis.
      random_seed = 1000
      amount_initial_centers = 3
      initial_centers = kmeans_plusplus_initializer(sample, amount_initial_centers, random_state=random_seed).initialize()
  
      # Create instance of X-Means algorithm with MNDL splitting criterion.
      xmeans_mndl = xmeans(sample, initial_centers, 20, splitting_type=splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH, random_state=random_seed)
      xmeans_mndl.process()
  
      # Extract X-Means MNDL clustering results.
      mndl_clusters = xmeans_mndl.get_clusters()
  
      # Visualize clustering results.
      visualizer = cluster_visualizer(titles=['X-Means with MNDL criterion'])
      visualizer.append_clusters(mndl_clusters, sample)
      visualizer.show()
  @endcode
  
  @image html xmeans_clustering_mndl_target.png "Fig. 2. X-Means MNDL clustering results (data 'Target')."
  
  As in many others algorithms, it is possible to specify metric that should be used for cluster analysis, for
  example, Chebyshev distance metric:
  @code
      # Create instance of X-Means algorithm with Chebyshev distance metric.
      chebyshev_metric = distance_metric(type_metric.CHEBYSHEV)
      xmeans_instance = xmeans(sample, initial_centers, max_clusters_amount, metric=chebyshev_metric).process()
  @endcode
  
  @see center_initializer
class_docstr_tok: ["!","@","brief","Class","represents","clustering","algorithm","X-Means",".","@","details","X-means","clustering","method","starts","with","the","assumption","of","having","a","minimum","number","of","clusters",",","and","then","dynamically","increases","them",".","X-means","uses","specified","splitting","criterion","to","control","the","process","of","splitting","clusters",".","Method","K-Means++","can","be","used","for","calculation","of","initial","centers",".","CCORE","implementation","of","the","algorithm","uses","thread","pool","to","parallelize","the","clustering","process",".","Here","example","how","to","perform","cluster","analysis","using","X-Means","algorithm",":","@","code","from","pyclustering.cluster","import","cluster_visualizer","from","pyclustering.cluster.xmeans","import","xmeans","from","pyclustering.cluster.center_initializer","import","kmeans_plusplus_initializer","from","pyclustering.utils","import","read_sample","from","pyclustering.samples.definitions","import","SIMPLE_SAMPLES","#","Read","sample","'simple3","'","from","file",".","sample","=","read_sample","(","SIMPLE_SAMPLES.SAMPLE_SIMPLE3",")","#","Prepare","initial","centers","-","amount","of","initial","centers","defines","amount","of","clusters","from","which","X-Means","will","#","start","analysis",".","amount_initial_centers","=","2","initial_centers","=","kmeans_plusplus_initializer","(","sample",",","amount_initial_centers",")",".initialize","(",")","#","Create","instance","of","X-Means","algorithm",".","The","algorithm","will","start","analysis","from","2","clusters",",","the","maximum","#","number","of","clusters","that","can","be","allocated","is","20.","xmeans_instance","=","xmeans","(","sample",",","initial_centers",",","20",")","xmeans_instance.process","(",")","#","Extract","clustering","results",":","clusters","and","their","centers","clusters","=","xmeans_instance.get_clusters","(",")","centers","=","xmeans_instance.get_centers","(",")","#","Print","total","sum","of","metric","errors","print","(","``","Total","WCE",":","''",",","xmeans_instance.get_total_wce","(",")",")","#","Visualize","clustering","results","visualizer","=","cluster_visualizer","(",")","visualizer.append_clusters","(","clusters",",","sample",")","visualizer.append_cluster","(","centers",",","None",",","marker=","'","*","'",",","markersize=10",")","visualizer.show","(",")","@","endcode","Visualization","of","clustering","results","that","were","obtained","using","code","above","and","where","X-Means","algorithm","allocates","four","clusters",".","@","image","html","xmeans_clustering_simple3.png","``","Fig",".","1",".","X-Means","clustering","results","(","data","'Simple3","'",")",".","''","By","default","X-Means","clustering","algorithm","uses","Bayesian","Information","Criterion","(","BIC",")","to","approximate","the","correct","number","of","clusters",".","There","is","an","example","where","another","criterion","Minimum","Noiseless","Description","Length","(","MNDL",")","is","used","in","order","to","find","optimal","amount","of","clusters",":","@","code","from","pyclustering.cluster","import","cluster_visualizer","from","pyclustering.cluster.xmeans","import","xmeans",",","splitting_type","from","pyclustering.cluster.center_initializer","import","kmeans_plusplus_initializer","from","pyclustering.utils","import","read_sample","from","pyclustering.samples.definitions","import","FCPS_SAMPLES","#","Read","sample","'Target","'",".","sample","=","read_sample","(","FCPS_SAMPLES.SAMPLE_TARGET",")","#","Prepare","initial","centers","-","amount","of","initial","centers","defines","amount","of","clusters","from","which","X-Means","will","start","analysis",".","random_seed","=","1000","amount_initial_centers","=","3","initial_centers","=","kmeans_plusplus_initializer","(","sample",",","amount_initial_centers",",","random_state=random_seed",")",".initialize","(",")","#","Create","instance","of","X-Means","algorithm","with","MNDL","splitting","criterion",".","xmeans_mndl","=","xmeans","(","sample",",","initial_centers",",","20",",","splitting_type=splitting_type.MINIMUM_NOISELESS_DESCRIPTION_LENGTH",",","random_state=random_seed",")","xmeans_mndl.process","(",")","#","Extract","X-Means","MNDL","clustering","results",".","mndl_clusters","=","xmeans_mndl.get_clusters","(",")","#","Visualize","clustering","results",".","visualizer","=","cluster_visualizer","(","titles=","[","'","X-Means","with","MNDL","criterion","'","]",")","visualizer.append_clusters","(","mndl_clusters",",","sample",")","visualizer.show","(",")","@","endcode","@","image","html","xmeans_clustering_mndl_target.png","``","Fig",".","2",".","X-Means","MNDL","clustering","results","(","data","'Target","'",")",".","''","As","in","many","others","algorithms",",","it","is","possible","to","specify","metric","that","should","be","used","for","cluster","analysis",",","for","example",",","Chebyshev","distance","metric",":","@","code","#","Create","instance","of","X-Means","algorithm","with","Chebyshev","distance","metric",".","chebyshev_metric","=","distance_metric","(","type_metric.CHEBYSHEV",")","xmeans_instance","=","xmeans","(","sample",",","initial_centers",",","max_clusters_amount",",","metric=chebyshev_metric",")",".process","(",")","@","endcode","@","see","center_initializer"]
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.__clusters = []
      while len(self.__centers) <= self.__kmax:
          current_cluster_number = len(self.__centers)
  
          (
              self.__clusters,
              self.__centers,
              _,
          ) = self.__improve_parameters(self.__centers)
          allocated_centers = self.__improve_structure(
              self.__clusters, self.__centers
          )
  
          if current_cluster_number == len(allocated_centers):
              break
          else:
              self.__centers = allocated_centers
  
      (
          self.__clusters,
          self.__centers,
          self.__total_wce,
      ) = self.__improve_parameters(self.__centers)
  
imports: import copy
  import numpy
  from enum import IntEnum
  from math import log
  from pyclustering.cluster.encoder import type_encoding
  from pyclustering.cluster.kmeans import kmeans
  from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer
  from pyclustering.core.metric_wrapper import metric_wrapper
  from pyclustering.core.wrapper import ccore_library
  import pyclustering.core.xmeans_wrapper
  from pyclustering.utils import distance_metric, type_metric
label_desc: Use image node_id 4 for calling the xmeans obj's underlying member method code with example usage: obj.__process_by_python() without return types