-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherrors.py
executable file
·58 lines (49 loc) · 1.35 KB
/
errors.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
#!/usr/bin/env python3
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.ticker import MaxNLocator
def readheaders(file):
headers = {}
for line in file:
if line == '#\n': break
assert line.startswith('# ')
name, value = line[len('# '):].split(':', maxsplit=1)
headers[name.strip()] = value.strip()
return headers
def readerrors(file):
PREFIX = '# error '
h = readheaders(file)
hurst = float(h['Hurst parameter'])
logn = int(h['Log of grid size'])
levels = int(h['Levels to descend'])
points = 0
errors = []
for line in file:
if not line.startswith('#'):
points += 1
continue
if not line.startswith(PREFIX):
continue
level, *rest = line[len(PREFIX):].split()
level = levels - int(level)
errors.append(level)
bins = np.arange(np.amax(errors) + 1) + logn
counts = np.bincount(errors)
return bins, counts/points, np.sqrt(counts)/points
def ploterrors(file, label=None):
x, y, yerr = readerrors(file)
plt.errorbar(x, y, yerr, fmt='.', label=label)
if __name__ == '__main__':
from sys import argv, stdin
for name in argv[1:]:
with open(name, 'r') as file:
ploterrors(file, label=name)
if len(argv) == 1:
ploterrors(stdin)
if len(argv) > 2:
plt.legend()
plt.xlim(left=0)
plt.gca().xaxis.set_major_locator(MaxNLocator(integer=True))
plt.xlabel("$\\ell$")
plt.ylabel("Error probability")
plt.show()