-
Notifications
You must be signed in to change notification settings - Fork 1
/
evaluate
executable file
·76 lines (63 loc) · 2.71 KB
/
evaluate
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
#!/usr/bin/env python3
import argparse
import re
from subprocess import PIPE, run
import matplotlib.pyplot as plt
import numpy as np
import seaborn as sns
def main():
parser = argparse.ArgumentParser()
parser.add_argument("-n", help="number of times to run", type=int, default=3)
parser.add_argument("-b", help="evaluate BentCigarFunction", action="store_true")
parser.add_argument("-k", help="evaluate KatsuuraEvaluation", action="store_true")
parser.add_argument("-s", help="evaluate SchaffersEvaluation", action="store_true")
parser.add_argument("-a", help="test all functions", action="store_true")
parser.add_argument("-p", "--plot", help="make a boxplot of the scores", action="store_true")
args = parser.parse_args()
functions = ["BentCigarFunction", "KatsuuraEvaluation", "SchaffersEvaluation"]
function = None
if args.b:
function = functions[0]
elif args.k:
function = functions[1]
elif args.s:
function = functions[2]
if function is not None:
score = get_score(function, args.n)
print("Average of {}: {}".format(args.n, score))
return
if args.a:
function = functions
bent = get_score(functions[0], args.n)
katsuura = get_score(functions[1], args.n)
schaffers = get_score(functions[2], args.n)
results = [bent, katsuura, schaffers]
data = [x[0] for x in results]
scores = [x[1] for x in results]
errors = [x[2] for x in results]
print("BentCigarFunction - average of {}: {} ± {}".format(args.n, scores[0], errors[0]))
print("KatsuuraEvaluation - average of {}: {} ± {}".format(args.n, scores[1], errors[1]))
print("SchaffersEvaluation - average of {}: {} ± {}".format(args.n, scores[2], errors[2]))
if args.plot:
ax = sns.boxplot(x=["BentCigar", "Katsuura", "Schaffers"], y=data)
sns.set_style("whitegrid")
plt.xlabel("Function")
plt.ylabel("Score")
plt.savefig("results_n{}.png".format(args.n), dpi=400)
return
# no flags given
print("Defaulting to BentCigarFunction...")
score = get_score(functions[0], args.n)
print("Average of {}: {}".format(args.n, score))
def get_score(function: str, n: int):
scores = []
for i in range(n):
output = run("make run FUNC={}".format(function).split(), stdout=PIPE).stdout.decode("utf-8")
print(output)
start = output.find("Score: ")
score = re.match("\d+\.\d+", output[start + 7:])
score = float(score.group())
scores.append(score)
return np.array(scores), sum(scores) / n, np.std(scores)
if __name__ == "__main__":
main()