-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path__main__.py
150 lines (133 loc) · 3.93 KB
/
__main__.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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import argparse
import contextlib
import os
import typst
from rich.console import Console
from rich.status import Status
from rich.traceback import install
from project.labs.lab02 import lab02
from project.labs.lab03 import lab03
from project.labs.lab04 import lab04
from project.labs.lab05 import lab05
from project.labs.lab07 import lab07
from project.labs.lab08 import lab08
from project.labs.lab09 import lab09
from project.labs.lab10 import lab10
from project.labs.lab11 import lab11
TYPST_PATH = "report/report.typ"
DATA = "data/trainData.txt"
lab_config = {
"lab02": {
"enabled": False,
"function": lab02,
"title": "Analyzing the features",
},
"lab03": {
"enabled": False,
"function": lab03,
"title": "PCA & LDA",
},
"lab04": {
"enabled": False,
"function": lab04,
"title": "Probability densities and ML estimates",
},
"lab05": {
"enabled": False,
"function": lab05,
"title": "Generative models for classification",
},
"lab07": {
"enabled": False,
"function": lab07,
"title": "Performance analysis of the MVG classifier",
},
"lab08": {
"enabled": False,
"function": lab08,
"title": "Performance analysis of the Binary Logistic Regression classifier",
},
"lab09": {
"enabled": False,
"function": lab09,
"title": "Support Vector Machines classification",
},
"lab10": {
"enabled": False,
"function": lab10,
"title": "Gaussian Mixture Models",
},
"lab11": {
"enabled": False,
"function": lab11,
"title": "Calibration and Evaluation",
},
}
def parse_args():
parser = argparse.ArgumentParser(
prog="python -m project",
description="Run the code for the project, separately for each labs. Optionally compile the report.",
)
parser.add_argument(
"-c",
"--compile_pdf",
action="store_true",
help="compile the report in pdf format",
)
parser.add_argument(
"-q",
"--quiet",
action="store_true",
help="suppress additional information during code execution",
)
group = parser.add_argument_group(
"labs", "Choose which part of the project, ordered by labs, to run"
)
exclusive_group = group.add_mutually_exclusive_group(required=True)
exclusive_group.add_argument(
"-a",
"--all",
action="store_true",
help="run all project parts",
)
exclusive_group.add_argument(
"-l",
"--labs",
choices=[2, 3, 4, 5, 7, 8, 9, 10, 11],
type=int,
nargs="+",
help="run specific project parts by specifying one of more associated lab numbers",
)
args = parser.parse_args()
if args.all:
for lab_key in lab_config.keys():
lab_config[lab_key]["enabled"] = True
else:
for lab in args.labs:
# Converts 2 to "lab02", 10 to "lab10", etc.
lab_key = f"lab{str(lab).zfill(2)}"
if lab_key in lab_config:
lab_config[lab_key]["enabled"] = True
return args
def main():
console = Console()
install(show_locals=True)
args = parse_args()
def run_labs():
for lab_id, lab_info in lab_config.items():
if lab_info["enabled"]:
console.log(f"{lab_id} - [bold red]{lab_info['title']} [/bold red]")
lab_info["function"](DATA)
if args.compile_pdf:
status = Status("Compiling the report...")
status.start()
typst.compile(TYPST_PATH, output=TYPST_PATH.replace(".typ", ".pdf"))
status.stop()
if args.quiet:
# Suppress output by redirecting stdout to /dev/null
with open(os.devnull, "w") as f, contextlib.redirect_stdout(f):
run_labs()
else:
run_labs()
if __name__ == "__main__":
main()