class_docstr: !
  @brief Class represents Genetic clustering algorithm.
  @details The searching capability of genetic algorithms is exploited in order to search for appropriate
           cluster centres.
  
  Example of clustering using genetic algorithm:
  @code
      from pyclustering.cluster.ga import genetic_algorithm, ga_observer
      from pyclustering.utils import read_sample
      from pyclustering.samples.definitions import SIMPLE_SAMPLES
  
  
      # Read input data for clustering
      sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE4)
  
      # Create instance of observer that will collect all information:
      observer_instance = ga_observer(True, True, True)
  
      # Create genetic algorithm for clustering
      ga_instance = genetic_algorithm(data=sample,
                                      count_clusters=4,
                                      chromosome_count=100,
                                      population_count=200,
                                      count_mutation_gens=1)
  
      # Start processing
      ga_instance.process()
  
      # Obtain results
      clusters = ga_instance.get_clusters()
  
      # Print cluster to console
      print("Amount of clusters: '%d'. Clusters: '%s'" % (len(clusters), clusters))
  @endcode
  
  There is an example of clustering results (fitness function evolution and allocated clusters) that were 
  visualized by 'ga_visualizer':
  
  @image html ga_clustering_sample_simple_04.png
  
  @see ga_visualizer
  @see ga_observer
class_docstr_tok: ["!","@","brief","Class","represents","Genetic","clustering","algorithm",".","@","details","The","searching","capability","of","genetic","algorithms","is","exploited","in","order","to","search","for","appropriate","cluster","centres",".","Example","of","clustering","using","genetic","algorithm",":","@","code","from","pyclustering.cluster.ga","import","genetic_algorithm",",","ga_observer","from","pyclustering.utils","import","read_sample","from","pyclustering.samples.definitions","import","SIMPLE_SAMPLES","#","Read","input","data","for","clustering","sample","=","read_sample","(","SIMPLE_SAMPLES.SAMPLE_SIMPLE4",")","#","Create","instance","of","observer","that","will","collect","all","information",":","observer_instance","=","ga_observer","(","True",",","True",",","True",")","#","Create","genetic","algorithm","for","clustering","ga_instance","=","genetic_algorithm","(","data=sample",",","count_clusters=4",",","chromosome_count=100",",","population_count=200",",","count_mutation_gens=1",")","#","Start","processing","ga_instance.process","(",")","#","Obtain","results","clusters","=","ga_instance.get_clusters","(",")","#","Print","cluster","to","console","print","(","``","Amount","of","clusters",":","'","%","d","'",".","Clusters",":","'","%","s","'","''","%","(","len","(","clusters",")",",","clusters",")",")","@","endcode","There","is","an","example","of","clustering","results","(","fitness","function","evolution","and","allocated","clusters",")","that","were","visualized","by","'ga_visualizer","'",":","@","image","html","ga_clustering_sample_simple_04.png","@","see","ga_visualizer","@","see","ga_observer"]
docstr: !
  @brief Initialize genetic clustering algorithm.
  
  @param[in] data (numpy.array|list): Input data for clustering that is represented by two dimensional array
              where each row is a point, for example, [[0.0, 2.1], [0.1, 2.0], [-0.2, 2.4]].
  @param[in] count_clusters (uint): The amount of clusters that should be allocated in the data.
  @param[in] chromosome_count (uint): The amount of chromosomes in each population.
  @param[in] population_count (uint): The amount of populations that essentially defines the amount of iterations.
  @param[in] **kwargs: Arbitrary keyword arguments (available arguments: `count_mutation_gens`,
              `coeff_mutation_count`, `select_coeff`, `crossover_rate`, `observer`, `random_state`).
  
  <b>Keyword Args:</b><br>
      - count_mutation_gens (uint): Amount of genes in chromosome that is mutated on each step.
      - coeff_mutation_count (float): Percent of chromosomes for mutation, distributed in range (0, 1] and
         thus amount of chromosomes is defined as follows: `chromosome_count` * `coeff_mutation_count`
      - select_coeff (float): Exponential coefficient for selection procedure that is used as follows:
         `math.exp(1 + fitness(chromosome) * select_coeff)`.
      - crossover_rate (float): Crossover rate.
      - observer (ga_observer): Observer that is used for collecting information of about clustering process on each step.
      - random_state (int): Seed for random state (by default is `None`, current system time is used).
docstr_tok: ["!","@","brief","Initialize","genetic","clustering","algorithm",".","@","param","[","in","]","data","(","numpy.array|list",")",":","Input","data","for","clustering","that","is","represented","by","two","dimensional","array","where","each","row","is","a","point",",","for","example",",","[","[","0.0",",","2.1","]",",","[","0.1",",","2.0","]",",","[","-0.2",",","2.4","]","]",".","@","param","[","in","]","count_clusters","(","uint",")",":","The","amount","of","clusters","that","should","be","allocated","in","the","data",".","@","param","[","in","]","chromosome_count","(","uint",")",":","The","amount","of","chromosomes","in","each","population",".","@","param","[","in","]","population_count","(","uint",")",":","The","amount","of","populations","that","essentially","defines","the","amount","of","iterations",".","@","param","[","in","]","*","*","kwargs",":","Arbitrary","keyword","arguments","(","available","arguments",":","`","count_mutation_gens","`",",","`","coeff_mutation_count","`",",","`","select_coeff","`",",","`","crossover_rate","`",",","`","observer","`",",","`","random_state","`",")",".","<","b",">","Keyword","Args",":","<","\/b",">","<","br",">","-","count_mutation_gens","(","uint",")",":","Amount","of","genes","in","chromosome","that","is","mutated","on","each","step",".","-","coeff_mutation_count","(","float",")",":","Percent","of","chromosomes","for","mutation",",","distributed","in","range","(","0",",","1","]","and","thus","amount","of","chromosomes","is","defined","as","follows",":","`","chromosome_count","`","*","`","coeff_mutation_count","`","-","select_coeff","(","float",")",":","Exponential","coefficient","for","selection","procedure","that","is","used","as","follows",":","`","math.exp","(","1","+","fitness","(","chromosome",")","*","select_coeff",")","`",".","-","crossover_rate","(","float",")",":","Crossover","rate",".","-","observer","(","ga_observer",")",":","Observer","that","is","used","for","collecting","information","of","about","clustering","process","on","each","step",".","-","random_state","(","int",")",":","Seed","for","random","state","(","by","default","is","`","None","`",",","current","system","time","is","used",")","."]
code: def __init__(
      self,
      data,
      count_clusters,
      chromosome_count,
      population_count,
      **kwargs,
  ):
      """!
      @brief Initialize genetic clustering algorithm.
  
      @param[in] data (numpy.array|list): Input data for clustering that is represented by two dimensional array
                  where each row is a point, for example, [[0.0, 2.1], [0.1, 2.0], [-0.2, 2.4]].
      @param[in] count_clusters (uint): The amount of clusters that should be allocated in the data.
      @param[in] chromosome_count (uint): The amount of chromosomes in each population.
      @param[in] population_count (uint): The amount of populations that essentially defines the amount of iterations.
      @param[in] **kwargs: Arbitrary keyword arguments (available arguments: `count_mutation_gens`,
                  `coeff_mutation_count`, `select_coeff`, `crossover_rate`, `observer`, `random_state`).
  
      <b>Keyword Args:</b><br>
          - count_mutation_gens (uint): Amount of genes in chromosome that is mutated on each step.
          - coeff_mutation_count (float): Percent of chromosomes for mutation, distributed in range (0, 1] and
             thus amount of chromosomes is defined as follows: `chromosome_count` * `coeff_mutation_count`
          - select_coeff (float): Exponential coefficient for selection procedure that is used as follows:
             `math.exp(1 + fitness(chromosome) * select_coeff)`.
          - crossover_rate (float): Crossover rate.
          - observer (ga_observer): Observer that is used for collecting information of about clustering process on each step.
          - random_state (int): Seed for random state (by default is `None`, current system time is used).
  
      """
  
      # Initialize random
      numpy.random.seed(kwargs.get("random_state", None))
  
      # Clustering data
      self._data = numpy.array(data)
  
      # Count clusters
      self._count_clusters = count_clusters
  
      # Home many chromosome in population
      self._chromosome_count = chromosome_count
  
      # How many populations
      self._population_count = population_count
  
      # Count mutation genes
      self._count_mutation_gens = kwargs.get("count_mutation_gens", 2)
  
      # Crossover rate
      self._crossover_rate = kwargs.get("crossover_rate", 1.0)
  
      # Count of chromosome for mutation (range [0, 1])
      self._coeff_mutation_count = kwargs.get(
          "coeff_mutation_count", 0.25
      )
  
      # Exponential coeff for selection
      self._select_coeff = kwargs.get("select_coeff", 1.0)
  
      # Result of clustering : best chromosome
      self._result_clustering = {
          "best_chromosome": [],
          "best_fitness_function": 0.0,
      }
  
      # Observer
      self._observer = kwargs.get("observer", ga_observer())
  
      self._verify_arguments()
  
imports: import numpy
  import matplotlib.pyplot
  import matplotlib.animation
  from pyclustering.cluster import cluster_visualizer
  from pyclustering.cluster.ga_maths import ga_math
label_desc: Use image node_id 1 to create a new genetic_algorithm object  with example: obj = genetic_algorithm(data, count_clusters, chromosome_count, population_count)