Build plots with PGFPlots(X.jl)
for all your optimal algorithms.
This repository is a work in progress. Check out the docs for more information.
Draw points, lines, sets, arrows in the plane.
xmin, xmax = -2, 2
ymin, ymax = -1.5, 1.5
axisbounds = (;xmin, xmax, ymin, ymax)
axis = baseaxis(axisbounds)
add_arrow!(axis, [-1, -1], [0, 1])
add_surface!(axis, [[0, 0], [1, 0], [0.5, 1]])
add_point!(axis, [-1, 1]; name = "y")
add_text!(axis, [-1, -1], "\nabla f(x)")
add_curve!()
add_segment!()
add_contour!()
add_level!()
add_iterates!()
add_legend!()
Plot one quantity (e.g. suboptimality) versus another (e.g. iterations).
Check the docstring of plot_curves
for options.
fig = plot_curves(
Dict(
L"f(x_k) - f^\star" => (1:30, [1/k for k in 1:30]),
L"f(x_k)" => (1:30, [1/k + 3.0 for k in 1:30]),
), get_abscisses, get_ordinates;
xlabel=raw"iteration $k$", ylabel=raw"",
)
Save several plots in one pdf file.
axis = []
push!(axis, plot_curves(
Dict(
L"f(x_k) - f^\star" => (1:30, [1/k for k in 1:30]),
), get_abscisses, get_ordinates;
xlabel=raw"iteration $k$", ylabel=raw"",
))
push!(axis, plot_curves(
Dict(
L"f(x_k)" => (1:30, [1/k + 3.0 for k in 1:30]),
), get_abscisses, get_ordinates;
xlabel=raw"iteration $k$", ylabel=raw"",
ymode="normal",
))
fig = TikzDocument(axis...)
Save the figure
savefig(fig, "nullpoints_convex"; FIGFOLDER = ".", include_preamble = false)
using PlotsOptim
using LinearAlgebra
f(x) = norm(x, 2)^2
x = [2, 2]
d1 = [4, 4]
d2 = [-4, 4]
model_to_functions = OrderedDict{String, Function}(
"f tangent" => t -> abs( f(x+t*d1) - f(x) ),
"f rand" => t -> abs( f(x+t*d2) - f(x) ),
)
model_to_curves = build_logcurves(model_to_functions)
## computing slopes
for (model, (xs, ys)) in model_to_curves
@show model
xsclean, ysclean = remove_small_functionvals(xs, ys)
β, residual= build_affinemodel(xsclean, ysclean)
@show β, residual
push!(model_to_functions, "$model reg" => t -> exp(β[2] + β[1]*log(t)))
@show check_curveslope(curve, 2)
end
plot_taylordev(build_logcurves(model_to_functions))
plot_taylordev(model_to_functions)
toydata = PlotsOptim.perfprofile_toydata()
plot_perfprofile(toydata, "My performance profile")