Repository navigation
Expand file tree
/
Copy pathagg.py
More file actions
executable file
·122 lines (101 loc) · 3.03 KB
/
Copy pathagg.py
File metadata and controls
executable file
·122 lines (101 loc) · 3.03 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
from argparse import ArgumentParser
from ast import literal_eval
from dataclasses import dataclass
from pathlib import Path
import pandas as pd
@dataclass
class Args:
results: list[Path]
recursive: bool
output: Path
def parse_args() -> Args:
description = "Aggregate the results of the experiments"
parser = ArgumentParser(description=description)
parser.add_argument(
"results",
type=Path,
nargs="+",
help="The results files to aggregate",
)
parser.add_argument(
"-r",
"--recursive",
action="store_true",
help="Recursively search for results files",
)
parser.add_argument(
"-o",
"--output",
type=Path,
default=Path("results.csv"),
help="The output file",
)
args = parser.parse_args()
return Args(
results=list(map(Path, args.results)),
recursive=bool(args.recursive),
output=Path(args.output),
)
def get_files_recursive(paths: list[Path], ext: str) -> list[Path]:
files = []
for path in paths:
if path.is_dir():
files.extend(get_files_recursive(path.iterdir(), ext))
elif path.suffix == ext:
files.append(path)
return files
def get_files_flat(paths: list[Path], ext: str) -> list[Path]:
return [path for path in paths if path.suffix == ext]
def get_files(paths: list[Path], ext: str, *, recursive: bool) -> list[Path]:
if recursive:
return get_files_recursive(paths, ext)
return get_files_flat(paths, ext)
DATASET_COL = "dataset"
ENSEMBLE_COL = "ensemble"
NORM_COL = "norm"
N_ESTIMATORS_COL = "n.fitted.estimators"
N_ACTIVE_ESTIMATORS_COL = "n.active.estimators"
N_ORACLES_CALLS_COL = "n.oracle.calls"
ELAPSED_TIME_COL = "elapsed.time"
ACCURACY_AFTER_COL = "accuracy.after.pruning"
ACCURACY_COL = "accuracy"
FIDELITY_COL = "fidelity"
ENSEMBLE_OPTIONS_COL = "ensemble.options"
MAX_DEPTH_COL = "max.depth"
def _max_depth(options: str) -> int:
return dict(literal_eval(options)).get("max_depth", 0)
def main() -> None:
args = parse_args()
files = get_files(args.results, ext=".csv", recursive=args.recursive)
data = pd.concat(map(pd.read_csv, files)).reset_index(drop=True)
data[MAX_DEPTH_COL] = data[ENSEMBLE_OPTIONS_COL].apply(_max_depth)
pivoted = data.pivot_table(
index=[
DATASET_COL,
N_ESTIMATORS_COL,
ENSEMBLE_COL,
NORM_COL,
MAX_DEPTH_COL,
],
values=[
N_ACTIVE_ESTIMATORS_COL,
N_ORACLES_CALLS_COL,
ELAPSED_TIME_COL,
ACCURACY_AFTER_COL,
FIDELITY_COL,
],
aggfunc={
N_ACTIVE_ESTIMATORS_COL: "mean",
N_ORACLES_CALLS_COL: "mean",
ELAPSED_TIME_COL: "mean",
ACCURACY_AFTER_COL: "mean",
FIDELITY_COL: "mean",
},
).rename(
columns={
ACCURACY_AFTER_COL: ACCURACY_COL,
}
)
pivoted.to_csv(args.output)
if __name__ == "__main__":
main()