def plotStats(logbook: tools.Logbook): # plot statistics: minFitnessValues, meanFitnessValues = logbook.select("min", "avg") plt.figure(1) sns.set_style("whitegrid") plt.plot(minFitnessValues, color='red') plt.plot(meanFitnessValues, color='green') plt.xlabel('Generation') plt.ylabel('Min / Average Fitness') plt.title('Min and Average fitness over Generations')
def plot_evolution(evolution: Logbook): args = ['gen', 'max', 'mean', 'surface', 'count'] ev_it, ev_max, ev_mean, ev_surface, ev_count = evolution.select(*args) ev_online = np.array(ev_mean).cumsum() / np.arange(1, len(ev_mean) + 1) ev_offline = np.array(ev_max).cumsum() / np.arange(1, len(ev_max) + 1) fig, (ax1, ax2, ax3) = plt.subplots(1, 3, sharex='all', figsize=(12, 4)) # zbieznosc ax1.plot(ev_it, ev_max, label='max') ax1.plot(ev_it, ev_mean, label='mean') ax1.plot(ev_it, ev_offline, label='offline') ax1.plot(ev_it, ev_online, label='online') ax1.set_title('Zbieżność algorytmu') ax1.set_xlabel('Iteracja') ax1.set_ylabel('Przystosowanie') ax1.grid() ax1.legend() # surface ax2.plot(ev_it, np.array(ev_surface)) ax2.set_title('Suma powierchni najlepszego osobnika') ax2.set_xlabel('Iteracja') ax2.set_ylabel('Powierzchnia') ax2.grid() # count ax3.plot(ev_it, ev_count) ax3.set_title('Liczba skrzyń najlepszego osobnika') ax3.set_xlabel('Iteracja') ax3.set_ylabel('Liczba skrzyń') ax3.grid() plt.tight_layout() return fig