-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathrepGraf.py
120 lines (100 loc) · 3.15 KB
/
repGraf.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
import oitoRainhasv1 as v1
import oitoRainhasv2 as v2
import matplotlib.pyplot as plt
import numpy as np
def getLongestList(listOfLists):
res = []
for e in listOfLists:
if(len(e)>len(res)):
res = e
return res
def swapLists(listOfList):
swapedList = []
aux=0
maxLen = 0
for e in listOfList:
aux = maxLen
maxLen = max(aux,len(e))
print(maxLen)
for e in range(maxLen):
swapedList.append([])
for e in listOfList:
i = 0
for t in e:
swapedList[i].append(t)
i+=1
return swapedList
def avg(list):
return sum(list)/len(list)
def avgAndStd(listOLists):
swapedL = swapLists(listOLists)
average = list(map(avg,swapedL))
dev = list(map(np.std, swapedL))
res = [average,dev]
return res
def avalL(List):
res = []
for e in List:
res.append(e[-1])
return res
def plotGraphs(repetitions, CondParadaSel, version):
nAvalLists =[]
maxFitnessLists =[]
avgFitnessLists = []
k=0
for e in range(repetitions):
print(k)
k+=1
if(version==1):
parameterList = v1.main(CondParadaSel,0)
if(version==2):
parameterList = v2.main(CondParadaSel,0)
nAvalLists.append(parameterList["nAvalList"])
maxFitnessLists.append( parameterList["maxFitnessList"])
avgFitnessLists.append( parameterList["avgFitnessList"])
nAvall = avalL(nAvalLists)
nAvalAvg = sum(nAvall)/len(nAvall)
nAvalStd = np.std(nAvall)
popSize = len(maxFitnessLists[1])
nAvalMax = getLongestList(nAvalLists)
[avgFitnesslAvg, avgFitnessStd] = avgAndStd(avgFitnessLists)
x = nAvalMax
y = avgFitnesslAvg
e = avgFitnessStd
plt.subplot(2,2,version)
plt.subplots_adjust(hspace=0.2)
plt.errorbar(x,y,e,ecolor="red")
titulo = "Média e desvio padrão do fitness médio da versão "+str(version) +"(" + str(repetitions) + " repetições )"
plt.title(titulo)
text = "Numero medio de avaliacoes: "+str(round(nAvalAvg,2))+"\n Desvio Padrao: "+ str(round(nAvalStd,2))
plt.text(330,0.4,text)
plt.ylabel("Average Fitness")
plt.xlabel("Fitness Evaluations")
[maxFitnesslAvg, maxFitnessStd] = avgAndStd(maxFitnessLists)
x = nAvalMax
y = maxFitnesslAvg
e = maxFitnessStd
plt.subplot(2, 2, version+2)
plt.errorbar(x, y, e, ecolor="red")
titulo = "Média e desvio padrão do fitness máximo da versão "+str(version) +"(" + str(repetitions) + " repetições)"
plt.title(titulo)
plt.ylabel("Max Fitness")
plt.xlabel("Fitness Evaluations")
if(CondParadaSel==1):
plt.suptitle("Condição de parada: Fitness Máximo = 1")
if(CondParadaSel==0):
plt.suptitle("Condição de parada: Fitness Médio = 1")
return
def compareFitMax(): #compara as versoes 1 e 2 com condicao de saida de Fitness max = 1
plotGraphs(30, 1, 1)
plotGraphs(30, 1, 2)
plt.show()
return
def compareFitAvg(): #compara as versoes 1 e 2 com condicao de saida de Fitness medio = 1
plotGraphs(10, 0, 1)
plotGraphs(10, 0, 2)
plt.show()
return
#compareFitMax()
compareFitAvg()
#print(getLongestList(a))