Compare two graphs
Before solving on a bigger graph, ask whether it can pay off at all. compare answers for every system at once, without solving, and the answer depends on the template: on the five graphs of (Debauche et al., 2023), a five-node graph can beat the common graph for quadratic forms, and never for the copositive templates. Comparing graphs explains the method, and this page runs it.
using PathCompleteCertificates
import Clarabel
using Plots
const OPTIMIZER = Clarabel.OptimizerFive graphs
The graphs of the paper, on two modes, built with empty_graph and add_edge!. The paper names the nodes a to e, and so does this page.
function build(n_nodes, edges)
graph = empty_graph(n_nodes)
for (a, b, mode) in edges
add_edge!(graph, a, b, mode)
end
return graph
end
G0 = build(1, [(1, 1, 1), (1, 1, 2)])
G1 = build(
5,
[
(1, 2, 1),
(2, 1, 1),
(1, 3, 1),
(3, 1, 2),
(1, 4, 2),
(4, 1, 1),
(1, 5, 2),
(5, 1, 2),
],
)
G2 = build(
4,
[
(1, 3, 2),
(1, 4, 2),
(2, 1, 1),
(2, 2, 1),
(3, 3, 2),
(3, 4, 2),
(4, 2, 1),
(4, 1, 1),
],
)
G3 = build(
5,
[
(1, 2, 1),
(1, 5, 2),
(1, 4, 1),
(2, 3, 1),
(2, 4, 2),
(3, 4, 1),
(3, 4, 2),
(4, 3, 2),
(4, 2, 2),
(4, 5, 1),
(5, 1, 1),
(5, 1, 2),
],
)
G4 = build(
5,
[
(1, 2, 1),
(2, 4, 1),
(3, 2, 1),
(4, 3, 1),
(4, 5, 1),
(5, 1, 1),
(1, 4, 2),
(1, 3, 2),
(2, 1, 2),
(3, 2, 2),
(4, 5, 2),
(5, 1, 2),
],
)
GRAPHS = [G0, G1, G2, G3, G4]
NAMES = ["G0", "G1", "G2", "G3", "G4"]
node_name(k) = string('a' + k - 1)Blue edges read mode 1, orange edges mode 2.
All five are path-complete. G0, G3 and G4 are also complete and co-complete, G1 and G2 neither:
satisfying(predicate) = [name for (name, g) in zip(NAMES, GRAPHS) if predicate(g, 1:2)]
(
path_complete = satisfying(is_path_complete),
complete = satisfying(is_complete),
co_complete = satisfying(is_co_complete),
)(path_complete = ["G0", "G1", "G2", "G3", "G4"], complete = ["G0", "G3", "G4"], co_complete = ["G0", "G3", "G4"])One comparison
compare(G1, G2) asks whether G2 is at least as good as G1. Given templates and the system they will be read on, it also says for which of them the order holds. The system is the paper's, positive, so that the copositive templates apply. Divided by 10 and rounded, it is the running example of the manual.
A = [[1.5519 0.44737; 7.6412 7.4716], [0.47501 9.1755; 1.8955 0.18502]]
system = switched_system(A)
problem = StabilityProblem(system)
QUADRATIC = QuadraticTemplate()
TEMPLATES = [
"quadratic" => QUADRATIC,
"linear copositive" => LinearCopositiveTemplate(),
"dual copositive" => DualCopositiveTemplate(),
]A comparison, read by name: the lifts whose lifted first graph simulates the second, and the templates for which the order is proved.
compared(G, H) = compare(G, H; templates = last.(TEMPLATES), system, optimizer = OPTIMIZER)
lift_name(lift) =
lift isa MinLift ? "min" :
lift isa MaxLift ? "max" : lift isa SumLift ? "sum" : string(nameof(typeof(lift)))
outcome(c) = (
simulating = lift_name.(first.(simulations(c))),
proved_for = [
name for (name, template) in TEMPLATES if any(t -> t === template, templates(c))
],
)
c12 = compared(G1, G2)
outcome(c12)(simulating = ["min", "max", "sum"], proved_for = ["quadratic", "linear copositive", "dual copositive"])No plain simulation exists, since G2 has a self-loop and G1 has none (Debauche et al., 2023; Ex. 1). But the min, max and sum lifts of G1 simulate G2, so G2 is at least as good for the three templates.
The sum lift's simulation is also a recipe: a nonnegative integer matrix $C$ such that $W = C\,V$ is a certificate on G2 whenever $V$ is one on G1 (Debauche et al., 2023; Thm. 2). Read row by row:
C = Dict(simulations(c12))[SumLift()]
combination(row) = join(
[(c == 1 ? "" : "$c·") * "V_" * node_name(g) for (g, c) in enumerate(row) if c > 0],
" + ",
)
["W_" * node_name(h) * " = " * combination(C[h, :]) for h in 1:n_nodes(G2)]4-element Vector{String}:
"W_a = V_a + V_c"
"W_b = V_a + V_b"
"W_c = V_a + V_e"
"W_d = V_a + V_d"The answer depends on the template
G4 against the common graph: its min and max lifts simulate G0, its sum lift does not. So G4 gives no better certificate than G0 for the templates for which the min or the max lift is valid, here the two copositive ones, but may for the quadratic template:
c40 = compared(G4, G0)
outcome(c40)(simulating = ["min", "max"], proved_for = ["linear copositive", "dual copositive"])G3, with as many nodes and edges as G4, is no better than G0 for any template for which the sum lift is valid. Its sum lift simulates G0 with a single row, $2V_a + V_b + V_c + 2V_d + 2V_e$, which builds a certificate on G0 from any certificate on G3.
c30 = compared(G3, G0)
Dict(simulations(c30))[SumLift()]1×5 Matrix{Int64}:
2 1 1 2 2The rates agree
The orders hold for every system, and on the paper's system the certified rates follow them. The quadratic rate drops from G1 to G2, is the same on G3 as on G0, and is lower on G4. The copositive rates are the same on G0, G3 and G4.
# The rates are near 9, so the bisection starts from 100 instead of doubling from 1.
bound(template, graph) =
certify(template, graph, problem; optimizer = OPTIMIZER, initial_upper = 100.0)
certified = Dict(
name => [bound(template, g).rate for g in GRAPHS] for (name, template) in TEMPLATES
)Dict{String, Vector{Float64}} with 3 entries:
"quadratic" => [9.5868, 9.01607, 8.68808, 9.5868, 9.48858]
"dual copositive" => [13.048, 11.5823, 9.23336, 13.048, 13.048]
"linear copositive" => [9.26959, 9.1711, 8.7019, 9.26959, 9.26959]figure = plot(;
xticks = (1:5, NAMES),
ylabel = "certified rate",
legend = :outerright,
size = (800, 420),
title = "five graphs, three templates",
)
for (name, _) in TEMPLATES
plot!(
figure,
1:5,
certified[name];
marker = :circle,
markersize = 6,
lw = 2,
label = name,
)
end
figurecompare never builds the min, max and sum lifts, which grow exponentially (see Comparing graphs). Improve my bound builds a better graph instead of comparing given ones.
This page was generated using Literate.jl.