-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraphFitnessConvergence.py
48 lines (45 loc) · 1.93 KB
/
graphFitnessConvergence.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import sys
import matplotlib
import matplotlib.pyplot
class Generation:
number=-1
avgFitness=-1
bestFitness=-1
def __init__(self,number,avgFitness,bestFitness):
self.number=number
self.avgFitness=avgFitness
self.bestFitness=bestFitness
def main(argv):
if len(argv) != 2:
print "incorrect use of script"
print "please specify the ECJ stat file to read"
else:
generationString= "Generation: "
averageFitnessString= "Average Fitness: "
bestFitnessString="Fitness: Standardized="
generationList=[]
with open(argv[1],'r') as fin:
for line in fin:
if line.find(generationString) != -1:
generationNumber=line[len(generationString):]
generationNumber=generationNumber.strip()
elif line.find(averageFitnessString) != -1:
averageFitness=line[len(averageFitnessString):]
averageFitness=averageFitness.strip()
elif line.find(bestFitnessString) != -1:
line=line[len(bestFitnessString):]
lineItems=line.split()
bestFitness=lineItems[0]
g=Generation(generationNumber,averageFitness,bestFitness)
generationList.append(g)
avgFitList=[550000-float(g.avgFitness) for g in generationList]
bestFitList=[550000-float(g.bestFitness) for g in generationList]
line1,=matplotlib.pyplot.plot(avgFitList, color='r',label="Average Fitness")
line2,=matplotlib.pyplot.plot(bestFitList, color='b',label="Best Fitness")
matplotlib.pyplot.ylabel("FitnessScore")
matplotlib.pyplot.xlabel("Generations")
matplotlib.pyplot.title("Fitness Convergence")
matplotlib.pyplot.legend([line1,line2],["Average Fitness","Best Fitness"])
matplotlib.pyplot.show()
if __name__=="__main__":
main(sys.argv)