Skip to content

Commit

Permalink
Scatter plot to compare mean particles vs lmfit parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
raunakbh92 committed May 14, 2020
1 parent cac30cf commit 8349e62
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 26 deletions.
67 changes: 59 additions & 8 deletions scripts/helpers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,72 @@
helpers.jl
This file provides helper functions to experiments.jl, the experiment script
Most functions have the script within the doc string as example
# List of functions
- metrics_from_jld
- metrics_from_jld_idmbased
- multiscenarios_idm
- multiscenarios_pf
- collision rmse functions
- scenario generation
"""

using Distributions # provides `mean`: to compute mean of particle dist over cars
using JLD # to save models
using AutomotiveInteraction
using DelimitedFiles # to write to txt file that will be read in by python

"""
- Make scatter plot of the lmidm parameters and final particle for a scenario
with each scatter point corresponding to a different car
# Examples
```julia
cd("scripts")
f= FilteringEnvironment()
scatterplot_lmfit_pf(f,scene_real,scenario_name="upper_1")
```
"""
function scatterplot_lmfit_pf(f::FilteringEnvironment;scenario_name="upper_1")
filename="media/$(scenario_name).jld"
particle,id_list,ts,te = JLD.load(filename,"p","veh_id_list","ts","te")
scene = deepcopy(f.traj[ts])
if !isempty(id_list) keep_vehicle_subset!(scene,id_list) end

v_des_vec = []
T_vec = []
v_des_vec_pf = []
T_vec_pf=[]
# Loop over list of vehicles and assign model params based on lmfit values
for veh in scene
veh_id = veh.id

# Read the lmfit parameters
lmfit_param_filename = "lmfit/$(scenario_name)/$(veh_id)_lmfit_params.txt"
if isfile(lmfit_param_filename)
lmparams = readdlm(lmfit_param_filename)
v_des = lmparams[1]
T = lmparams[2]
s_min = lmparams[3]
push!(v_des_vec,v_des)
push!(T_vec,T)
else
# Default to Jeremy's parameters
print("Could not find lmfit param file for $(veh_id). Use Jeremy params\n")
v_des=17.837
T=0.918
s_min=5.249
push!(v_des_vec,v_des)
push!(T_vec,T)
end

# Insert the pf parameters
push!(v_des_vec_pf,particle[veh_id][1])
push!(T_vec_pf,particle[veh_id][3])
end

scatter_lmidm = PGFPlots.Plots.Scatter(Float64.(v_des_vec),Float64.(T_vec),
legendentry="lmidm")
scatter_pf = PGFPlots.Plots.Scatter(Float64.(v_des_vec_pf),Float64.(T_vec_pf),
legendentry="pf")
a = PGFPlots.Axis([scatter_lmidm,scatter_pf],xlabel="v",ylabel="T",
title="lmidm vs pf parameters")
PGFPlots.save("media/lmfit_pf_scatter_$(scenario_name).svg",a)
return nothing
end

#****************scenario_generation************************
"""
function train_one_test_another(;train_filename="media/lower_3.jld",test_filename="media/upper_2.jld",video_filename="media/train_low_test_up.mp4")
Expand Down
3 changes: 2 additions & 1 deletion src/Driving/driving_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,8 @@ function make_cidm_models(f::FilteringEnvironment,scene)
print("c-IDM models being assigned to vehicles\n")
models = Dict{Int64,DriverModel}()
for veh in scene
models[veh.id] = CooperativeIDM(env=f.mergeenv,c=1.0)
models[veh.id] = CooperativeIDM(env=f.mergeenv,c=1.0,
idm=IntelligentDriverModel(v_des=5.))
end
return models
end
Expand Down
33 changes: 16 additions & 17 deletions src/Filtering/metrics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,14 @@ end
# Example
```julia
rmse_pos_mat_idm,rmse_vel_mat_idm,coll_mat_idm =
multiscenarios_idm(mergetype="upper",modelmaker=make_IDM_models)
rmse_pos_mat_cidm, rmse_vel_mat_cidm, coll_mat_cidm =
multiscenarios_idm(mergetype="upper",modelmaker=make_cidm_models)
rmse_pos_mat_lmidm, rmse_vel_mat_lmidm, coll_mat_lmidm = multiscenarios_lmidm(
mergetype="upper")
rmse_pos_mat_pf, rmse_vel_mat_pf, coll_mat_pf = multiscenarios_pf(mergetype="upper")
coll_mat_list = [coll_mat_idm,coll_mat_cidm,coll_mat_lmidm,coll_mat_pf]
coll_barchart(coll_mat_list,filename = "media/coll_barchart_new.svg")
cd("scripts")
rmse_pos_mat_idm,rmse_vel_mat_idm,coll_mat_idm = multiscenarios_idm(mergetype="upper",modelmaker=make_IDM_models);
rmse_pos_mat_cidm, rmse_vel_mat_cidm, coll_mat_cidm = multiscenarios_idm(mergetype="upper",modelmaker=make_cidm_models);
rmse_pos_mat_lmidm, rmse_vel_mat_lmidm, coll_mat_lmidm = multiscenarios_lmidm(mergetype="upper");
rmse_pos_mat_pf, rmse_vel_mat_pf, coll_mat_pf = multiscenarios_pf(mergetype="upper");
coll_mat_list = [coll_mat_idm,coll_mat_cidm,coll_mat_lmidm,coll_mat_pf];
coll_barchart(coll_mat_list,filename = "media/coll_barchart_new_cidm.svg");
```
"""
function coll_barchart(coll_mat_list;filename="media/test_bar.pdf")
Expand Down Expand Up @@ -246,13 +244,14 @@ function rmse_plots_modelscompare(rmse_list;filename="media/test_rmse.pdf")
# Example
```julia
rmse_pos_mat_idm,rmse_vel_mat_idm,coll_mat_idm = multiscenarios_idm(mergetype="upper",modelmaker=make_IDM_models)
rmse_pos_mat_cidm, rmse_vel_mat_cidm, coll_mat_cidm = multiscenarios_idm(mergetype="upper",modelmaker=make_cidm_models)
rmse_pos_mat_lmidm, rmse_vel_mat_lmidm, coll_mat_lmidm = multiscenarios_lmidm(mergetype="upper")
rmse_pos_mat_pf, rmse_vel_mat_pf, coll_mat_pf = multiscenarios_pf(mergetype="upper")
rmse_list = [rmse_pos_mat_idm,rmse_pos_mat_cidm,rmse_pos_mat_lmidm,rmse_pos_mat_pf]
rmse_plots_modelscompare(rmse_list,filename = "media/rmse_pos_new.svg")
cd("scripts")
rmse_pos_mat_idm,rmse_vel_mat_idm,coll_mat_idm = multiscenarios_idm(mergetype="upper",modelmaker=make_IDM_models);
rmse_pos_mat_cidm, rmse_vel_mat_cidm, coll_mat_cidm = multiscenarios_idm(mergetype="upper",modelmaker=make_cidm_models);
rmse_pos_mat_lmidm, rmse_vel_mat_lmidm, coll_mat_lmidm = multiscenarios_lmidm(mergetype="upper");
rmse_pos_mat_pf, rmse_vel_mat_pf, coll_mat_pf = multiscenarios_pf(mergetype="upper");
rmse_list = [rmse_pos_mat_idm,rmse_pos_mat_cidm,rmse_pos_mat_lmidm,rmse_pos_mat_pf];
rmse_plots_modelscompare(rmse_list,filename = "media/rmse_pos_new.svg");
```
"""
function rmse_plots_modelscompare(rmse_mat_list;filename="media/test_rmse.pdf")
Expand Down

0 comments on commit 8349e62

Please sign in to comment.