diff --git a/scripts/helpers.jl b/scripts/helpers.jl index c42370a..7b1cb58 100644 --- a/scripts/helpers.jl +++ b/scripts/helpers.jl @@ -2,14 +2,6 @@ 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 @@ -17,6 +9,65 @@ 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") diff --git a/src/Driving/driving_simulation.jl b/src/Driving/driving_simulation.jl index 4e5c08e..9acd8ba 100644 --- a/src/Driving/driving_simulation.jl +++ b/src/Driving/driving_simulation.jl @@ -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 diff --git a/src/Filtering/metrics.jl b/src/Filtering/metrics.jl index f80a5c9..72b1ef1 100644 --- a/src/Filtering/metrics.jl +++ b/src/Filtering/metrics.jl @@ -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") @@ -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")