Added docstrings

This commit is contained in:
Marcin Kostrzewski 2020-05-17 11:22:38 +02:00
parent 96cf823619
commit 04370fb98c

View File

@ -3,6 +3,7 @@ A small script to help you analyze the output logs from GA algorithm.
It shows you best and worst population with all values. It shows you best and worst population with all values.
Specify the input file as an exec parameter. Specify the input file as an exec parameter.
""" """
import sys import sys
from ast import literal_eval from ast import literal_eval
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
@ -10,6 +11,11 @@ import numpy
def fitnessPlot(pop): def fitnessPlot(pop):
"""
Draw a fitness plot and write it to a file
:param pop: Population array with fitness
"""
fig, ax = plt.subplots() fig, ax = plt.subplots()
ax.plot([i[4] for i in pop]) ax.plot([i[4] for i in pop])
ax.set_title("Best fitness by generation") ax.set_title("Best fitness by generation")
@ -22,6 +28,11 @@ def fitnessPlot(pop):
def printBestWorstGenes(pop): def printBestWorstGenes(pop):
"""
Print info about best and worst specimen.
:param pop: Population array with fitness
"""
fitnesses = [i[4] for i in pop] fitnesses = [i[4] for i in pop]
bestIdxs = (numpy.where(fitnesses == numpy.max(fitnesses)))[0] bestIdxs = (numpy.where(fitnesses == numpy.max(fitnesses)))[0]