Metrics and plotting¶
metrics
¶
Population diversity measures, for GeneticAlgorithm(diversity=...).
A measure receives the genomes of the current population and returns a number, or None when it cannot
be computed for those genomes. Write your own with the same signature for other genome types.
positional_diversity
¶
Diversity in [0, 1] for sequence genomes of equal length (str, list, tuple, bytes, numpy array).
For each gene position, the share of individuals that do not carry the most common gene, averaged over
positions. 0 = every individual is identical (premature convergence).
Genes are compared by equality: for real-valued genes use :func:gene_spread.
Returns None for other genomes, unequal lengths or unhashable genes.
Source code in src/carmelolg/galib/metrics.py
gene_spread
¶
Mean, over gene positions, of the population standard deviation of each gene.
Meant for real-valued genomes (list, tuple or numpy array of numbers). It is in the same unit as the
genes, so compare it with the size of the search space. Returns None for non-numeric genomes or
unequal lengths.
Source code in src/carmelolg/galib/metrics.py
plot
¶
Optional plotting. Requires matplotlib: pip install "carmelolg-galib[plot]".
plot_history
¶
plot_history(result: Result[Any], show: bool = True) -> Any
Plot best/mean fitness and diversity of a finished run. Returns the matplotlib figure.