-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_results.py
53 lines (45 loc) · 1.76 KB
/
print_results.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
import argparse
import sys
import os
import pandas as pd
import numpy as np
parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--testproblem", type=str, required=True)
parser.add_argument("--param1", nargs='+', type=float, default=[])
parser.add_argument("--param2", nargs='+', type=float, default=[])
args, _ = parser.parse_known_args()
testproblem = args.testproblem
linearisations = ["newton"]
for linearisation in linearisations:
mypath = f"results/results{linearisation}{testproblem}"
my_files = [f for f in os.listdir(mypath) if (os.path.isfile(os.path.join(mypath, f)) and f.endswith(".txt"))]
var1, var2 = my_files[0].split("_")[0:2]
values_1 = []
values_2 = []
for my_file in my_files:
my_file = my_file.replace(".txt", "")
_, _, val1, val2 = my_file.split("_")
values_1.append(val1)
values_2.append(val2)
key = lambda x: float(x)
reverse1 = np.min([float(v) for v in values_1]) < 1.0
reverse2 = np.min([float(v) for v in values_2]) < 1.0
values_1 = sorted(np.unique(values_1), key=key, reverse=reverse1)
values_2 = sorted(np.unique(values_2), key=key, reverse=reverse2)
df = pd.DataFrame(index = values_1, columns = values_2)
for my_file in my_files:
with open(os.path.join(mypath, my_file), 'r') as f:
it_num = f.read()
my_file = my_file.replace(".txt", "")
_, _, val1, val2 = my_file.split("_")
df[val2][val1] = it_num
df = df.T
df.columns.name = f"{var2}/{var1}"
df = df.fillna("( 0) -- ")
if args.param1:
df = df[[str(p) for p in args.param1]]
if args.param2:
df = df.loc[[str(p) for p in args.param2]]
print(df)
print(df.to_latex())
df.to_csv(os.path.join(mypath, "it_numbers.csv"))