forked from 7ossam81/EvoloPy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_convergence.py
28 lines (24 loc) · 1.13 KB
/
plot_convergence.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import matplotlib.pyplot as plt
import pandas as pd
def run(results_directory, optimizer, objectivefunc, Iterations):
plt.ioff()
fileResultsData = pd.read_csv(results_directory + '/experiment.csv')
for j in range (0, len(objectivefunc)):
objective_name = objectivefunc[j]
startIteration = 0
if 'SSA' in optimizer:
startIteration = 1
allGenerations = [x+1 for x in range(startIteration,Iterations)]
for i in range(len(optimizer)):
optimizer_name = optimizer[i]
row = fileResultsData[(fileResultsData["Optimizer"] == optimizer_name) & (fileResultsData["objfname"] == objective_name)]
row = row.iloc[:, 3+startIteration:]
plt.plot(allGenerations, row.values.tolist()[0], label=optimizer_name)
plt.xlabel('Iterations')
plt.ylabel('Fitness')
plt.legend(loc="top right", bbox_to_anchor=(1.2,1.02))
plt.grid()
fig_name = results_directory + "/convergence-" + objective_name + ".png"
plt.savefig(fig_name, bbox_inches='tight')
plt.clf()
#plt.show()