/
graph.py
49 lines (37 loc) · 1.48 KB
/
graph.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
import click
import matplotlib.pyplot as plt
from pathlib import Path
@click.group()
def cli():
pass
def sensitivity(results_path, output_path, baseline_path, xticks, xlim):
parameters = []
accuracies = []
with open(baseline_path) as f:
_, baseline_acc = f.read().strip().split()
baseline_acc = float(baseline_acc)
with open(results_path) as f:
for line in f:
parameter, _, accuracy = line.strip().split()
parameters.append(float(parameter))
accuracies.append(float(accuracy))
plt.plot([-100, 100], [baseline_acc, baseline_acc], ':')
plt.plot(parameters, accuracies, '-o')
plt.xticks(xticks)
plt.ylim(baseline_acc - 10, baseline_acc + 10)
plt.xlim(*xlim)
plt.savefig(output_path)
@cli.command()
@click.argument('results_path', type=click.Path(exists=True))
@click.argument('output_path', type=click.Path())
@click.option('--baseline', type=click.Path(exists=True))
def sensitivity_align(results_path, output_path, baseline):
sensitivity(results_path, output_path, baseline, [-2.5, -3.0, -3.5, -4.0, -4.5], (-2.3, -4.7))
@cli.command()
@click.argument('results_path', type=click.Path(exists=True))
@click.argument('output_path', type=click.Path())
@click.option('--baseline', type=click.Path(exists=True))
def sensitivity_csls(results_path, output_path, baseline):
sensitivity(results_path, output_path, baseline, [0.9, 0.8, 0.7, 0.6, 0.5], (0.92, 0.48))
if __name__ == '__main__':
cli()