|
2 | 2 | # Trajectory Plot
|
3 | 3 | ################################################################################
|
4 | 4 |
|
5 |
| -function plot_traj!(model::AbstractGameModel, traj::Traj; plt=plot()) |
6 |
| - plot!(plt, legend=false, aspect_ratio=:equal) |
| 5 | +# function plot_traj!(model::AbstractGameModel, traj::Traj; plt=plot()) |
| 6 | +# plot!(plt, legend=false, aspect_ratio=:equal) |
| 7 | +# N = length(traj) |
| 8 | +# for i = 1:model.p |
| 9 | +# xi = [Algames.state(traj[k])[model.pz[i][1]] for k=1:N] |
| 10 | +# yi = [Algames.state(traj[k])[model.pz[i][2]] for k=1:N] |
| 11 | +# plot!(xi, yi, label=false) |
| 12 | +# scatter!(xi, yi) |
| 13 | +# end |
| 14 | +# display(plt) |
| 15 | +# return nothing |
| 16 | +# end |
| 17 | + |
| 18 | +@recipe function recipe_traj(model::AbstractGameModel, traj::Traj) |
7 | 19 | N = length(traj)
|
| 20 | + x = [] |
| 21 | + y = [] |
8 | 22 | for i = 1:model.p
|
9 | 23 | xi = [Algames.state(traj[k])[model.pz[i][1]] for k=1:N]
|
10 | 24 | yi = [Algames.state(traj[k])[model.pz[i][2]] for k=1:N]
|
11 |
| - plot!(xi, yi, label=false) |
12 |
| - scatter!(xi, yi) |
| 25 | + push!(x, xi) |
| 26 | + push!(y, yi) |
13 | 27 | end
|
14 |
| - display(plt) |
15 |
| - return nothing |
| 28 | + aspect_ratio --> :equal |
| 29 | + xguide --> "X" |
| 30 | + yguide --> "Y" |
| 31 | + title --> "Trajectories" |
| 32 | + legend --> :false |
| 33 | + seriestype --> [fill(:scatter, model.p)... fill(:path, model.p)...] |
| 34 | + return [x, x], [y, y] |
16 | 35 | end
|
17 | 36 |
|
| 37 | + |
18 | 38 | ################################################################################
|
19 | 39 | # Constraint Violation Plot
|
20 | 40 | ################################################################################
|
21 | 41 |
|
22 |
| -function plot_violation!(stats::Statistics; plt=plot(), lw::T=5.0) where {T} |
23 |
| - plot!(plt, |
24 |
| - size=(500,500), |
25 |
| - layout=(1,1,)) |
26 |
| - iter = stats.iter |
27 |
| - dyn = log.(10, max.(1e-10, [stats.dyn_vio[i].max for i=1:iter])) |
| 42 | +# function plot_violation!(stats::Statistics; plt=plot(), lw::T=5.0) where {T} |
| 43 | +# plot!(plt, |
| 44 | +# size=(500,500), |
| 45 | +# layout=(1,1,)) |
| 46 | +# iter = stats.iter |
| 47 | +# dyn = log.(10, max.(1e-10, [stats.dyn_vio[i].max for i=1:iter])) |
| 48 | +# con = log.(10, max.(1e-10, [stats.con_vio[i].max for i=1:iter])) |
| 49 | +# sta = log.(10, max.(1e-10, [stats.sta_vio[i].max for i=1:iter])) |
| 50 | +# opt = log.(10, max.(1e-10, [stats.opt_vio[i].max for i=1:iter])) |
| 51 | +# y_min = minimum([dyn; con; sta; opt]) |
| 52 | +# y_max = maximum([dyn; con; sta; opt]) |
| 53 | +# # Set up plot |
| 54 | +# plot!(plt[1,1], |
| 55 | +# legend=:bottomleft, |
| 56 | +# xlabel="Outer Loop Iterations", |
| 57 | +# ylabel="log(cons. vio.)", |
| 58 | +# title="Constraint Violation") |
| 59 | +# # Add curves |
| 60 | +# plot!(plt[1,1], dyn, linewidth=lw, label="dyn", legend=:bottomleft) |
| 61 | +# plot!(plt[1,1], con, linewidth=lw, label="con", legend=:bottomleft) |
| 62 | +# plot!(plt[1,1], sta, linewidth=lw, label="sta", legend=:bottomleft) |
| 63 | +# plot!(plt[1,1], opt, linewidth=lw, label="opt", legend=:bottomleft) |
| 64 | +# # Add rectangles |
| 65 | +# plot_epochs!(plt, y_min, y_max, stats.outer_iter) |
| 66 | +# |
| 67 | +# display(plt) |
| 68 | +# return nothing |
| 69 | +# end |
| 70 | +# |
| 71 | +# function plot_epochs!(plt, y_min::T, y_max::T, epochs::Vector{Int}) where {T} |
| 72 | +# rectangle(w, h, x, y) = Shape(x .+ [0,w,w,0], y .+ [0,0,h,h]) |
| 73 | +# i_start = 1 |
| 74 | +# i_end = -1 |
| 75 | +# for k = 1:epochs[end] |
| 76 | +# i_end = findlast(x -> x==k, epochs ) |
| 77 | +# plot!(rectangle(i_end-i_start,y_max-y_min,i_start,y_min), opacity=.1, label=false) |
| 78 | +# i_start = i_end + 1 |
| 79 | +# end |
| 80 | +# return nothing |
| 81 | +# end |
| 82 | + |
| 83 | +@recipe function recipe_violation(stats::Statistics) |
| 84 | + rectangle(w, h, x, y) = Shape(x .+ [0,w,w,0], y .+ [0,0,h,h]) |
| 85 | + |
| 86 | + iter = stats.iter |
| 87 | + dyn = log.(10, max.(1e-10, [stats.dyn_vio[i].max for i=1:iter])) |
28 | 88 | con = log.(10, max.(1e-10, [stats.con_vio[i].max for i=1:iter]))
|
29 | 89 | sta = log.(10, max.(1e-10, [stats.sta_vio[i].max for i=1:iter]))
|
30 | 90 | opt = log.(10, max.(1e-10, [stats.opt_vio[i].max for i=1:iter]))
|
31 | 91 | y_min = minimum([dyn; con; sta; opt])
|
32 | 92 | y_max = maximum([dyn; con; sta; opt])
|
33 |
| - # Set up plot |
34 |
| - plot!(plt[1,1], |
35 |
| - legend=:bottomleft, |
36 |
| - xlabel="Outer Loop Iterations", |
37 |
| - ylabel="log(cons. vio.)", |
38 |
| - title="Constraint Violation") |
39 |
| - # Add curves |
40 |
| - plot!(plt[1,1], dyn, linewidth=lw, label="dyn", legend=:bottomleft) |
41 |
| - plot!(plt[1,1], con, linewidth=lw, label="con", legend=:bottomleft) |
42 |
| - plot!(plt[1,1], sta, linewidth=lw, label="sta", legend=:bottomleft) |
43 |
| - plot!(plt[1,1], opt, linewidth=lw, label="opt", legend=:bottomleft) |
44 |
| - # Add rectangles |
45 |
| - plot_epochs!(plt, y_min, y_max, stats.outer_iter) |
46 |
| - |
47 |
| - display(plt) |
48 |
| - return nothing |
49 |
| -end |
50 | 93 |
|
51 |
| -function plot_epochs!(plt, y_min::T, y_max::T, epochs::Vector{Int}) where {T} |
52 |
| - rectangle(w, h, x, y) = Shape(x .+ [0,w,w,0], y .+ [0,0,h,h]) |
| 94 | + epochs = stats.outer_iter |
53 | 95 | i_start = 1
|
54 | 96 | i_end = -1
|
55 |
| - for k = 1:epochs[end] |
| 97 | + epo = [] |
| 98 | + N_epochs = epochs[end] |
| 99 | + for k = 1:N_epochs |
56 | 100 | i_end = findlast(x -> x==k, epochs )
|
57 |
| - plot!(rectangle(i_end-i_start,y_max-y_min,i_start,y_min), opacity=.1, label=false) |
| 101 | + push!(epo, Vector(range(i_start, stop = i_end, length = iter))) |
58 | 102 | i_start = i_end + 1
|
59 | 103 | end
|
60 |
| - return nothing |
| 104 | + |
| 105 | + size --> (500,500) |
| 106 | + legend --> :bottomleft |
| 107 | + ylims --> [y_min, y_max] |
| 108 | + xguide --> "Outer Loop Iterations" |
| 109 | + yguide --> "log(cons. vio.)" |
| 110 | + title --> "Constraint Violation" |
| 111 | + linewidth --> [zeros(N_epochs)... 5.0 5.0 5.0 5.0] |
| 112 | + label --> [fill("", N_epochs)... "dyn" "con" "sta" "opt" ] |
| 113 | + fillrange --> [[fill(y_min*ones(90), N_epochs)... dyn con sta opt ] |
| 114 | + [fill(zeros(iter), N_epochs)... zeros(iter) zeros(iter) zeros(iter) zeros(iter) ]] |
| 115 | + fillalpha --> [fill(0.1, N_epochs)... 0.0 0.0 0.0 0.0] |
| 116 | + |
| 117 | + y = fill(y_max*ones(iter), N_epochs) |
| 118 | + x = Vector(1:iter) |
| 119 | + return [epo..., x, x, x, x], [y..., dyn, con, sta, opt] |
61 | 120 | end
|
0 commit comments