diff --git a/scripts/experiments.jl b/scripts/experiments.jl index 1f95550..36b682c 100644 --- a/scripts/experiments.jl +++ b/scripts/experiments.jl @@ -85,3 +85,9 @@ rmse_plots_modelscompare(rmse_pos_list,filename = "media/rmse_pos_upper.svg"); coll_mat_list = [coll_mat_idm,coll_mat_cidm,coll_mat_lmidm,coll_mat_pf]; coll_barchart(coll_mat_list,filename = "media/coll_barchart_upper.svg"); + +#********************Train upper test lower****************** +# We need to show a variability in the generated scenarios +# So we need to combine the particle sets of different vehicles together +# And then for the same set of vehicles in the lower merge i.e. test domain +# We show significantly different driving behavior by sampling from the particle set diff --git a/scripts/helpers.jl b/scripts/helpers.jl index 5cb5507..327b88e 100644 --- a/scripts/helpers.jl +++ b/scripts/helpers.jl @@ -348,3 +348,38 @@ function rmse_plots_modelscompare(rmse_mat_list;filename="media/test_rmse.pdf") print("function rmse_plots_modelscompare says: saved $(filename)\n") return nothing end + +""" +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") +- Take final particle (i.e. mean of particles) obtained for one vehicle in train scenario +- Assign cidm model using that particle to all vehicles in test scenario +- Run a simulation, make a video and return collision assessment + +# Example +```julia +# Run this from scripts folder +train_one_test_another(train_filename="media/lower_3.jld", +test_filename="media/upper_4.jld",video_filename="media/train_test_3_4.mp4") +``` +""" +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") + # p_dict is a Dict(veh_id=>final_mean_particle) + p_dict,train_id_list = JLD.load(train_filename,"p","veh_id_list") + particle = p_dict[train_id_list[1]] # pick the first veh in train list wlog + + f = FilteringEnvironment() # Will need to have lower as mergeenv when testing on lower + test_id_list,test_ts,test_te = JLD.load(test_filename,"veh_id_list","ts","te") + models = Dict{Int64,DriverModel}() + for id in test_id_list + models[id] = cidm_from_particle(f,particle) + end + nticks = test_te-test_ts+1 + scene_real = deepcopy(f.traj[test_ts]) + if !isempty(test_id_list) keep_vehicle_subset!(scene_real,test_id_list) end + scene_list = simulate(scene_real,f.roadway,models,nticks,f.timestep) + + c_array = test_collision(scene_list,test_id_list) + scenelist2video(f,scene_list,filename=video_filename) + return c_array +end diff --git a/src/AutomotiveInteraction.jl b/src/AutomotiveInteraction.jl index 24f70fd..7f6ce63 100644 --- a/src/AutomotiveInteraction.jl +++ b/src/AutomotiveInteraction.jl @@ -77,6 +77,7 @@ export include("Driving/overlays.jl") export + cidm_from_particle, hallucinate_a_step, weight_and_resample, multistep_update, diff --git a/src/Data_Processing/roadway_building.jl b/src/Data_Processing/roadway_building.jl index 800d3aa..68e4659 100644 --- a/src/Data_Processing/roadway_building.jl +++ b/src/Data_Processing/roadway_building.jl @@ -199,7 +199,7 @@ end """ function make_roadway_ngsim() -- Read in the ngsim 101 roadway from the provided roadway file `../dataset/ngsim_101.txt` +- Read in the ngsim 101 roadway from the provided roadway file `/dataset/ngsim_101.txt` # Examples ```julia @@ -207,7 +207,7 @@ roadway_ngsim = make_roadway_ngsim() ``` """ function make_roadway_ngsim() - roadway_ngsim = open(io->read(io, MIME"text/plain"(), Roadway),joinpath(@__DIR__,"dataset/ngsim_101.txt"), "r") + roadway_ngsim = open(io->read(io, Roadway),joinpath(@__DIR__,"dataset/ngsim_101.txt"), "r") return roadway_ngsim end diff --git a/src/Driving/visualization.jl b/src/Driving/visualization.jl index 9ef6ba4..a6e54bc 100644 --- a/src/Driving/visualization.jl +++ b/src/Driving/visualization.jl @@ -39,25 +39,27 @@ end # Examples ```julia -# See run_vehicles function in driving_simulation.jl +scenelist2video(f,scenelist,filename="media/test_scenelist2video.mp4") ``` """ -function scenelist2video(scene_list;id_list=[],roadway,filename) +function scenelist2video(f::FilteringEnvironment,scene_list;filename) frames = Frames(MIME("image/png"),fps = 10) - mr = MergingRoadway(roadway) # Wrapper for specialized render for merging lanes + mr = MergingRoadway(f.roadway) # Wrapper for specialized render for merging lanes mp = VecE2(1064.5227, 959.1559) # Loop over list of scenes and convert to video for i in 1:length(scene_list) - if !isempty(id_list) keep_vehicle_subset!(scene_list[i],id_list) end - scene_visual = render([mr,scene_list[i], - IDOverlay(scene=scene_list[i]), - TextOverlay(text=["frame=$(i)"],font_size=12)], - camera=StaticCamera(position=mp,zoom=5.) - ) + temp_scene = deepcopy(scene_list[i]) + renderables = [ + mr, + (FancyCar(car=temp_scene[j]) for j in 1:length(temp_scene))..., + IDOverlay(scene=temp_scene), + TextOverlay(text=["frame=$(i)"],font_size=12) + ] + scene_visual = render(renderables,camera=StaticCamera(position=mp,zoom=5.)) push!(frames,scene_visual) end - print("Making video filename: $(filename)\n") + print("scenelist2video says: Making video filename: $(filename)\n") write(filename,frames) return nothing end