-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot.py
More file actions
109 lines (89 loc) · 3.52 KB
/
plot.py
File metadata and controls
109 lines (89 loc) · 3.52 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
# This script visualizes the output of TestOptionalContinuation.
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
import pandas as pd
def plotP(df):
numSamples = len(df.s.unique())
np.random.seed(0)
plottedSamples = np.random.choice(range(numSamples), 200, replace=False)
xmin, xmax = df.t.min(), df.t.max()
fig, ax = plt.subplots(1, 1)
for sampleID in plottedSamples:
sdf = df[df.s == sampleID]
row = sdf.iloc[0]
if row.stopTP != -1:
color = (0, 1, 0)
alpha = 1
ax.plot(sdf.t, sdf.p, color=color, alpha=alpha)
elif row.stopTPOC != -1:
sdfReal = sdf[sdf.t <= row.stopTPOC]
sdfHypothetic = sdf[sdf.t > row.stopTPOC]
color = (1, 0, 0)
alpha = 1
ax.plot(sdfReal.t, sdfReal.p, color=color, alpha=alpha)
ax.plot(sdfHypothetic.t, sdfHypothetic.p, linestyle="--", color=color, alpha=alpha)
else:
color = (0, 0, 0)
alpha = 0.1
ax.plot(sdf.t, sdf.p, color=color, alpha=alpha)
ax.hlines(0.05, xmin, xmax, linewidth=3)
handles = [
[matplotlib.patches.Patch(facecolor=(0, 1, 0))],
[matplotlib.patches.Patch(facecolor=(0, 1, 0)), matplotlib.patches.Patch(facecolor=(1, 0, 0))],
]
labels = [
"standard, type I error {:.3f}".format(len(df[df.stopTP != -1].s.unique())/numSamples),
"optional continuation, type I error {:.3f}".format(len(df[df.stopTPOC != -1].s.unique())/numSamples),
]
ax.legend(handles=handles, labels=labels, handler_map={list: matplotlib.legend_handler.HandlerTuple(None)})
ax.set_yscale('log')
ax.set_xlabel("n")
ax.set_ylabel("p-value")
ax.set_title("T-test with/without optional continuation")
def plotE(df):
stoppedStd = list(df[df.stopTE != -1].s.unique())
stoppedOC = list(df[(df.stopTEOC != -1) & (df.stopTE == -1)].s.unique())
numSamples = len(df.s.unique())
np.random.seed(0)
numPlotted = 200
plottedSamples = list(np.random.choice(range(numSamples), numPlotted, replace=False))
plottedOC = list(np.random.choice(stoppedOC, int(np.round(len(stoppedOC)*numPlotted/numSamples)), replace=False))
# plottedSamples += stoppedStd + plottedOC
xmin, xmax = df.t.min(), df.t.max()
fig, ax = plt.subplots(1, 1)
for sampleID in plottedSamples:
sdf = df[df.s == sampleID]
row = sdf.iloc[0]
if row.stopTE != -1:
color = (0, 1, 0)
alpha = 1
ax.plot(sdf.t, sdf.e, color=color, alpha=alpha)
elif row.stopTEOC != -1:
sdfReal = sdf[sdf.t <= row.stopTEOC]
sdfHypothetic = sdf[sdf.t > row.stopTEOC]
color = (1, 0, 0)
alpha = 1
ax.plot(sdfReal.t, sdfReal.e, color=color, alpha=alpha)
ax.plot(sdfHypothetic.t, sdfHypothetic.e, linestyle="--", color=color, alpha=alpha)
else:
color = (0, 0, 0)
alpha = 0.1
ax.plot(sdf.t, sdf.e, color=color, alpha=alpha)
ax.hlines(1./0.05, xmin, xmax, linewidth=3)
handles = [
[matplotlib.patches.Patch(facecolor=(0, 1, 0))],
[matplotlib.patches.Patch(facecolor=(0, 1, 0)), matplotlib.patches.Patch(facecolor=(1, 0, 0))],
]
labels = [
"standard, type I error {:.3f}".format(len(df[df.stopTE != -1].s.unique())/numSamples),
"optional continuation, type I error {:.3f}".format(len(df[df.stopTEOC != -1].s.unique())/numSamples),
]
ax.legend(handles=handles, labels=labels, handler_map={list: matplotlib.legend_handler.HandlerTuple(None)})
ax.set_yscale('log')
ax.set_xlabel("n")
ax.set_ylabel("e-value")
ax.set_title("E-value test with/without optional continuation")
df = pd.read_csv("oc.csv")
plotP(df)
plotE(df)