-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathfigures.jl
198 lines (166 loc) · 6.95 KB
/
figures.jl
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
using CalibrationPaper
using CSV
using DataFrames
using PGFPlotsX
using StatsBase
using Statistics
function errors_comparison()
# initialize group plot
@pgf plt = GroupPlot(
{
group_style =
{
group_size = "3 by 4",
xlabels_at = "edge bottom",
ylabels_at = "edge left",
horizontal_sep = raw"0.12\linewidth",
vertical_sep = raw"0.06\linewidth",
},
no_markers,
tick_label_style = { font = raw"\tiny" },
grid = "major",
title_style = { align = "center" },
width = raw"0.3\linewidth",
height = raw"0.24\linewidth",
"every x tick scale label/.style" = {at = "{(1,0)}", anchor = "west"},
ylabel_style = { font = raw"\small" }
})
# define displayed experiments and corresponding labels
experiments = ["ECE_uniform", "SKCEb_median", "SKCEuq_median", "SKCEul_median"]
labels = [raw"$\widehat{\ECE}$", raw"$\biasedestimator$",
raw"$\unbiasedestimator$", raw"$\linearestimator$"]
# define displayed models
models = [CalibrationPaperModel(10, 0.1, 0.0, false),
CalibrationPaperModel(10, 0.1, 0.5, true),
CalibrationPaperModel(10, 0.1, 1.0, false)]
# directory with all experimental results
datadir = joinpath(@__DIR__, "..", "experiments", "data", "errors")
# for all studied experiments and models
for (i, experiment) in enumerate(experiments), (j, model) in enumerate(models)
# obtain full path
file = joinpath(datadir, "$experiment.csv")
# load estimates
estimates = collect_estimates(CSV.read(file), model)
# compute histogram
hist = fit(Histogram, estimates, closed = :left)
# create axis object with histogram
@pgf ax = Axis(PlotInc({ ybar_interval, fill = "Dark2-A!30!white" }, Table(hist)),
VLine({ solid, thick, "Dark2-B" }, mean(estimates)))
# add titles
if i == 1
ax["title"] = "\$\\symbf{M$j}\$"
end
# add labels
if j == 1
ax["ylabel"] = labels[i]
end
# compute true value
if startswith(experiment, "ECE")
analytic = CalibrationPaper.analytic_ece(model)
else
# take mean of quadratic unbiased estimates
if startswith(experiment, "SKCEuq")
analytic = mean(estimates)
else
file_uq = replace(file, r"(SKCEb|SKCEul)" => "SKCEuq")
estimates_uq = collect_estimates(CSV.read(file_uq), model)
analytic = mean(estimates_uq)
end
end
# plot true value
@pgf push!(ax, VLine({ dashed, thick, "Dark2-C" }, analytic))
# hack so that limits are updated as well
@pgf push!(ax, PlotInc({ draw = "none" }, Coordinates([analytic], [0])))
# add axis to group plot
push!(plt, ax)
end
# add labels
picture = TikzPicture(plt,
raw"\node[anchor=north] at ($(group c1r4.west |- group c1r4.outer south)!0.5!(group c3r4.east |- group c3r4.outer south)$){calibration error estimate};",
raw"\node[anchor=south, rotate=90, yshift=1ex] at ($(group c1r1.north -| group c1r1.outer west)!0.5!(group c1r4.south -| group c1r4.outer west)$){\# runs};")
# save histogram
figuresdir = joinpath(@__DIR__, "figures")
isdir(figuresdir) || mkdir(figuresdir)
pgfsave(joinpath(figuresdir, "errors_comparison.tex"), picture; include_preamble = false)
nothing
end
function pvalues_comparison()
# initialize group plot
@pgf plt = GroupPlot(
{
group_style =
{
group_size = "3 by 6",
xlabels_at = "edge bottom",
ylabels_at = "edge left",
horizontal_sep = raw"0.07\linewidth",
vertical_sep = raw"0.03\linewidth",
xticklabels_at = "edge bottom",
yticklabels_at = "edge left",
},
no_markers,
tick_label_style = { font = raw"\tiny" },
grid = "major",
title_style = { align = "center" },
width = raw"0.325\linewidth",
height = raw"0.25\linewidth",
"every x tick scale label/.style" = {at = "{(1,0)}", anchor = "west"},
ylabel_style = { font = raw"\small" },
xmin = 0, xmax = 1, ymin=-0.1, ymax=1.1
})
# define displayed experiments and corresponding labels
experiments = ["ECE_uniform", "SKCEb_median_distribution_free",
"SKCEuq_median_distribution_free",
"SKCEul_median_distribution_free",
"SKCEuq_median_asymptotic",
"SKCEul_median_asymptotic"]
labels = [raw"$\symbf{C}$", raw"$\symbf{D}_{\mathrm{b}}$",
raw"$\symbf{D}_{\mathrm{uq}}$", raw"$\symbf{D}_{\mathrm{l}}$",
raw"$\symbf{A}_{\mathrm{uq}}$",
raw"$\symbf{A}_{\mathrm{l}}$"]
# define displayed models
models = [CalibrationPaperModel(10, 0.1, 0.0, false),
CalibrationPaperModel(10, 0.1, 0.5, true),
CalibrationPaperModel(10, 0.1, 1.0, false)]
# define range of significance levels
αs = 0:0.01:1
# directory with all experimental results
datadir = joinpath(@__DIR__, "..", "experiments", "data", "pvalues")
# for all studied experiments and models
for (i, experiment) in enumerate(experiments), (j, model) in enumerate(models)
# obtain full path
file = joinpath(datadir, "$experiment.csv")
# load p-value estimates
pvalues = collect_estimates(CSV.read(file), model)
# compute empirical CDF
empiricalCDF = ecdf(pvalues)
if iszero(model.π)
# if the model is calibrated we plot the empirical estimate of
# P[p(T) < \alpha | H_0] together with the diagonal of the unit square
@pgf ax = Axis(PlotInc({ thick }, Table(αs, empiricalCDF.(αs))),
PlotInc({ dashed, thick }, Coordinates([0, 1], [0, 1])))
else
# otherwise we plot the empirical estimate for P[p(T) > \alpha | H_1]
@pgf ax = Axis(PlotInc({ thick }, Table(αs, 1 .- empiricalCDF.(αs))))
end
# add titles
if i == 1
ax["title"] = "\$\\symbf{M$j}\$"
end
# add labels
if j == 1
ax["ylabel"] = labels[i]
end
# add axis to group plot
push!(plt, ax)
end
# add labels
picture = TikzPicture(plt,
raw"\node[anchor=north] at ($(group c1r6.west |- group c1r6.outer south)!0.5!(group c3r6.east |- group c3r6.outer south)$){significance level};",
raw"\node[anchor=south, rotate=90] at ($(group c1r1.north -| group c1r1.outer west)!0.5!(group c1r6.south -| group c1r6.outer west)$){empirical test error};")
# save histogram
figuresdir = joinpath(@__DIR__, "figures")
isdir(figuresdir) || mkdir(figuresdir)
pgfsave(joinpath(figuresdir, "pvalues_comparison.tex"), picture; include_preamble = false)
nothing
end