-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplot_utils.jl
90 lines (77 loc) · 2.24 KB
/
plot_utils.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
using PlotsOptim: get_abscisses, get_ordinates, COLORS_7, COLORS_10
using PlotsOptim
using PGFPlotsX
using DelimitedFiles
function extract_seriousnullsteps(pb, tr)
xsnull, ysnull = Int64[], Float64[]
xsser, ysser = Int64[], Float64[]
function subopt(p)
return F(pb, p)
end
iser = 1
for (inull, pt) in enumerate(tr[end].additionalinfo.nullstepshist)
Fpt = subopt(pt)
# Null steps
push!(ysnull, Fpt)
push!(xsnull, inull)
# Serious step
if pt == tr[iser].additionalinfo.p
push!(ysser, Fpt)
push!(xsser, inull)
iser += 1
end
end
@assert iser ≥ length(tr)
return xsnull, ysnull, xsser, ysser
end
function plot_seriousnullsteps(pb, tr, Fopt; title)
xsnull, ysnull, xsser, ysser = extract_seriousnullsteps(pb, tr)
model_to_curve = [
("null", xsnull, ysnull .- Fopt, "x", COLORS_7[3]),
("serious", xsser, ysser .- Fopt, "pentagon", COLORS_7[5])
]
# Building plot
plotdata = []
for (mod, xs, ys, marker, color) in model_to_curve
points = Tuple{Float64, Float64}[(xs[i], ys[i]) for i in axes(xs, 1)]
push!(
plotdata,
PlotInc(
PGFPlotsX.Options(
"mark" => marker,
"color" => color,
(mod == "null" ? "" : "only marks") => nothing
),
Coordinates(points),
),
)
push!(plotdata, LegendEntry(mod))
end
fig = TikzPicture(@pgf Axis(
{
ymode = "log",
xlabel = "bbox calls",
ylabel = "subopt",
legend_pos = "north east",
legend_style = "font=\\footnotesize",
legend_cell_align = "left",
unbounded_coords = "jump",
title = title,
xmin = 0,
# xmax = 200,
ymin = 1e-16,
ymax = 1e6,
width = "8cm",
height = "6cm",
},
plotdata...,
))
return fig
end
function write_nullsteps(pb, tr, name)
xsnull, ysnull, xsser, ysser = extract_seriousnullsteps(pb, tr)
open(name, "w") do io
writedlm(io, ysnull)
end
return nothing
end