class_docstr: !
  @brief Genetic algorithm visualizer is used to show clustering results that are specific for
          this particular algorithm: clusters, evolution of global and local optimum.
  @details The visualizer requires 'ga_observer' that collects evolution of clustering process in
            genetic algorithm. The observer is created by user and passed to genetic algorithm. There
            is usage example of the visualizer using the observer:
  @code
      from pyclustering.cluster.ga import genetic_algorithm, ga_observer, ga_visualizer
      from pyclustering.utils import read_sample
      from pyclustering.samples.definitions import SIMPLE_SAMPLES
  
  
      # Read data for clustering
      sample = read_sample(SIMPLE_SAMPLES.SAMPLE_SIMPLE1)
  
      # Create instance of observer that will collect all information:
      observer_instance = ga_observer(True, True, True)
  
      # Create genetic algorithm where observer will collect information:
      ga_instance = genetic_algorithm(data=sample,
                                      count_clusters=2,
                                      chromosome_count=20,
                                      population_count=20,
                                      count_mutation_gens=1,
                                      observer=observer_instance)
  
      # 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))
  
      # Show cluster using observer:
      ga_visualizer.show_clusters(sample, observer_instance)
  @endcode
  
  @see cluster_visualizer
class_docstr_tok: ["!","@","brief","Genetic","algorithm","visualizer","is","used","to","show","clustering","results","that","are","specific","for","this","particular","algorithm",":","clusters",",","evolution","of","global","and","local","optimum",".","@","details","The","visualizer","requires","'ga_observer","'","that","collects","evolution","of","clustering","process","in","genetic","algorithm",".","The","observer","is","created","by","user","and","passed","to","genetic","algorithm",".","There","is","usage","example","of","the","visualizer","using","the","observer",":","@","code","from","pyclustering.cluster.ga","import","genetic_algorithm",",","ga_observer",",","ga_visualizer","from","pyclustering.utils","import","read_sample","from","pyclustering.samples.definitions","import","SIMPLE_SAMPLES","#","Read","data","for","clustering","sample","=","read_sample","(","SIMPLE_SAMPLES.SAMPLE_SIMPLE1",")","#","Create","instance","of","observer","that","will","collect","all","information",":","observer_instance","=","ga_observer","(","True",",","True",",","True",")","#","Create","genetic","algorithm","where","observer","will","collect","information",":","ga_instance","=","genetic_algorithm","(","data=sample",",","count_clusters=2",",","chromosome_count=20",",","population_count=20",",","count_mutation_gens=1",",","observer=observer_instance",")","#","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",")",")","#","Show","cluster","using","observer",":","ga_visualizer.show_clusters","(","sample",",","observer_instance",")","@","endcode","@","see","cluster_visualizer"]
docstr: !
  @brief Animate clustering process of genetic clustering algorithm.
  @details This method can be also used for rendering movie of clustering process and 'ffmpeg' is required for that purpuse.
  
  @param[in] data (list): Input data that was used for clustering process by the algorithm.
  @param[in] observer (ga_observer): Observer that was used for collection information about clustering process.
              Be sure that whole information was collected by the observer.
  @param[in] animation_velocity (uint): Interval between frames in milliseconds (for run-time animation only).
  @param[in] movie_fps (uint): Defines frames per second (for rendering movie only).
  @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
docstr_tok: ["!","@","brief","Animate","clustering","process","of","genetic","clustering","algorithm",".","@","details","This","method","can","be","also","used","for","rendering","movie","of","clustering","process","and","'ffmpeg","'","is","required","for","that","purpuse",".","@","param","[","in","]","data","(","list",")",":","Input","data","that","was","used","for","clustering","process","by","the","algorithm",".","@","param","[","in","]","observer","(","ga_observer",")",":","Observer","that","was","used","for","collection","information","about","clustering","process",".","Be","sure","that","whole","information","was","collected","by","the","observer",".","@","param","[","in","]","animation_velocity","(","uint",")",":","Interval","between","frames","in","milliseconds","(","for","run-time","animation","only",")",".","@","param","[","in","]","movie_fps","(","uint",")",":","Defines","frames","per","second","(","for","rendering","movie","only",")",".","@","param","[","in","]","save_movie","(","string",")",":","If","it","is","specified","then","animation","will","be","stored","to","file","that","is","specified","in","this","parameter","."]
code: def animate_cluster_allocation(
      data,
      observer,
      animation_velocity=75,
      movie_fps=5,
      save_movie=None,
  ):
      """!
      @brief Animate clustering process of genetic clustering algorithm.
      @details This method can be also used for rendering movie of clustering process and 'ffmpeg' is required for that purpuse.
  
      @param[in] data (list): Input data that was used for clustering process by the algorithm.
      @param[in] observer (ga_observer): Observer that was used for collection information about clustering process.
                  Be sure that whole information was collected by the observer.
      @param[in] animation_velocity (uint): Interval between frames in milliseconds (for run-time animation only).
      @param[in] movie_fps (uint): Defines frames per second (for rendering movie only).
      @param[in] save_movie (string): If it is specified then animation will be stored to file that is specified in this parameter.
  
      """
  
      figure = plt.figure()
  
      def init_frame():
          return frame_generation(0)
  
      def frame_generation(index_iteration):
          figure.clf()
  
          figure.suptitle(
              "Clustering genetic algorithm (iteration: "
              + str(index_iteration)
              + ")",
              fontsize=18,
              fontweight="bold",
          )
  
          visualizer = cluster_visualizer(
              4,
              2,
              [
                  "The best pop. on step #" + str(index_iteration),
                  "The best population",
              ],
          )
  
          local_minimum_clusters = ga_math.get_clusters_representation(
              observer.get_population_best()["chromosome"][
                  index_iteration
              ]
          )
          visualizer.append_clusters(local_minimum_clusters, data, 0)
  
          global_minimum_clusters = ga_math.get_clusters_representation(
              observer.get_global_best()["chromosome"][index_iteration]
          )
          visualizer.append_clusters(global_minimum_clusters, data, 1)
  
          ax1 = plt.subplot2grid((2, 2), (1, 0), colspan=2)
          ga_visualizer.show_evolution(
              observer, 0, index_iteration + 1, ax1, False
          )
  
          visualizer.show(figure, shift=0, display=False)
          figure.subplots_adjust(top=0.85)
  
          return [figure.gca()]
  
      iterations = len(observer)
      cluster_animation = animation.FuncAnimation(
          figure,
          frame_generation,
          iterations,
          interval=animation_velocity,
          init_func=init_frame,
          repeat_delay=5000,
      )
  
      if save_movie is not None:
          cluster_animation.save(
              save_movie, writer="ffmpeg", fps=movie_fps, bitrate=1500
          )
      else:
          plt.show()
  
      plt.close(figure)
  
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 3 for calling the ga_visualizer obj's underlying member method code with example usage: obj.animate_cluster_allocation(data, observer, animation_velocity, movie_fps, save_movie) and returns: frame_generation, list