class_docstr: !
  @brief Class represents Elbow method that is used to find out appropriate amount of clusters in a dataset.
  @details The elbow is a heuristic method of interpretation and validation of consistency within cluster analysis
            designed to help find the appropriate number of clusters in a dataset.Elbow method performs clustering
            using K-Means algorithm for each K and estimate clustering results using sum of square erros. By default
            K-Means++ algorithm is used to calculate initial centers that are used by K-Means algorithm.
  
  The Elbow is determined by max distance from each point (x, y) to segment from kmin-point (x0, y0) to kmax-point (x1, y1),
  where 'x' is K (amount of clusters), and 'y' is within-cluster error. Following expression is used to calculate Elbow
  length:
  [Elbow_{k} = rac{\left ( y_{0} - y_{1} 
  ight )x_{k} + \left ( x_{1} - x_{0} 
  ight )y_{k} + \left ( x_{0}y_{1} - x_{1}y_{0} 
  ight )}{\sqrt{\left ( x_{1} - x_{0} 
  ight )^{2} + \left ( y_{1} - y_{0} 
  ight )^{2}}}]
  
  Usage example of Elbow method for cluster analysis:
  @code
      from pyclustering.cluster.kmeans import kmeans, kmeans_visualizer
      from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer
      from pyclustering.cluster.elbow import elbow
      from pyclustering.utils import read_sample
      from pyclustering.samples.definitions import SIMPLE_SAMPLES
  
      # read sample 'Simple3' from file (sample contains four clusters)
      sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE3)
  
      # create instance of Elbow method using K value from 1 to 10.
      kmin, kmax = 1, 10
      elbow_instance = elbow(sample, kmin, kmax)
  
      # process input data and obtain results of analysis
      elbow_instance.process()
      amount_clusters = elbow_instance.get_amount()  # most probable amount of clusters
      wce = elbow_instance.get_wce()  # total within-cluster errors for each K
  
      # perform cluster analysis using K-Means algorithm
      centers = kmeans_plusplus_initializer(sample, amount_clusters,
                                            amount_candidates=kmeans_plusplus_initializer.FARTHEST_CENTER_CANDIDATE).initialize()
      kmeans_instance = kmeans(sample, centers)
      kmeans_instance.process()
  
      # obtain clustering results and visualize them
      clusters = kmeans_instance.get_clusters()
      centers = kmeans_instance.get_centers()
      kmeans_visualizer.show_clusters(sample, clusters, centers)
  @endcode
  
  By default Elbow uses K-Means++ initializer to calculate initial centers for K-Means algorithm, it can be changed
  using argument 'initializer':
  @code
      # perform analysis using Elbow method with random center initializer for K-Means algorithm inside of the method.
      kmin, kmax = 1, 10
      elbow_instance = elbow(sample, kmin, kmax, initializer=random_center_initializer)
      elbow_instance.process()
  @endcode
  
  @image html elbow_example_simple_03.png "Elbows analysis with further K-Means clustering."
class_docstr_tok: ["!","@","brief","Class","represents","Elbow","method","that","is","used","to","find","out","appropriate","amount","of","clusters","in","a","dataset",".","@","details","The","elbow","is","a","heuristic","method","of","interpretation","and","validation","of","consistency","within","cluster","analysis","designed","to","help","find","the","appropriate","number","of","clusters","in","a","dataset.Elbow","method","performs","clustering","using","K-Means","algorithm","for","each","K","and","estimate","clustering","results","using","sum","of","square","erros",".","By","default","K-Means++","algorithm","is","used","to","calculate","initial","centers","that","are","used","by","K-Means","algorithm",".","The","Elbow","is","determined","by","max","distance","from","each","point","(","x",",","y",")","to","segment","from","kmin-point","(","x0",",","y0",")","to","kmax-point","(","x1",",","y1",")",",","where","'","x","'","is","K","(","amount","of","clusters",")",",","and","'","y","'","is","within-cluster","error",".","Following","expression","is","used","to","calculate","Elbow","length",":","[","Elbow_","{","k","}","=","rac","{","\\left","(","y_","{","0","}","-","y_","{","1","}","ight",")","x_","{","k","}","+","\\left","(","x_","{","1","}","-","x_","{","0","}","ight",")","y_","{","k","}","+","\\left","(","x_","{","0","}","y_","{","1","}","-","x_","{","1","}","y_","{","0","}","ight",")","}","{","\\sqrt","{","\\left","(","x_","{","1","}","-","x_","{","0","}","ight",")","^","{","2","}","+","\\left","(","y_","{","1","}","-","y_","{","0","}","ight",")","^","{","2","}","}","}","]","Usage","example","of","Elbow","method","for","cluster","analysis",":","@","code","from","pyclustering.cluster.kmeans","import","kmeans",",","kmeans_visualizer","from","pyclustering.cluster.center_initializer","import","kmeans_plusplus_initializer","from","pyclustering.cluster.elbow","import","elbow","from","pyclustering.utils","import","read_sample","from","pyclustering.samples.definitions","import","SIMPLE_SAMPLES","#","read","sample","'Simple3","'","from","file","(","sample","contains","four","clusters",")","sample","=","read_sample","(","SIMPLE_SAMPLES.SAMPLE_SIMPLE3",")","#","create","instance","of","Elbow","method","using","K","value","from","1","to","10.","kmin",",","kmax","=","1",",","10","elbow_instance","=","elbow","(","sample",",","kmin",",","kmax",")","#","process","input","data","and","obtain","results","of","analysis","elbow_instance.process","(",")","amount_clusters","=","elbow_instance.get_amount","(",")","#","most","probable","amount","of","clusters","wce","=","elbow_instance.get_wce","(",")","#","total","within-cluster","errors","for","each","K","#","perform","cluster","analysis","using","K-Means","algorithm","centers","=","kmeans_plusplus_initializer","(","sample",",","amount_clusters",",","amount_candidates=kmeans_plusplus_initializer.FARTHEST_CENTER_CANDIDATE",")",".initialize","(",")","kmeans_instance","=","kmeans","(","sample",",","centers",")","kmeans_instance.process","(",")","#","obtain","clustering","results","and","visualize","them","clusters","=","kmeans_instance.get_clusters","(",")","centers","=","kmeans_instance.get_centers","(",")","kmeans_visualizer.show_clusters","(","sample",",","clusters",",","centers",")","@","endcode","By","default","Elbow","uses","K-Means++","initializer","to","calculate","initial","centers","for","K-Means","algorithm",",","it","can","be","changed","using","argument","'initializer","'",":","@","code","#","perform","analysis","using","Elbow","method","with","random","center","initializer","for","K-Means","algorithm","inside","of","the","method",".","kmin",",","kmax","=","1",",","10","elbow_instance","=","elbow","(","sample",",","kmin",",","kmax",",","initializer=random_center_initializer",")","elbow_instance.process","(",")","@","endcode","@","image","html","elbow_example_simple_03.png","``","Elbows","analysis","with","further","K-Means","clustering",".","''"]
docstr: !
  @brief Finds elbow and returns corresponding K-value.
docstr_tok: ["!","@","brief","Finds","elbow","and","returns","corresponding","K-value","."]
code: def __find_optimal_kvalue(self):
      """!
      @brief Finds elbow and returns corresponding K-value.
  
      """
      optimal_elbow_value = max(self.__elbows)
      self.__kvalue = (
          self.__elbows.index(optimal_elbow_value) + 1
      ) * self.__kstep + self.__kmin
  
file_path: pyclustering/pyclustering/cluster/elbow.py
imports: import math
  from pyclustering.cluster.kmeans import kmeans
  from pyclustering.cluster.center_initializer import kmeans_plusplus_initializer, random_center_initializer
  from pyclustering.core.wrapper import ccore_library
  import pyclustering.core.elbow_wrapper
label_desc: Use image node_id 8 for calling the elbow obj's underlying member method code with example usage: obj.__find_optimal_kvalue() without return types