Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change to use lq results for plot #119

Open
wants to merge 179 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
179 commits
Select commit Hold shift + click to select a range
d62549d
change to use lq results for plot
hmzh-khn Sep 15, 2023
1a0d5b8
change file
hmzh-khn Sep 15, 2023
c808a22
adjust measurement/meas. model details
hmzh-khn Sep 15, 2023
fcca4be
label changes
hmzh-khn Sep 15, 2023
19a5487
bug 1
hmzh-khn Sep 15, 2023
b8b1ff3
make LQ sim longer
hmzh-khn Sep 15, 2023
d938505
Remove step annotations
hmzh-khn Sep 15, 2023
9fd4763
slight modificationsgit st
hmzh-khn Sep 16, 2023
ce069db
typo 1
hmzh-khn Sep 16, 2023
be325a3
change file for non-lq silq
hmzh-khn Sep 16, 2023
1cd5761
change file for non-lq silq
hmzh-khn Sep 16, 2023
29cd6ba
Fix label
hmzh-khn Sep 16, 2023
7057dbd
Fix label 2
hmzh-khn Sep 16, 2023
63760e6
Fix label 3
hmzh-khn Sep 16, 2023
c98f3ac
Fix label 4
hmzh-khn Sep 16, 2023
4ff6765
Fix label 5
hmzh-khn Sep 16, 2023
0ad97ae
Fix label 6
hmzh-khn Sep 16, 2023
1056f4c
Fix label 7
hmzh-khn Sep 16, 2023
129be74
Fix label 8
hmzh-khn Sep 16, 2023
e519091
generate the longer Ts
hmzh-khn Sep 16, 2023
4d3cd53
generate the longer Ts 1
hmzh-khn Sep 16, 2023
0a77df3
fix label 9
hmzh-khn Sep 16, 2023
af0fd42
fix label 10
hmzh-khn Sep 16, 2023
af0ff42
fix label 11
hmzh-khn Sep 16, 2023
7260d34
fix label 12
hmzh-khn Sep 16, 2023
4746786
Make plot changes from review
hmzh-khn Sep 20, 2023
a024f71
more changes
hmzh-khn Sep 20, 2023
7e48456
bug fix 1
hmzh-khn Sep 20, 2023
25ee6be
bug fix 2
hmzh-khn Sep 20, 2023
7f4f8bd
Add insets
hmzh-khn Sep 21, 2023
c1195ee
Add insets 1
hmzh-khn Sep 21, 2023
5f99112
Add insets 2
hmzh-khn Sep 21, 2023
fb5df76
Add insets 3
hmzh-khn Sep 21, 2023
cadbb28
Add insets 4
hmzh-khn Sep 21, 2023
9c10ec7
Add insets 5
hmzh-khn Sep 21, 2023
f211d3d
Add insets 6
hmzh-khn Sep 21, 2023
3789013
Add insets 7
hmzh-khn Sep 21, 2023
0967a8e
Add insets 8
hmzh-khn Sep 21, 2023
8894d0b
Add insets 9
hmzh-khn Sep 21, 2023
beda5f4
Add insets 10
hmzh-khn Sep 21, 2023
ae2997c
Add insets 11
hmzh-khn Sep 21, 2023
8ce4120
Add insets 12
hmzh-khn Sep 21, 2023
0e06bdf
Add insets 13
hmzh-khn Sep 21, 2023
d1d5a67
Add insets 14
hmzh-khn Sep 21, 2023
f9e4de1
Add insets 15
hmzh-khn Sep 21, 2023
ed27eda
Add insets 15
hmzh-khn Sep 21, 2023
2f25cf5
Add insets 16
hmzh-khn Sep 21, 2023
ce612a6
Add insets 17
hmzh-khn Sep 21, 2023
eebb880
Add insets 18
hmzh-khn Sep 21, 2023
1614d19
Add insets 19
hmzh-khn Sep 21, 2023
521fa74
Add insets 20
hmzh-khn Sep 21, 2023
c83c148
Add insets 21
hmzh-khn Sep 21, 2023
575091a
Add insets 22
hmzh-khn Sep 21, 2023
252918f
Add insets 23
hmzh-khn Sep 21, 2023
21ba6d8
Add insets 24
hmzh-khn Sep 21, 2023
fe3de6d
Add insets 25
hmzh-khn Sep 21, 2023
6c0b070
Add insets 26
hmzh-khn Sep 21, 2023
67c7221
Add insets 27
hmzh-khn Sep 21, 2023
db3aab9
Add insets 28
hmzh-khn Sep 21, 2023
3b7a0c0
Add insets 29
hmzh-khn Sep 21, 2023
4b30ba6
Add insets 20
hmzh-khn Sep 21, 2023
3157796
Add insets 30
hmzh-khn Sep 21, 2023
c7343a7
Add insets 31
hmzh-khn Sep 21, 2023
6346298
Add insets 32
hmzh-khn Sep 21, 2023
f5bcd84
Add insets 33
hmzh-khn Sep 21, 2023
68737e5
Add insets 34
hmzh-khn Sep 21, 2023
b872266
Add insets 35
hmzh-khn Sep 21, 2023
7d4308e
Add insets 36
hmzh-khn Sep 21, 2023
69286a4
Add insets 36
hmzh-khn Sep 21, 2023
0d4b21f
Add insets 36
hmzh-khn Sep 21, 2023
7897a83
Add insets 37
hmzh-khn Sep 21, 2023
06490ad
Add insets 39
hmzh-khn Sep 21, 2023
ebac726
Add insets 40
hmzh-khn Sep 21, 2023
ecb3b03
Add insets 40
hmzh-khn Sep 21, 2023
836498f
Add insets 41
hmzh-khn Sep 21, 2023
07e5ca5
Fix timing script.
hmzh-khn Sep 21, 2023
bb897c4
Fix timing script.
hmzh-khn Sep 21, 2023
62f41d5
Switch to non-lQ SILQGames plots 2
hmzh-khn Sep 21, 2023
0eb07a4
change silq plots
hmzh-khn Sep 21, 2023
fe2d8b2
change silq plots 2
hmzh-khn Sep 21, 2023
27de4f6
change silq plots 3
hmzh-khn Sep 21, 2023
02b15fc
change silq plots 4
hmzh-khn Sep 21, 2023
9c6a113
change silq plots 5
hmzh-khn Sep 21, 2023
dd964bb
change silq plots 5
hmzh-khn Sep 21, 2023
3286194
change silq plots 6
hmzh-khn Sep 21, 2023
b2a725b
change silq plots 6
hmzh-khn Sep 21, 2023
d0d37a8
change silq plots 6
hmzh-khn Sep 21, 2023
4ea01e1
change silq plots 10
hmzh-khn Sep 21, 2023
25b5214
change silq plots 11
hmzh-khn Sep 21, 2023
dc4ce67
change silq plots 11
hmzh-khn Sep 21, 2023
c7f41ae
change silq plots 12
hmzh-khn Sep 21, 2023
632df4f
change silq plots 13
hmzh-khn Sep 21, 2023
7dec0f9
change silq plots 14
hmzh-khn Sep 21, 2023
8ce96c7
change silq plots 15
hmzh-khn Sep 21, 2023
a5bc601
change silq plots 15
hmzh-khn Sep 21, 2023
6f68e1d
change silq plots 17
hmzh-khn Sep 21, 2023
b25729c
change silq plots 18
hmzh-khn Sep 21, 2023
2130ae8
change silq plots 19
hmzh-khn Sep 21, 2023
12e0a52
change silq plots 20
hmzh-khn Sep 21, 2023
ae0ff70
change silq plots 21
hmzh-khn Sep 21, 2023
e24b4f1
change for generation of pass
hmzh-khn Sep 22, 2023
ddf9ece
undo
hmzh-khn Sep 22, 2023
3c5e2ce
plot changes
hmzh-khn Sep 25, 2023
22fcc4c
plot changes 1
hmzh-khn Sep 25, 2023
34e393d
Correct regularization in cost.
hmzh-khn Sep 25, 2023
55815f2
redo plot
hmzh-khn Sep 25, 2023
4bcd34d
redo plot 2
hmzh-khn Sep 25, 2023
bd2c53d
Final changes
hmzh-khn Sep 25, 2023
23d7915
relabel
hmzh-khn Sep 25, 2023
a9d3499
relabel 2
hmzh-khn Sep 25, 2023
fe6e67d
relabel 3
hmzh-khn Sep 25, 2023
6f99d5b
merging debug remove and compute timing prints
hmzh-khn Sep 28, 2023
0c4b401
merging debug remove and compute timing prints 2
hmzh-khn Sep 28, 2023
0d7bdc0
merging debug remove and compute timing prints 3
hmzh-khn Sep 28, 2023
e9221d1
merging debug remove and compute timing prints 4
hmzh-khn Sep 28, 2023
34f6cd7
merging debug remove and compute timing prints 5
hmzh-khn Sep 28, 2023
5ccd086
merging debug remove and compute timing prints 6
hmzh-khn Sep 28, 2023
4f1d587
merging debug remove and compute timing prints 6
hmzh-khn Sep 28, 2023
cac1e5d
merging debug remove and compute timing prints 7
hmzh-khn Sep 28, 2023
9ec4a34
merging debug remove and compute timing prints 9
hmzh-khn Sep 28, 2023
711e2fd
Adjust convergence plot
hmzh-khn Sep 28, 2023
95eb9e5
Adjust convergence plot 2
hmzh-khn Sep 28, 2023
42e8a8e
Adjust convergence plot 3
hmzh-khn Sep 28, 2023
ec9997b
Adjust convergence plot 4
hmzh-khn Sep 28, 2023
243fd5e
Adjust convergence plot 5
hmzh-khn Sep 28, 2023
c83ea9f
Adjust convergence plot 6
hmzh-khn Sep 28, 2023
06124e3
Adjust convergence plot 7
hmzh-khn Sep 28, 2023
46431b4
Adjust convergence plot 8
hmzh-khn Sep 28, 2023
9aaf227
Adjust convergence plot 9
hmzh-khn Sep 28, 2023
0d6f801
passing plot
hmzh-khn Sep 28, 2023
295799a
Adjust convergence plot 10
hmzh-khn Sep 28, 2023
7b576fc
Adjust convergence plot 10 + passing plot 2
hmzh-khn Sep 28, 2023
10b1d2b
Adjust convergence plot 10 + passing plot 3
hmzh-khn Sep 28, 2023
08fec6d
Adjust convergence plot 10 + passing plot 4
hmzh-khn Sep 29, 2023
730fb88
Adjust convergence plot 11 + passing plot 4
hmzh-khn Sep 29, 2023
368cd59
Adjust convergence plot 12 + passing plot 4
hmzh-khn Sep 29, 2023
bfc43ec
Adjust convergence plot 13 + passing plot 4
hmzh-khn Sep 29, 2023
befb467
Adjust convergence plot 14 + passing plot 4
hmzh-khn Sep 29, 2023
a58bd43
Adjust convergence plot 15 + passing plot 4
hmzh-khn Sep 29, 2023
1ee4a26
Adjust convergence plot 16 + passing plot 4
hmzh-khn Sep 29, 2023
472acc9
Adjust convergence plot 17 + passing plot 4
hmzh-khn Sep 29, 2023
8a8c7cb
Adjust convergence plot 18 + passing plot 4
hmzh-khn Sep 29, 2023
6e4dac5
Adjust convergence plot 19 + passing plot 4
hmzh-khn Sep 29, 2023
6de20f4
Adjust convergence plot 20 + passing plot 4
hmzh-khn Sep 29, 2023
4300f77
Adjust convergence plot 21 + passing plot 4
hmzh-khn Sep 29, 2023
8d1af81
Adjust convergence plot 22 + passing plot 4
hmzh-khn Sep 29, 2023
2ad67f6
Adjust convergence plot 23 + passing plot 4
hmzh-khn Sep 30, 2023
45a36bd
Adjust convergence plot 24 + passing plot 4
hmzh-khn Sep 30, 2023
eb774a8
Adjust convergence plot 24 + passing plot 5
hmzh-khn Oct 2, 2023
40b5654
Thick line and label fix
hmzh-khn Oct 8, 2023
e44aac3
Plot red on top when small amount
hmzh-khn Oct 8, 2023
348974a
chnaged dash line
hmzh-khn Oct 8, 2023
4c0e92d
Change position proc. noise 1e-3 to 1e-2
hmzh-khn Oct 10, 2023
76a8861
undo previous, proc. noise for P2 pos from 1e2 to 2e2
hmzh-khn Oct 10, 2023
d0b2a89
undo previous, proc. noise for P2 pos from 2e2 to 3e2
hmzh-khn Oct 10, 2023
4927e44
undo previous, proc. noise for P2 pos from 3e2 to 1.5e2
hmzh-khn Oct 10, 2023
b0e5150
undo previous, proc. noise for P2 pos from 1.5e2 to 5e2
hmzh-khn Oct 10, 2023
dc1c515
Remove prints
hmzh-khn Oct 10, 2023
98d7d28
Change P2 vel proc to 1e1
hmzh-khn Oct 10, 2023
79d00fb
Change P1 pos. proc. to 5e2, P2 back to 1e2
hmzh-khn Oct 11, 2023
b641a97
Change P1 pos. proc. from 5e2 to 1.5e2
hmzh-khn Oct 11, 2023
bc5e6f6
Change P1 pos. proc. from 1.5e2 to 2e2
hmzh-khn Oct 11, 2023
ce1e807
Change P1 pos. proc. from 2e2 to 3e2
hmzh-khn Oct 11, 2023
a2ecad4
Change P1 pos. proc. from 3e2 to 5e2, again
hmzh-khn Oct 12, 2023
8fa6d92
Increase plot margins.
hmzh-khn Oct 12, 2023
84e22b5
Change P1 pos. proc. from 5e2 to 3e2, again
hmzh-khn Oct 12, 2023
b84a48f
Change P1 pos. proc. from 3e2 to 2e2, again
hmzh-khn Oct 12, 2023
84bff9f
Change P1 pos. proc. from 2e2 to 1_5e2, again
hmzh-khn Oct 12, 2023
92e0658
Change P1 pos. proc. from 1.5e2 to 5e2, again
hmzh-khn Oct 12, 2023
330ce09
Change truth to dashed lines, merging proc noise to 1.5e2
hmzh-khn Oct 12, 2023
93a80d0
dash to dot
hmzh-khn Oct 12, 2023
238529b
Add timings to scenarios
hmzh-khn Jan 18, 2024
c445a71
Add timings to scenarios - imports
hmzh-khn Jan 18, 2024
992d8ad
Refactor MC SILQGames but don't change example
hmzh-khn Jan 18, 2024
dc2394d
100 sims -> 10
hmzh-khn Jan 18, 2024
75df916
Refactor some code.
hmzh-khn Jan 18, 2024
14f5ed0
Comment unneeded
hmzh-khn Jan 18, 2024
b238de6
Back to 100
hmzh-khn Jan 18, 2024
4ff16b5
rebuttal follower variation
hmzh-khn Jan 18, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
# Files generated by invoking Julia with --track-allocation
*.jl.mem

merging_scenario_2_leadfilt*
passing_scenario_2_leadfilt*
mc_data*

# System-specific files and directories generated by the BinaryProvider and BinDeps packages
# They contain absolute paths specific to the host computer, and so should not be committed
deps/deps.jl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ \section{Steps}

At each iteration $k = 1, 2, \ldots$ until convergence condition $\| \Delta \gamma^i_{k} \| < $ threshold $\epsilon$,
\begin{enumerate}
\item Propagate $\gamma^i_{k-1}$ forward in time using the gain matrices $S^i_{1:T, k=i}$ from $\truestate{0}$ to get $\xi_k \equiv \{ \stackmeas{}{1:\horizon}, \ctrlhat{i}{1:\horizon} \}$.
\item Propagate $\gamma^i_{k-1}$ forward in time using the gain matrices $S^i_{1:T, k=i}$ from $\truestate{0}$ to get $\state{k} \equiv \{ \stackmeas{}{1:\horizon}, \ctrlhat{i}{1:\horizon} \}$.

\item Compute errors
\[ \delta \truestate{t} = \truestate{t} - \stackmeas{}{1:\horizon}, ~~~ \delta \ctrl{i}{t} = \ctrl{i}{t} - \ctrlhat{i}{1:\horizon}. \]
Expand Down
34 changes: 18 additions & 16 deletions example/PassingScenario/CreateMergingScenarioGame.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,18 @@ function create_merging_scenario_costs(cfg::MergingScenarioConfig, si, w_p1, w_p
c2b = PlayerCost(avoid_collisions_cost_fn, si)

# 3. enforce speed limit and turning limit
c1c_i = AbsoluteLogBarrierCost(4, cfg.speed_limit_mps, false)
c1c_ii = AbsoluteLogBarrierCost(4, -cfg.speed_limit_mps, true)
reg_term = 100.
reg_offset = 0.01
c1c_i = AbsoluteLogBarrierCost(4, cfg.speed_limit_mps, false, reg_term, reg_offset)
c1c_ii = AbsoluteLogBarrierCost(4, -cfg.speed_limit_mps, true, reg_term, reg_offset)

c1c_iii = AbsoluteLogBarrierCost(3, cfg.θ₀+cfg.max_heading_deviation, false)
c1c_iv = AbsoluteLogBarrierCost(3, cfg.θ₀-cfg.max_heading_deviation, true)
c1c_iii = AbsoluteLogBarrierCost(3, cfg.θ₀+cfg.max_heading_deviation, false, reg_term, reg_offset)
c1c_iv = AbsoluteLogBarrierCost(3, cfg.θ₀-cfg.max_heading_deviation, true, reg_term, reg_offset)

c2c_i = AbsoluteLogBarrierCost(8, cfg.speed_limit_mps, false)
c2c_ii = AbsoluteLogBarrierCost(8, -cfg.speed_limit_mps, true)
c2c_iii = AbsoluteLogBarrierCost(7, cfg.θ₀+cfg.max_heading_deviation, false)
c2c_iv = AbsoluteLogBarrierCost(7, cfg.θ₀-cfg.max_heading_deviation, true)
c2c_i = AbsoluteLogBarrierCost(8, cfg.speed_limit_mps, false, reg_term, reg_offset)
c2c_ii = AbsoluteLogBarrierCost(8, -cfg.speed_limit_mps, true, reg_term, reg_offset)
c2c_iii = AbsoluteLogBarrierCost(7, cfg.θ₀+cfg.max_heading_deviation, false, reg_term, reg_offset)
c2c_iv = AbsoluteLogBarrierCost(7, cfg.θ₀-cfg.max_heading_deviation, true, reg_term, reg_offset)

# 4, 5. minimize and bound control effort - acceleration should be easier than rotation
c1de = QuadraticCost(zeros(8, 8), zeros(8), 0.)
Expand All @@ -125,20 +127,20 @@ function create_merging_scenario_costs(cfg::MergingScenarioConfig, si, w_p1, w_p
max_rotvel = cfg.max_rotational_velocity_radps
max_accel = cfg.max_acceleration_mps

c1de_i = AbsoluteLogBarrierControlCost(1, [1.; 0.], max_rotvel, false)
c1de_ii = AbsoluteLogBarrierControlCost(1, [1.; 0.], -max_rotvel, true)
c1de_iii = AbsoluteLogBarrierControlCost(1, [0.; 1.], max_accel, false)
c1de_iv = AbsoluteLogBarrierControlCost(1, [0.; 1.], -max_accel, true)
c1de_i = AbsoluteLogBarrierControlCost(1, [1.; 0.], max_rotvel, false, reg_term, reg_offset)
c1de_ii = AbsoluteLogBarrierControlCost(1, [1.; 0.], -max_rotvel, true, reg_term, reg_offset)
c1de_iii = AbsoluteLogBarrierControlCost(1, [0.; 1.], max_accel, false, reg_term, reg_offset)
c1de_iv = AbsoluteLogBarrierControlCost(1, [0.; 1.], -max_accel, true, reg_term, reg_offset)

c2de = QuadraticCost(zeros(8, 8))
R22 = [1. 0; 0 1.]
add_control_cost!(c2de, 2, Z22)
add_control_cost!(c2de, 1, Z22)

c2de_i = AbsoluteLogBarrierControlCost(2, [1.; 0.], max_rotvel, false)
c2de_ii = AbsoluteLogBarrierControlCost(2, [1.; 0.], -max_rotvel, true)
c2de_iii = AbsoluteLogBarrierControlCost(2, [0.; 1.], max_accel, false)
c2de_iv = AbsoluteLogBarrierControlCost(2, [0.; 1.], -max_accel, true)
c2de_i = AbsoluteLogBarrierControlCost(2, [1.; 0.], max_rotvel, false, reg_term, reg_offset)
c2de_ii = AbsoluteLogBarrierControlCost(2, [1.; 0.], -max_rotvel, true, reg_term, reg_offset)
c2de_iii = AbsoluteLogBarrierControlCost(2, [0.; 1.], max_accel, false, reg_term, reg_offset)
c2de_iv = AbsoluteLogBarrierControlCost(2, [0.; 1.], -max_accel, true, reg_term, reg_offset)

# 6. log barriers on the x dimension ensure that the vehicles don't exit the road
# TODO(hamzah) - remove assumption of straight road
Expand Down
32 changes: 18 additions & 14 deletions example/PassingScenario/PassingScenarioPlotUtils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ function make_passing_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits

# Only needs to be generated once.
p1a = plot_leadership_filter_positions(sg_objs[1].dyn, rotated_true_xs[:, 1:T], rotated_x̂s[:, 1:T])
plot!(p1a, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1a, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
p1a = add_lane_lines!(p1a, cfg, limits)

p1m = plot_leadership_filter_measurements(sg_objs[1].dyn, rotated_true_xs[:, 1:T], rotated_zs[:, 1:T])
plot!(p1m, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1m, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
p1m = add_lane_lines!(p1m, cfg, limits)

pos_main_filepath = joinpath(folder_name, "LF_passing_scenario_main.pdf")
Expand All @@ -52,18 +52,20 @@ function make_passing_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits

# Generate a probability plot no timings.
prob_plot = make_probability_plots(times[1:T], probs[1:T])
plot!(prob_plot, title="")
plot!(prob_plot, title="Leadership Probability v. Time", xlabel="", ylabel="")
# plot!(prob_plot, leftmargin=10Plots.mm, bottommargin=10Plots.mm)
prob_filepath = joinpath(folder_name, "LF_passing_scenario_probs.pdf")
savefig(prob_plot, prob_filepath)

ii = 1
for t in iter1
p1b = plot_leadership_filter_measurement_details(num_particles, sg_objs[t], rotated_true_xs[:, 1:T], rotated_x̂s; transform_particle_fn=rotate_particle_state, include_all_labels=true)
plot!(p1b, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1b, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
p1b = add_lane_lines!(p1b, cfg, limits)

prob_plot = make_probability_plots(times[1:T], probs[1:T]; t_idx=t)
plot!(prob_plot, title="")
plot!(prob_plot, title="Leadership Probability v. Time", xlabel="", ylabel="")
# plot!(prob_plot, leftmargin=10Plots.mm, bottommargin=10Plots.mm)

pos2_filepath = joinpath(folder_name, "0$(ii)_LF_passing_scenario_positions_detail.pdf")
prob_filepath = joinpath(folder_name, "0$(ii)_LF_passing_scenario_probs.pdf")
Expand All @@ -90,12 +92,12 @@ function make_merging_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits

# Only needs to be generated once.
p1a = plot_leadership_filter_positions(sg_objs[1].dyn, rotated_true_xs[:, 1:T], rotated_x̂s[:, 1:T])
# plot!(p1a, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1a, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
# plot!(p1a, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1a, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
p1a = add_lane_lines!(p1a, cfg, limits)

p1m = plot_leadership_filter_measurements(sg_objs[1].dyn, rotated_true_xs[:, 1:T], rotated_zs[:, 1:T])
plot!(p1m, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1m, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
p1m = add_lane_lines!(p1m, cfg, limits)

pos_main_filepath = joinpath(folder_name, "LF_merging_scenario_main.pdf")
Expand All @@ -106,18 +108,20 @@ function make_merging_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits

# Generate a probability plot no timings.
prob_plot = make_probability_plots(times[1:T], probs[1:T])
plot!(prob_plot, title="")
plot!(prob_plot, title="Leadership Probability v. Time", xlabel="", ylabel="")
# plot!(prob_plot, title="")
prob_filepath = joinpath(folder_name, "LF_merging_scenario_probs.pdf")
savefig(prob_plot, prob_filepath)

ii = 1
for t in iter1
p1b = plot_leadership_filter_measurement_details(num_particles, sg_objs[t], rotated_true_xs[:, 1:T], rotated_x̂s; transform_particle_fn=rotate_particle_state, include_all_labels=true)
plot!(p1b, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1b, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
p1b = add_lane_lines!(p1b, cfg, limits)

prob_plot = make_probability_plots(times[1:T], probs[1:T]; t_idx=t)
plot!(prob_plot, title="")
plot!(prob_plot, title="Leadership Probability v. Time", xlabel="", ylabel="")
# plot!(prob_plot, title="")
# plot!(p6, title="")

pos2_filepath = joinpath(folder_name, "0$(ii)_LF_merging_scenario_positions_detail.pdf")
Expand Down Expand Up @@ -147,7 +151,7 @@ function make_debug_gif(folder_name, filename, cfg, limits, dyn, horizon, times,
# This plot need not be in the loop.
title="x-y plot of agent positions over time"
p1a = plot_leadership_filter_positions(dyn, rotated_true_xs[:, 1:T], rotated_x̂s[:, 1:T])
plot!(p1a, title=title, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1a, title=title, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
p1a = add_lane_lines!(p1a, cfg, limits)

iter = ProgressBar(2:T)
Expand All @@ -156,7 +160,7 @@ function make_debug_gif(folder_name, filename, cfg, limits, dyn, horizon, times,

plot_title = string("LF (", t, "/", T, "), Ts=", Ts, ", Ns=", num_particles, ", p(not transition)=", p_transition, ", #games: ", num_games)
p1b = plot_leadership_filter_measurement_details(num_particles, sg_objs[t], rotated_true_xs[:, 1:T], rotated_x̂s[:, 1:T]; transform_particle_fn=rotate_particle_state, include_all_labels=true)
plot!(p1b, ylabel="Transverse Position (m)", xlabel="Along-Road Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
plot!(p1b, ylabel="Transverse Position (m)", xlabel="Longitudinal Position (m)", ylimit=(-(cfg.lane_width_m+1), cfg.lane_width_m+1), xlimit=limits_tuple)
p1b = add_lane_lines!(p1b, cfg, limits)

_, p_px, p_py, p_θ, p_v, _, _ = plot_states_and_controls(dyn, times[1:T], true_xs[:, 1:T], true_us)
Expand All @@ -175,7 +179,7 @@ function make_debug_gif(folder_name, filename, cfg, limits, dyn, horizon, times,

# plot 4 - accel. controls
title5 = "Input acceleration controls (u) over time"
p4 = plot( xlabel="t (s)", ylabel="accel. (m/s^2)", title=title5)
p4 = plot( xlabel="Time (s)", ylabel="accel. (m/s^2)", title=title5)
plot!(p4, times[1:T], true_us[1][1, 1:T], label=L"\mathcal{A}_1 ω")
plot!(p4, times[1:T], true_us[2][1, 1:T], label=L"\mathcal{A}_2 ω")
plot!(p4, times[1:T], true_us[1][2, 1:T], label=L"\mathcal{A}_1 a")
Expand Down
28 changes: 19 additions & 9 deletions example/PassingScenario/RunMergingScenario.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using Plots
using ProgressBars
using Random: MersenneTwister
using Distributions: Bernoulli, MvNormal
using Statistics
#gr()

include("CreateMergingScenarioGame.jl")
Expand Down Expand Up @@ -100,8 +101,10 @@ pos_unc = 1e-3
vel_unc = 1e-3
P₁ = Diagonal([pos_unc, pos_unc, θ_inc, vel_unc, pos_unc, pos_unc, θ_inc, vel_unc])

# Process noise uncertainty
Q = 1e-2 * Diagonal([1e-2, 1e-2, 1e-3, 1e-2, 1e-2, 1e-2, 1e-3, 1e-2])
# Process noise uncertainty - P2 is leader, remember.
pos_proc_1 = 1.5e-2
pos_proc_2 = 1e-2
Q = 1e-2 * Diagonal([pos_proc_1, pos_proc_1, 1e-3, 1e-2, pos_proc_2, pos_proc_2, 1e-3, 1e-2])


# CONFIG:
Expand Down Expand Up @@ -178,12 +181,19 @@ gr()
folder_name = "merging_scenario_2_leadfilt_$(get_date_str())"
isdir(folder_name) || mkdir(folder_name)

# Generate the plots for the paper.
snapshot_freq = Int((T - 1)/10)
make_merging_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits, sg_objs[1].dyn, T, times, true_xs, true_us, probs, x̂s, zs, num_particles)
# make_driving_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits, dyn, horizon, times, true_xs, true_us, probs, x̂s, zs, num_particles)
# Timing
mean_times_per_step = mean(iter_timings)
std_times_per_step = std(iter_timings)
println("merging iter timings $(mean_times_per_step)±$(std_times_per_step)")

# This generates the gif.
filename = "merging_scenario_2.gif"
make_debug_gif(folder_name, filename, cfg, limits, dyn, T, times, true_xs, true_us, probs, x̂s, zs, Ts, num_particles, p_transition, num_games)
# # Generate the plots for the paper.
# snapshot_freq = Int((T - 1)/10)
# make_merging_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits, sg_objs[1].dyn, T, times, true_xs, true_us, probs, x̂s, zs, num_particles)
# # make_driving_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits, dyn, horizon, times, true_xs, true_us, probs, x̂s, zs, num_particles)

# # # This generates the gif.
# # filename = "merging_scenario_2.gif"
# # make_debug_gif(folder_name, filename, cfg, limits, dyn, T, times, true_xs, true_us, probs, x̂s, zs, Ts, num_particles, p_transition, num_games)

# println("Saved in $(folder_name).")

18 changes: 12 additions & 6 deletions example/PassingScenario/RunPassingScenario2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ using LinearAlgebra: norm, Diagonal, I
using ProgressBars
using Random: MersenneTwister
using Distributions: Bernoulli, MvNormal
using Statistics

include("CreatePassingScenarioGame.jl")
include("GroundTruthUtils.jl")
Expand Down Expand Up @@ -146,13 +147,18 @@ x̂s, P̂s, probs, pf, sg_objs, iter_timings = leadership_filter(dyn, costs, t
using Dates
gr()

# Create the folder if it doesn't exist
folder_name = "passing_scenario_2_leadfilt_$(get_date_str())"
isdir(folder_name) || mkdir(folder_name)
# Timing
mean_times_per_step = mean(iter_timings)
std_times_per_step = std(iter_timings)
println("passing iter timings $(mean_times_per_step)±$(std_times_per_step)")

# Generate the plots for the paper.
snapshot_freq = Int((T - 1)/10)
make_passing_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits, sg_objs[1].dyn, T, times, true_xs, true_us, probs, x̂s, zs, num_particles)
# # Create the folder if it doesn't exist
# folder_name = "passing_scenario_2_leadfilt_$(get_date_str())"
# isdir(folder_name) || mkdir(folder_name)

# # Generate the plots for the paper.
# snapshot_freq = Int((T - 1)/10)
# make_passing_scenario_pdf_plots(folder_name, snapshot_freq, cfg, limits, sg_objs[1].dyn, T, times, true_xs, true_us, probs, x̂s, zs, num_particles)

# # This generates the gif.
# filename = "passing_scenario_2.gif"
Expand Down
32 changes: 22 additions & 10 deletions example/SILQGamesExamples/ComputeTimingInfo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ using Statistics
include("MCFileLocations.jl")


lqp1_data_folder, s, lqp1_lf_path = get_final_lq_paths_p1()
lqp1_data_folder, lqp1_silq_path, lqp1_lf_path = get_final_lq_paths_p1()
# lqp2_data_folder, _, lqp2_lf_path = get_final_lq_paths_p2()
# uqp1_data_folder, _, uqp1_lf_path = get_final_uq_paths_p1()
nonlqp2_data_folder, nonlqp2_silq_path, nonlqp2_lf_path = get_final_nonlq_paths_p2()

function compute_silqgames_timing_info(data_folder, silq_filename)
function compute_silqgames_timing_info(data_folder, silq_filename; remove_build_times=false)
mc_foldername = joinpath(mc_folder, data_folder)
input_data_path = joinpath(mc_foldername, silq_filename)
silq_data = load(input_data_path)["data"]
Expand All @@ -27,9 +27,17 @@ function compute_silqgames_timing_info(data_folder, silq_filename)
mean_num_iters = mean(num_iterations .- 1)
std_num_iters = std(num_iterations .- 1)

iteration_times = silq_data["elapsed_iteration_times"]
iteration_times = deepcopy(silq_data["elapsed_iteration_times"])

if remove_build_times
# For 100 sim LQ game, manually remove build times.
# println(iteration_times[1:5:100])
iteration_times[1:5:100] .= 0
end
iters_of_interest = iteration_times[iteration_times[:] .!= 0]
@assert length(iters_of_interest)-silq_data["num_sims"] == sum(num_iterations.-1) "length 1: $(length(iters_of_interest)-silq_data["num_sims"]), length 2: $(sum(num_iterations.-1))"
if !remove_build_times
@assert length(iters_of_interest)-silq_data["num_sims"] == sum(num_iterations.-1) "length 1: $(length(iters_of_interest)-silq_data["num_sims"]), length 2: $(sum(num_iterations.-1))"
end

mean_iter_time = mean(iters_of_interest)
std_iter_time = std(iters_of_interest)
Expand Down Expand Up @@ -74,17 +82,21 @@ function compute_overall_timing_info(data_folder, lf_filename)
end

# LQ P1
lq1_lf_m, lq1_lf_s, lq1_silq_m, lq1_silq_s = compute_overall_timing_info(lqp1_data_folder, lqp1_lf_path)
println("LQ SILQGames (P1), 201 timesteps @ 0.05s: $(lq1_silq_m) ± $(lq1_silq_s)")
println("LQ LF (P1), 201 timesteps @ 0.05s, Ts=30, Ns=50: $(lq1_lf_m) ± $(lq1_lf_s)")
# lq1_lf_m, lq1_lf_s, lq1_silq_m, lq1_silq_s = compute_overall_timing_info(lqp1_data_folder, lqp1_lf_path)
# println("LQ SILQGames (P1), 501 timesteps @ 0.02s: $(lq1_silq_m) ± $(lq1_silq_s)")
# println("LQ LF (P1), 501 timesteps @ 0.05s, Ts=75, Ns=50: $(lq1_lf_m) ± $(lq1_lf_s)")

# # LQ P1
# Non-LQ P1
# nonlq2_lf_m, nonlq2_lf_s, nonlq2_silq_m, nonlq2_silq_s = compute_overall_timing_info(nonlqp2_data_folder, nonlqp2_lf_path)
# println("NonLQ SILQGames (P2), 251 timesteps @ 0.02s: $(nonlq2_silq_m) ± $(nonlq2_silq_s)")
# println("NonLQ SILQGames (P2), 501 timesteps @ 0.02s: $(nonlq2_silq_m) ± $(nonlq2_silq_s)")
# println("NonLQ LF (P2), 251 timesteps @ 0.02s, Ts=30, Ns=100: $(nonlq2_lf_m) ± $(nonlq2_lf_s)")


lq_iters_mean, lq_iters_std, lq_iter_time_mean, lq_iter_time_std = compute_silqgames_timing_info(lqp1_data_folder, lqp1_silq_path)
lq_iters_mean, lq_iters_std, lq_iter_time_mean, lq_iter_time_std = compute_silqgames_timing_info(lqp1_data_folder, lqp1_silq_path; remove_build_times=true)
lq_lf_iters_means, lq_lf_iters_stds, lq_lf_total_mean, lq_lf_total_std = compute_leadership_filter_timing_info(lqp1_data_folder, lqp1_lf_path)
println("LQ SILQGames (L=P2) 501 timesteps @ 0.02s: time/iteration: $(lq_iter_time_mean) ± $(lq_iter_time_std) \niterations: $(lq_iters_mean) ± $(lq_iters_std)")
println("LQ SLF (L=P2) 501 timesteps @ 0.02s, Ts=75, Ns=50: time/iteration: $(mean(lq_lf_iters_means)) ± $(mean(lq_lf_iters_stds)) \nTotal Time: $(lq_lf_total_mean) ± $(lq_lf_total_std)")

# For non-LQ paper timing metrics.
nonlq_iters_mean, nonlq_iters_std, nonlq_iter_time_mean, nonlq_iter_time_std = compute_silqgames_timing_info(nonlqp2_data_folder, nonlqp2_silq_path)
println("Non-LQ SILQGames (L=P2) 501 timesteps @ 0.02s: time/iteration: $(nonlq_iter_time_mean) ± $(nonlq_iter_time_std) \niterations: $(nonlq_iters_mean) ± $(nonlq_iters_std)")
Loading