pyclustering.cluster.ga.ga_visualizer Class Reference

Genetic algorithm visualizer is used to show clustering results that are specific for this particular algorithm: clusters, evolution of global and local optimum. More...

Static Public Member Functions

def show_evolution (observer, start_iteration=0, stop_iteration=None, ax=None, display=True)
 Displays evolution of fitness function for the best chromosome, for the current best chromosome and average value among all chromosomes. More...
 
def show_clusters (data, observer, marker='.', markersize=None)
 Shows allocated clusters by the genetic algorithm. More...
 
def animate_cluster_allocation (data, observer, animation_velocity=75, movie_fps=5, save_movie=None)
 Animate clustering process of genetic clustering algorithm. More...
 

Detailed Description

Genetic algorithm visualizer is used to show clustering results that are specific for this particular algorithm: clusters, evolution of global and local optimum.

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:

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)
See also
cluster_visualizer

Definition at line 160 of file ga.py.

Member Function Documentation

◆ animate_cluster_allocation()

def pyclustering.cluster.ga.ga_visualizer.animate_cluster_allocation (   data,
  observer,
  animation_velocity = 75,
  movie_fps = 5,
  save_movie = None 
)
static

Animate clustering process of genetic clustering algorithm.

This method can be also used for rendering movie of clustering process and 'ffmpeg' is required for that purpuse.

Parameters
[in]data(list): Input data that was used for clustering process by the algorithm.
[in]observer(ga_observer): Observer that was used for collection information about clustering process. Be sure that whole information was collected by the observer.
[in]animation_velocity(uint): Interval between frames in milliseconds (for run-time animation only).
[in]movie_fps(uint): Defines frames per second (for rendering movie only).
[in]save_movie(string): If it is specified then animation will be stored to file that is specified in this parameter.

Definition at line 276 of file ga.py.

◆ show_clusters()

def pyclustering.cluster.ga.ga_visualizer.show_clusters (   data,
  observer,
  marker = '.',
  markersize = None 
)
static

Shows allocated clusters by the genetic algorithm.

Parameters
[in]data(list): Input data that was used for clustering process by the algorithm.
[in]observer(ga_observer): Observer that was used for collection information about clustering process.
[in]marker(char): Type of marker that should be used for object (point) representation.
[in]markersize(uint): Size of the marker that is used for object (point) representation.
Note
If you have clusters instead of observer then 'cluster_visualizer' can be used for visualization purposes.
See also
cluster_visualizer

Definition at line 248 of file ga.py.

◆ show_evolution()

def pyclustering.cluster.ga.ga_visualizer.show_evolution (   observer,
  start_iteration = 0,
  stop_iteration = None,
  ax = None,
  display = True 
)
static

Displays evolution of fitness function for the best chromosome, for the current best chromosome and average value among all chromosomes.

Parameters
[in]observer(ga_observer): Genetic algorithm observer that was used for collecting evolution in the algorithm and where whole required information for visualization is stored.
[in]start_iteration(uint): Iteration from that evolution should be shown.
[in]stop_iteration(uint): Iteration after that evolution shouldn't be shown.
[in]ax(Axes): Canvas where evolution should be displayed.
[in]display(bool): If 'True' then visualization of the evolution will be shown by the function. This argument should be 'False' if you want to add something else to the canvas and display it later.
Returns
(Axis) Canvas where evolution was shown.

Definition at line 205 of file ga.py.


The documentation for this class was generated from the following file: