-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatScript.py
More file actions
135 lines (106 loc) · 5.58 KB
/
statScript.py
File metadata and controls
135 lines (106 loc) · 5.58 KB
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import matplotlib.pyplot as plt
import pandas as pd
from pathlib import Path
import numpy as np
import onemaxFunctions
# Pandas mean on a dataframe of the columns to mean
def makeGraf(folder, listOp):
allcsvForSeeds = list(Path(folder).rglob("*.csv"))
mean = pd.read_csv(allcsvForSeeds[0])
if listOp is not None:
historyMethodsMean = stringSeriesToList(mean["methodsHistory"])
historyProbMean = stringSeriesToList(mean["probOpe"])
maxGen = max(mean["generation"])
for file in allcsvForSeeds[1:]:
df = pd.read_csv(file)
if max(df["generation"]) < maxGen:
maxGen = max(df["generation"])
if listOp is not None:
historyMethodsMean = np.add(stringSeriesToList(df["methodsHistory"][:maxGen]), historyMethodsMean[:maxGen])
historyProbMean = np.add(stringSeriesToList(df["probOpe"][:maxGen]), historyProbMean[:maxGen])
mean["min_fitness"] = mean["min_fitness"][:maxGen] + df["min_fitness"][:maxGen]
mean["max_fitness"] = mean["max_fitness"][:maxGen] + df["max_fitness"][:maxGen]
mean["mean"] = mean["mean"][:maxGen] + df["mean"][:maxGen]
mean["standard_deviation"] = mean["standard_deviation"][:maxGen] + df["standard_deviation"][:maxGen]
mean["min_fitness"] = mean["min_fitness"].div(len(allcsvForSeeds))
mean["max_fitness"] = mean["max_fitness"].div(len(allcsvForSeeds))
mean["mean"] = mean["mean"].div(len(allcsvForSeeds))
mean["standard_deviation"] = mean["standard_deviation"].div(len(allcsvForSeeds))
if listOp is not None:
historyMethodsMean = np.divide(historyMethodsMean, len(allcsvForSeeds))
historyProbMean = np.divide(historyProbMean, len(allcsvForSeeds))
# fitness + use graf
fig = plt.figure()
ax = plt.axes()
ax.plot(mean["generation"], mean["mean"], label="mean fitness")
ax.plot(mean["generation"], mean["min_fitness"], label="min fitness")
ax.plot(mean["generation"], mean["max_fitness"], label="max fitness")
lengthGraf = 0
if listOp is not None:
listOfOp = [[t[o] for t in historyMethodsMean] for o in range(len(listOp))]
for o in range(len(listOp)):
plt.plot(listOfOp[o], label=str(listOp[o].__name__))
for o in range(len(listOp)):
maxOpe = historyMethodsMean[-1][o]
if lengthGraf < maxOpe:
lengthGraf = maxOpe
if lengthGraf < max(mean["max_fitness"]):
lengthGraf = max(mean["max_fitness"])
ax.set(xlim=(-1, maxGen*1.1),
ylim=(-1, lengthGraf * 1.1),
xlabel="Generation", ylabel="fitness/Application of operations",
title='mean fitness and operation usage per generation')
else:
lengthGraf = max(mean["max_fitness"] * 1.1)
if lengthGraf == 0:
lengthGraf = 1
ax.set(xlim=(-1, maxGen*1.1),
ylim=(-1, lengthGraf * 1.1),
xlabel="Generation", ylabel="fitness",
title='mean fitness per generation')
plt.legend()
plt.fill_between(mean["generation"], mean["mean"] + mean["standard_deviation"],
mean["mean"] - mean["standard_deviation"], color="gray", label="standard deviation")
plt.grid()
#plt.savefig(folder + "/fig_use_and_fitness_per_gen.png")
plt.show()
if listOp is not None:
# Percentage per fit graf
fig = plt.figure()
ax = plt.axes()
listOfOp = [[t[o] for t in historyProbMean] for o in range(len(listOp))]
for o in range(len(listOp)):
plt.plot(mean["max_fitness"][:maxGen], listOfOp[o], label=str(listOp[o].__name__))
ax.set(xlim=(-1, max(mean["max_fitness"])*1.1),
ylim=(-0.1, 1.1),
xlabel="max fitness", ylabel="% of use",
title='Percentage of use of operation per fitness max of the population')
plt.legend()
plt.grid()
#plt.savefig(folder + "/fig_percentage_per_fit.png")
plt.show()
# Percentage per gen graf
fig = plt.figure()
ax = plt.axes()
listOfOp = [[t[o] for t in historyProbMean] for o in range(len(listOp))]
for o in range(len(listOp)):
plt.plot(mean["generation"][:maxGen], listOfOp[o], label=str(listOp[o].__name__))
ax.set(xlim=(-1, maxGen*1.1),
ylim=(-0.1, 1.1),
xlabel="generation", ylabel="% of use",
title='Percentage of use of operation per generation')
plt.legend()
plt.grid()
#plt.savefig(folder + "/fig_percentage_per_gen.png")
plt.show()
# Get list from pandas Series of strings
def stringSeriesToList(column):
result = []
for prob in column:
tmp = prob.strip("[]").split(", ")
for i in range(len(tmp)):
tmp[i] = float(tmp[i])
result += [tmp]
return result
makeGraf("/home/etud/PycharmProjects/evo/data/(1000, 40000)/tournamentSelection_monopoint_roulette_[oneFlip_threeFlip_fiveFlip_bitFlip]fit/",
[onemaxFunctions.oneFlip, onemaxFunctions.threeFlip, onemaxFunctions.fiveFlip, onemaxFunctions.bitFlip])