Skip to content

Commit

Permalink
Merge pull request #384 from JuliaReach/schillic/plots
Browse files Browse the repository at this point in the history
Revise plots for models
  • Loading branch information
schillic authored Apr 9, 2024
2 parents a81ed70 + 163b9d0 commit d250da2
Show file tree
Hide file tree
Showing 9 changed files with 86 additions and 75 deletions.
16 changes: 10 additions & 6 deletions models/ACC/ACC.jl
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ sol_tanh, sim_tanh = run(use_relu_controller=false);

# Script to plot the results:

function plot_helper(sol, sim, scenario)
function plot_helper(sol, sim)
F = overapproximate(flowpipe(sol), Zonotope)

fp_rel = linear_map(Matrix(d_rel'), F)
Expand All @@ -230,22 +230,26 @@ function plot_helper(sol, sim, scenario)
fp_safe = affine_map(Matrix(d_safe'), F, [D_default])
output_map_safe = x -> dot(d_safe, x) + D_default

fig = plot(leg=(0.4, 0.3), xlab="time")
fig = plot(leg=(0.4, 0.3))
plot!(fig, fp_rel; vars=(0, 1), c=:red, alpha=0.4)
plot!(fig, fp_safe; vars=(0, 1), c=:blue, alpha=0.4)
plot_simulation!(fig, sim; output_map=output_map_rel, color=:red, lab="Drel")
plot_simulation!(fig, sim; output_map=output_map_safe, color=:blue, lab="Dsafe")
## savefig("ACC-$scenario.png") # command to save the plot to a file
fig = DisplayAs.Text(DisplayAs.PNG(fig))
plot!(fig; xlab="time")
return fig
end;

# Plot the results:

fig = plot_helper(sol_relu, sim_relu, "ReLU")
fig = plot_helper(sol_relu, sim_relu)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "ACC-ReLU.png") # command to save the plot to a file

#-

fig = plot_helper(sol_tanh, sim_tanh, "tanh")
fig = plot_helper(sol_tanh, sim_tanh)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "ACC-tanh.png") # command to save the plot to a file

end #jl
nothing #jl
Expand Down
10 changes: 6 additions & 4 deletions models/Airplane/Airplane.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,21 @@ print_timed(res);

# Script to plot the results:

function plot_helper!(fig, vars)
function plot_helper(vars)
fig = plot()
plot!(fig, project(safe_states, vars); color=:lightgreen, lab="safe")
plot!(fig, project(initial_state(prob), vars); c=:cornflowerblue, alpha=1, lab="X₀")
plot!(fig, sol; vars=vars, color=:yellow, lab="")
lab_sim = falsification ? "simulation" : ""
plot_simulation!(fig, sim; vars=vars, color=:black, lab=lab_sim)
return fig
end;

# Plot the results:

vars = (2, 7)
fig = plot(xlab="s_y", ylab="ϕ", leg=:bottomleft)
fig = plot_helper!(fig, vars)
fig = plot_helper(vars)
plot!(fig; xlab="s_y", ylab="ϕ", leg=:bottomleft)
if falsification
xlims!(-0.01, 0.65)
ylims!(0.85, 1.01)
Expand All @@ -279,7 +281,7 @@ else
ylims!(-1.05, 1.05)
end
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig("Airplane-x2-x7.png") # command to save the plot to a file
## savefig(fig, "Airplane.png") # command to save the plot to a file

end #jl
nothing #jl
16 changes: 8 additions & 8 deletions models/AttitudeControl/AttitudeControl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,23 @@ print_timed(res);

# Script to plot the results:

function plot_helper!(fig, vars; show_simulation::Bool=true)
function plot_helper(vars)
fig = plot()
plot!(fig, project(unsafe_states, vars); color=:red, alpha=:0.2,
lab="unsafe", leg=:topleft)
plot!(fig, sol; vars=vars, color=:yellow, lab="")
plot!(fig, project(X₀, vars); c=:cornflowerblue, alpha=1, lab="X₀")
if show_simulation
plot_simulation!(fig, sim; vars=vars, color=:black, lab="")
end
fig = DisplayAs.Text(DisplayAs.PNG(fig))
plot_simulation!(fig, sim; vars=vars, color=:black, lab="")
return fig
end;

# Plot the results:

vars = (1, 2)
fig = plot(xlab="ω₁", ylab="ω₂")
fig = plot_helper!(fig, vars)
## savefig("AttitudeControl-x1-x2.png") # command to save the plot to a file
fig = plot_helper(vars)
plot!(fig; xlab="ω₁", ylab="ω₂")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "AttitudeControl.png") # command to save the plot to a file

end #jl
nothing #jl
Expand Down
8 changes: 5 additions & 3 deletions models/InvertedPendulum/InvertedPendulum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ print_timed(res);

function plot_helper()
vars = (0, 1)
fig = plot(ylab="θ")
fig = plot()
unsafe_states_projected = cartesian_product(Interval(0.5, 1.0),
project(unsafe_states, [vars[2]]))
plot!(fig, unsafe_states_projected; color=:red, alpha=:0.2, lab="unsafe")
Expand All @@ -189,13 +189,15 @@ function plot_helper()
end
lab_sim = falsification ? "simulation" : ""
plot_simulation!(fig, sim; vars=vars, color=:black, lab=lab_sim)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
plot!(fig; xlab="t", ylab="θ")
return fig
end;

# Plot the results:

fig = plot_helper()
## savefig("InvertedPendulum.png") # command to save the plot to a file
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "InvertedPendulum.png") # command to save the plot to a file

end #jl
nothing #jl
31 changes: 14 additions & 17 deletions models/InvertedTwoLinkPendulum/InvertedTwoLinkPendulum.jl
Original file line number Diff line number Diff line change
Expand Up @@ -244,40 +244,37 @@ sol_mr, sim_mr, prob_mr, spec_mr = run(less_robust_scenario=false);

# Script to plot the results:

function plot_helper!(fig, vars, sol, sim, prob, spec, scenario)
function plot_helper(vars, sol, sim, prob, spec)
safe_states = spec.ext
fig = plot()
plot!(fig, project(safe_states, vars); color=:lightgreen, lab="safe")
plot!(fig, sol; vars=vars, color=:yellow, lab="")
plot!(fig, project(initial_state(prob), vars); c=:cornflowerblue, alpha=1, lab="X₀")
lab_sim = falsification ? "simulation" : ""
plot_simulation!(fig, sim; vars=vars, color=:black, lab=lab_sim)
if falsification
plot!(leg=:topleft)
plot!(fig; leg=:topleft)
end
## Command to save the plot to a file:
## savefig("InvertedTwoLinkPendulum-$scenario-x$(vars[1])-x$(vars[2]).png")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
return fig
end;

# Plot the results:

vars=(3, 4)
fig = plot(xlab="θ₁'", ylab="θ₂'")
xlims!(-0.7, 1.7)
ylims!(-1.6, 1.5)
fig = plot_helper!(fig, vars, sol_lr, sim_lr, prob_lr, spec_lr, "less-robust")
fig = plot_helper(vars, sol_lr, sim_lr, prob_lr, spec_lr)
plot!(fig; xlab="θ₁'", ylab="θ₂'")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## Command to save the plot to a file:
## savefig(fig, "InvertedTwoLinkPendulum-less-robust.png")

#-

vars=(3, 4)
fig = plot(xlab="θ₁'", ylab="θ₂'")
if falsification
ylims!(-1.0, 1.5)
else
xlims!(-1.8, 1.5)
ylims!(-1.6, 1.5)
end
fig = plot_helper!(fig, vars, sol_mr, sim_mr, prob_mr, spec_mr, "more-robust")
fig = plot_helper(vars, sol_mr, sim_mr, prob_mr, spec_mr)
plot!(fig; xlab="θ₁'", ylab="θ₂'")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## Command to save the plot to a file:
## savefig(fig, "InvertedTwoLinkPendulum-more-robust.png")

end #jl
nothing #jl
16 changes: 8 additions & 8 deletions models/Quadrotor/Quadrotor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -172,23 +172,23 @@ print_timed(res);

# Script to plot the results:

function plot_helper!(fig, vars; show_simulation::Bool=true)
function plot_helper(vars)
goal_states_projected = cartesian_product(Interval(0, T),
project(goal_states, [vars[2]]))
fig = plot()
plot!(fig, goal_states_projected; color=:cyan, lab="goal")
plot!(fig, sol; vars=vars, color=:yellow, lab="")
if show_simulation
plot_simulation!(fig, sim; vars=vars, color=:black, lab="")
end
fig = DisplayAs.Text(DisplayAs.PNG(fig))
plot_simulation!(fig, sim; vars=vars, color=:black, lab="")
return fig
end;

# Plot the results:

vars = (0, 3)
fig = plot(xlab="t", ylab="x₃")
fig = plot_helper!(fig, vars)
## savefig("Quadrotor-t-x3.png") # command to save the plot to a file
fig = plot_helper(vars)
plot!(fig; xlab="t", ylab="x₃")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "Quadrotor.png") # command to save the plot to a file

end #jl
nothing #jl
Expand Down
23 changes: 12 additions & 11 deletions models/SpacecraftDocking/SpacecraftDocking.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,28 +142,29 @@ print_timed(res);

# Script to plot the results:

function plot_helper!(fig, vars; show_simulation::Bool=true)
function plot_helper(vars)
fig = plot()
plot!(fig, sol; vars=vars, color=:yellow, lab="")
plot!(fig, project(X₀, vars); c=:cornflowerblue, alpha=0.7, lab="X₀")
if show_simulation
plot_simulation!(fig, sim; vars=vars, color=:black, lab="")
end
fig = DisplayAs.Text(DisplayAs.PNG(fig))
plot_simulation!(fig, sim; vars=vars, color=:black, lab="")
return fig
end;

# Plot the results:

vars = (1, 2)
fig = plot(xlab="x", ylab="y")
fig = plot_helper!(fig, vars)
## savefig("SpacecraftDocking-x-y.png") # command to save the plot to a file
fig = plot_helper(vars)
plot!(fig; xlab="x", ylab="y")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "SpacecraftDocking-x-y.png") # command to save the plot to a file

#-

vars = (3, 4)
fig = plot(xlab="x'", ylab="y'")
fig = plot_helper!(fig, vars)
## savefig("SpacecraftDocking-x'-y'.png") # command to save the plot to a file
fig = plot_helper(vars)
plot!(fig; xlab="x'", ylab="y'")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "SpacecraftDocking-x'-y'.png") # command to save the plot to a file

end #jl
nothing #jl
Expand Down
26 changes: 15 additions & 11 deletions models/TORA/TORA.jl
Original file line number Diff line number Diff line change
Expand Up @@ -256,27 +256,30 @@ solz = overapproximate(sol_r, Zonotope);

# Script to plot the results:

function plot_helper1!(fig, vars)
function plot_helper1(vars)
fig = plot()
plot!(fig, project(safe_states, vars); color=:lightgreen, lab="safe")
plot!(fig, solz; vars=vars, color=:yellow, lab="")
plot!(fig, project(X₀1, vars); c=:cornflowerblue, alpha=1, lab="X₀")
plot_simulation!(fig, sim_r; vars=vars, color=:black, lab="")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
return fig
end;

# Plot the results:

vars = (1, 2)
fig = plot(xlab="x₁", ylab="x₂")
fig = plot_helper1!(fig, vars)
## savefig("TORA-ReLU-x1-x2.png") # command to save the plot to a file
fig = plot_helper1(vars)
plot!(fig; xlab="x₁", ylab="x₂")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "TORA-ReLU-x1-x2.png") # command to save the plot to a file

#-

vars = (3, 4)
fig = plot(xlab="x₃", ylab="x₄")
fig = plot_helper1!(fig, vars)
## savefig("TORA-ReLU-x3-x4.png") # command to save the plot to a file
fig = plot_helper1(vars)
plot!(fig; xlab="x₃", ylab="x₄")
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig(fig, "TORA-ReLU-x3-x4.png") # command to save the plot to a file

#-

Expand All @@ -286,11 +289,12 @@ fig = plot_helper1!(fig, vars)

function plot_helper2(sol, sim)
vars = (1, 2)
fig = plot(xlab="x₁", ylab="x₂")
fig = plot()
plot!(fig, project(goal_states, vars); color=:cyan, lab="goal")
plot!(fig, sol; vars=vars, color=:yellow, lab="")
plot!(fig, project(X₀2, vars); c=:cornflowerblue, alpha=1, lab="X₀")
plot_simulation!(fig, sim; vars=vars, color=:black, lab="")
plot!(fig; xlab="x₁", ylab="x₂")
return fig
end;

Expand All @@ -302,7 +306,7 @@ lens!(fig, [-0.785, -0.735], [-0.47, -0.41]; inset=(1, bbox(0.2, 0.4, 0.2, 0.2))
lens!(fig, [0.0, 0.25], [-0.85, -0.7]; inset=(1, bbox(0.6, 0.4, 0.2, 0.2)),
lc=:black, xticks=[0, 0.2], yticks=[-0.8, -0.7], subplot=3)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig("TORA-ReLUtanh-x1-x2.png") # command to save the plot to a file
## savefig(fig, "TORA-ReLUtanh.png") # command to save the plot to a file

#-

Expand All @@ -312,7 +316,7 @@ lens!(fig, [-0.785, -0.735], [-0.47, -0.41]; inset=(1, bbox(0.2, 0.4, 0.2, 0.2))
lens!(fig, [0.09, 0.22], [-0.9, -0.8]; inset=(1, bbox(0.6, 0.4, 0.2, 0.2)),
lc=:black, xticks=[0.1, 0.2], yticks=[-0.9, -0.8], subplot=3)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig("TORA-sigmoid-x1-x2.png") # command to save the plot to a file
## savefig(fig, "TORA-sigmoid.png") # command to save the plot to a file

end #jl
nothing #jl
Expand Down
15 changes: 8 additions & 7 deletions models/Unicycle/Unicycle.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ Tint = try convert(Int, T) catch; T end;

# Script to plot the results:

function plot_helper!(fig, vars; show_simulation::Bool=true)
function plot_helper(vars; show_simulation::Bool=true)
fig = plot()
plot!(fig, project(goal_set, vars); color=:cyan, alpha=0.5, lab="goal")
plot!(fig, solz; vars=vars, color=:yellow, lab="")
plot!(fig, project(X₀, vars); color=:cornflowerblue, alpha=1, lab="X₀")
Expand All @@ -173,26 +174,26 @@ end;
# Plot the results:

vars = (1, 2)
fig = plot(xlab="x₁", ylab="x₂", leg=:bottomleft)
fig = plot_helper!(fig, vars)
fig = plot_helper(vars)
plot!(fig; xlab="x₁", ylab="x₂", leg=:bottomleft)
lens!(fig, [9.49, 9.56], [-4.51, -4.44]; inset=(1, bbox(0.65, 0.05, 0.25, 0.25)),
lc=:black, xticks=[9.5, 9.55], yticks=[-4.5, -4.45], subplot=2)
lens!(fig, [0.3, 0.7], [-0.25, 0.25]; inset=(1, bbox(0.1, 0.3, 0.25, 0.25)),
lc=:black, xticks=[0.4, 0.6], yticks=[-0.2, 0.2], subplot=3)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig("Unicycle-x1-x2.png") # command to save the plot to a file
## savefig(fig, "Unicycle-x1-x2.png") # command to save the plot to a file

#-

vars = (3, 4)
fig = plot(xlab="x₃", ylab="x₄", leg=:bottom)
fig = plot_helper!(fig, vars; show_simulation=false)
fig = plot_helper(vars; show_simulation=false)
plot!(fig; xlab="x₃", ylab="x₄", leg=:bottom)
lens!(fig, [2.09, 2.12], [1.495, 1.515]; inset=(1, bbox(0.72, 0.54, 0.25, 0.25)),
lc=:black, xticks=[2.1, 2.11], yticks=[1.5, 1.51], subplot=2)
lens!(fig, [-0.1, 0.03], [-0.4, -0.15]; inset=(1, bbox(0.1, 0.1, 0.25, 0.25)),
lc=:black, xticks=[-0.08, 0], yticks=[-0.3, -0.2], subplot=3)
fig = DisplayAs.Text(DisplayAs.PNG(fig))
## savefig("Unicycle-x3-x4.png") # command to save the plot to a file
## savefig(fig, "Unicycle-x3-x4.png") # command to save the plot to a file

end #jl
nothing #jl
Expand Down

0 comments on commit d250da2

Please sign in to comment.