Skip to content

Commit

Permalink
Merge 75ee629 into 65582b2
Browse files Browse the repository at this point in the history
  • Loading branch information
raunakbh92 committed Jun 1, 2020
2 parents 65582b2 + 75ee629 commit b3464dc
Show file tree
Hide file tree
Showing 9 changed files with 1,316 additions and 397 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ test/media/
# media files generated by scripts
scripts/media/

# ipynb checkpoints in pythonscripts
scripts/pythonscripts/.ipynb_checkpoints

# idm acc trace files stored in lmfit
scripts/lmfit/

# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov
Expand Down
3 changes: 3 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
ImageIO = "82e4d734-157c-48bb-816b-45c225c6df19"
ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1"
JLD = "4138dd39-2aa7-5051-a626-17a0bb65d9c8"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PGFPlots = "3b7a836e-365b-5785-a47d-02c71176b4aa"
Expand All @@ -18,6 +20,7 @@ Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reel = "71555da5-176e-5e73-a222-aebc6c6e4f2f"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
StatsPlots = "f3b207a7-027a-5e70-b257-86293d7955fd"

[compat]
Reel = "1.1.1"
Expand Down
125 changes: 103 additions & 22 deletions scripts/experiments.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ for i in 1:length(s)
JLD.save("media/upper_$i.jld","m",m,"p",p,"md",md,"veh_id_list",veh_id_list,"ts",ts,"te",te)
end

#*****************Generate idm params for lmfit************
s = scenarios_upper
f = FilteringEnvironment()
name = "upper"

for i in 1:length(s)
veh_id_list = s[i][1]
ts = s[i][2][1]
te = s[i][2][2]
filename = "media/upper_$i.jld";
id_list,ts,te = JLD.load(filename,"veh_id_list","ts","te");
scene_list_true = replay_scenelist(f,id_list=id_list,ts=ts,te=te);

dirname = "$(name)_$(i)"
mkdir("lmfit/$(dirname)")
feat_dict = scenelist2idmfeatures(f,scene_list_true,id_list=id_list,
scenario_name=name,scenario_number=i);
end

#************Docstring example code from multiscenarios_pf in helpers.jl*****
# USEFUL to keep around for making tikz plots later on by rerunning this script
Expand Down Expand Up @@ -87,30 +105,93 @@ 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
#***********Histogram plot****************
# Full example in docstring of Filtering/metrics.jl vel_distribution
a = PGFPlots.Axis([veh_hist_true,v_hist_idm,v_hist_cidm,v_hist_lmidm,v_hist_pf,
Plots.Command(raw"\legend{true,idm,cidm,lmidm,pf}")
]);

aidm = PGFPlots.Axis([veh_hist_true,v_hist_idm,Plots.Command(raw"\legend{true,idm}")],
xlabel="velocity",ylabel="density",title="True vs IDM");

acidm = PGFPlots.Axis([veh_hist_true,v_hist_cidm,Plots.Command(raw"\legend{true,c-idm}")],
xlabel="velocity",ylabel="density",title="True vs C-IDM");

almidm = PGFPlots.Axis([veh_hist_true,v_hist_lmidm,Plots.Command(raw"\legend{true,lm-idm}")],
xlabel="velocity",ylabel="density",title="True vs LM-IDM");

apf = PGFPlots.Axis([veh_hist_true,v_hist_pf,Plots.Command(raw"\legend{true,pf}")],
xlabel="velocity",ylabel="density",title="True vs pf");

PGFPlots.save("media/vhist_idm.svg",aidm)
PGFPlots.save("media/vhist_cidm.svg",acidm)
PGFPlots.save("media/vhist_lmidm.svg",almidm)
PGFPlots.save("media/vhist_pf.svg",apf)

#*******************Histogram2 plot for position trace****
# Get the true position tracks for all upper scenarios and make histogram2
cd("scripts");
f = FilteringEnvironment();

pos_x_master = Float64[];pos_y_master = Float64[];
pos_x_master_idm = Float64[];pos_y_master_idm = Float64[];
pos_x_master_cidm = Float64[];pos_y_master_cidm = Float64[];
pos_x_master_lmidm = Float64[];pos_y_master_lmidm = Float64[];
pos_x_master_pf = Float64[];pos_y_master_pf = Float64[];

for i in 1:10
filename = "media/upper_$i.jld"

# Get position data for replay
id_list,ts,te = JLD.load(filename,"veh_id_list","ts","te")
scenelist = replay_scenelist(f,id_list=id_list,ts=ts,te=te)
pos_x_array,pos_y_array = pos_data(scenelist,id_list=id_list)
append!(pos_x_master,pos_x_array)
append!(pos_y_master,pos_y_array)

# Get position data for idm
scenelist_idm = scenelist_from_jld_idmbased(f,filename=filename,modelmaker=make_IDM_models)
pos_x_array_idm,pos_y_array_idm = pos_data(scenelist_idm,id_list=id_list)
append!(pos_x_master_idm,pos_x_array_idm)
append!(pos_y_master_idm,pos_y_array_idm)

# Get position data for cidm
scenelist_cidm = scenelist_from_jld_idmbased(f,filename=filename,modelmaker=make_cidm_models)
pos_x_array_cidm,pos_y_array_cidm = pos_data(scenelist_cidm,id_list=id_list)
append!(pos_x_master_cidm,pos_x_array_cidm)
append!(pos_y_master_cidm,pos_y_array_cidm)

# Get position data for lmidm
scenelist_lmidm = scenelist_from_jld_lmidm(f,scenario_name="upper",scenario_number=i)
pos_x_array_lmidm,pos_y_array_lmidm = pos_data(scenelist_lmidm,id_list=id_list)
append!(pos_x_master_lmidm,pos_x_array_lmidm)
append!(pos_y_master_lmidm,pos_y_array_lmidm)

# Get position data for pf
scenelist_pf = scenelist_from_jld_pf(f,filename=filename)
pos_x_array_pf,pos_y_array_pf = pos_data(scenelist_pf,id_list=id_list)
append!(pos_x_master_pf,pos_x_array_pf)
append!(pos_y_master_pf,pos_y_array_pf)

end

p = PGFPlots.Plots.Histogram2(pos_x_master,pos_y_master,zmode="log");
PGFPlots.save("poshisttrue.svg",p) # Note that media/ is not part of the filename

p_idm = PGFPlots.Plots.Histogram2(pos_x_master_idm,pos_y_master_idm,zmode="log");
PGFPlots.save("poshistidm.svg",p_idm)

#************LsqFit failed experimentation***************
# model(t, p) = p[1] * exp.(-p[2] * t)
# tdata = range(0,stop=10,length=20)
# ydata = model(tdata, [1.0 2.0]) + 0.01*randn(length(tdata))
# p0 = [0.5,0.5]
# fit = curve_fit(model, tdata, ydata, p0)
p_cidm = PGFPlots.Plots.Histogram2(pos_x_master_cidm,pos_y_master_cidm,zmode="log");
PGFPlots.save("poshistcidm.svg",p_cidm)

# function test_lmfit(d,p)
# print("test_lmfit called\n")
# print("says:d=$d\n")
# t = d["t"]
# return p[1]*exp.(-p[2]*t)
# end
p_lmidm = PGFPlots.Plots.Histogram2(pos_x_master_lmidm,pos_y_master_lmidm,zmode="log");
PGFPlots.save("poshistlmidm.svg",p_lmidm)

# test_tdata = []
# for t in tdata
# push!(test_tdata,Dict("t"=>t))
# end
p_pf = PGFPlots.Plots.Histogram2(pos_x_master_pf,pos_y_master_pf,zmode="log");
PGFPlots.save("poshistpf.svg",p_pf)

# curve_fit(test_lmfit,test_tdata,ydata,[0.5,0.5])
#********************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
Loading

0 comments on commit b3464dc

Please sign in to comment.