-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathconv.py
63 lines (53 loc) · 1.67 KB
/
conv.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
import argparse
import pandas as pd
import numpy as np
import arviz as az
import matplotlib.pyplot as plt
from matplotlib.backends.backend_pdf import PdfPages
psr = argparse.ArgumentParser()
psr.add_argument("ipt", type=str, nargs="+", help="input files")
psr.add_argument("-o", dest="opt", type=str, help="output file")
args = psr.parse_args()
samples = [
pd.read_hdf(ipt, "sample")
.set_index(["TriggerNo", "ChannelID"])
.groupby(level=[0, 1])
for ipt in args.ipt
]
t0 = []
s0 = []
for sample in samples:
t0.append(np.vstack(sample.apply(lambda ent: ent["t0"].values)).T)
s0.append(np.vstack(sample.apply(lambda ent: ent["s0"].values)).T)
t0 = np.array(t0)
s0 = np.array(s0)
# chain, draw, x_dim_0
t0 = az.convert_to_dataset(t0)
s0 = az.convert_to_dataset(s0)
trials = range(100, 2500, 100)
res_t0 = []
res_s0 = []
for i in trials:
result = az.rhat(t0.sel(draw=slice(i, i * 2), x_dim_0=slice(None, 10)))
res_t0.append(np.array(result.x))
result = az.rhat(s0.sel(draw=slice(i, i * 2), x_dim_0=slice(None, 10)))
res_s0.append(np.array(result.x))
res_t0 = np.array(res_t0)
res_s0 = np.array(res_s0)
with PdfPages(args.opt) as pp:
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(np.array(trials) * 2, res_t0, label=[str(i) for i in range(11)])
ax.set_xlabel("step")
ax.set_ylabel("\hat{R}")
ax.set_title("Convergence of t0")
ax.legend()
pp.savefig(fig)
fig = plt.figure()
ax = fig.add_subplot(1, 1, 1)
ax.plot(np.array(trials) * 2, res_s0, label=[str(i) for i in range(11)])
ax.set_xlabel("step")
ax.set_ylabel("\hat{R}")
ax.set_title("Convergence of ||s||0")
ax.legend()
pp.savefig(fig)