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

[WIP] Particle filtering #7

Merged
merged 27 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
5aa7fc0
bring filtering functions in from jupyter notebooks, add Distribution…
raunakbh92 Apr 2, 2020
37ee4cb
FilteringEnvironment created
raunakbh92 Apr 3, 2020
f3b43c9
updating traavis, docs md, and docs project.toml to match fix_travis PR
Apr 6, 2020
db79328
Merge branch 'filtering' of https://github.com/sisl/AutomotiveInterac…
raunakbh92 Apr 6, 2020
dc7dc31
organize src into dedicated folders, add multistep_update to filterin…
raunakbh92 Apr 6, 2020
1cd824d
filtering utils, and obtain_driver_models
raunakbh92 Apr 7, 2020
b908f31
filtering visualization and docs
raunakbh92 Apr 13, 2020
b8abb6a
imitation trajectory generation and rmse computation
raunakbh92 Apr 14, 2020
ee3739a
Have leader vehicles in imitation trajectory replayed from data
raunakbh92 Apr 15, 2020
ab2a0c2
rmse computation functions
raunakbh92 Apr 20, 2020
2f151c1
Sample vehicles that drive together
raunakbh92 Apr 20, 2020
fa14a0f
tests for vehicle sampling, specific param pair plotting function
raunakbh92 Apr 20, 2020
cf2be84
collision checker, and scripts
raunakbh92 Apr 21, 2020
e1eeaae
update gitignore, functions within experiments
raunakbh92 Apr 21, 2020
c496c86
rmse extraction and plotting added to exp script
raunakbh92 Apr 22, 2020
19f7084
helper functions for exps, and two veh sets for merge
raunakbh92 Apr 22, 2020
8567127
convergence progress plots, and changed signature for obtain_driver_m…
raunakbh92 Apr 23, 2020
f26c67e
separate upper and lower merge sections, c-idm more generic to handle…
raunakbh92 Apr 27, 2020
7faf934
merge scenarios identified, merge point for lower hard-coded
raunakbh92 Apr 28, 2020
c024e80
multi-scenario rmse extraction from jld, scenario replay viz, non lin…
raunakbh92 Apr 29, 2020
4df96e8
script for lower merge scenario pf,idm,cidm,lmidm
raunakbh92 Apr 30, 2020
3578505
collision fraction compute, model compare and bar chart plots added t…
raunakbh92 May 5, 2020
00bcbd3
identified merge scenarios in 1001:2000 frame number range
raunakbh92 May 5, 2020
84a5784
train lower test upper, update io for ngsim roadway reading
raunakbh92 May 7, 2020
90acc31
Merge branch 'master' into filtering
raunakbh92 May 7, 2020
a0b5eb5
helpers to extract stop fraction and hard brake fraction, extract idm…
raunakbh92 May 11, 2020
04e66ef
capture true acceleration in addition to idm features
raunakbh92 May 11, 2020
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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ julia_notebooks/.ipynb_checkpoints
# media files generated by notebooks
julia_notebooks/media/

# media files generated by tests
test/media/

# media files generated by scripts
scripts/media/

# Files generated by invoking Julia with --code-coverage
*.jl.cov
*.jl.*.cov
Expand Down
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ jobs:
- julia --project=docs/ -e 'using Pkg; Pkg.develop(PackageSpec(path=pwd()));
Pkg.instantiate()'
- julia --project=docs/ docs/make.jl
after_success: skip
after_success: skip
9 changes: 9 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@ version = "0.1.0"
[deps]
AutomotiveSimulator = "6aa42d20-6c96-11ea-1103-339224409280"
AutomotiveVisualization = "0faf7fd0-6c98-11ea-1740-03605baa3b07"
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DelimitedFiles = "8bb1440f-4735-579b-a4ab-409b98df4dab"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
JLD = "4138dd39-2aa7-5051-a626-17a0bb65d9c8"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PGFPlots = "3b7a836e-365b-5785-a47d-02c71176b4aa"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
Reel = "71555da5-176e-5e73-a222-aebc6c6e4f2f"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"

[compat]
Reel = "1.1.1"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand Down
2 changes: 1 addition & 1 deletion docs/src/driving_simulation.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ These functions help in running driving simulations.
run_vehicles_curvept_overlay
test_barrier_vehicle
test_jumpy_vehicle
```
```
23 changes: 23 additions & 0 deletions docs/src/filtering.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Particle Filtering

These functions are responsible for performing particle filtering for parameter estimation.

```@docs
c_idm_from_particle
hallucinate_a_step
weight_and_resample
multistep_update
obtain_driver_models
```

The following functions are helpers. They provide access to information about vehicle state, as well as help visualize filtering progress.

```@docs
get_frenet_s
get_veh_info
get_lane_id
get_lane_change_prob
initial_pmat
pgfplots2gif
plot_pairwise_particles
```
5 changes: 3 additions & 2 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Pages = [
"roadway_building.md",
"driving_simulation.md",
"visualization.md",
"veh_track_reading.md"
"veh_track_reading.md",
"filtering.md"
]
```
```
2 changes: 1 addition & 1 deletion docs/src/roadway_building.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ These functions are required to build the roadway from the provided centerline t
make_discont_roadway_jagged
MergingRoadway
add_renderable!
```
```
116 changes: 116 additions & 0 deletions scripts/experiments.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
# This file is used for performing experiments
# Run by changing path in REPL to scripts folder
# Then `include("experiments.jl")`

using AutomotiveSimulator
using AutomotiveInteraction
using PGFPlots
using JLD

include("helpers.jl")

# Scenarios for upper merge
# List of tuples. Elem 1 of tuple is veh id list, elem 2 is list with ts and te
scenarios_upper = [
([6,8,13,19,28,29],[1,120]), #19,29 merge lane
([34,37,40,42,43,49,50],[88,230]), #34,37,43,50 merge lane
([59,60,62,66,67,71,73],[188,390]), #59,62,66,71 merge lane
([66,67,71,73,76,82,88,92,95],[310,440]), #71,76,95 merge lane
([187,191,193,194],[940,985]), #187,191,194 merge lane

([211,213,215,217,221],[1135,1190]), #211,217,221 merge lane
([248,249,250,256],[1323,1420]), # 249 merge lane
([272,275,276,277,279],[1440,1615]), #275, 277 merge lane
([294,295,300,307,308,311],[1576,1780]), #295,307,308 merge lane
([324,327,329,333,335,339,341,346,354,357],[1810,1950]) #327,333,339,346,354
]

# Scenarios for lower merge
scenarios_lower = [
([2,7,10,18,25],[1,30]), #7,25 merge vehicles
([64,68,70,74,77],[198,230]), #70 merge lane
([105,106,108,110],[382,430]), # 110 merge lane
([176,177,178],[827,870]), #177 merge lane

([252,253,255],[1315,1370]), #253 merge lane
([361,363,364,366],[1830,1885]) #363 merge lane
]

#***********Run filtering and store resulting models to jld files****
# s = scenarios_lower
# f = FilteringEnvironment(mergeenv=MergingEnvironmentLower())

s = scenarios_upper
f = FilteringEnvironment()
for i in 1:length(s)
veh_id_list = s[i][1]
ts = s[i][2][1]
te = s[i][2][2]
m,p,md = obtain_driver_models(f,veh_id_list=veh_id_list,num_p=50,ts=ts,te=te)
#JLD.save("media/lower_$i.jld","m",m,"p",p,"md",md,"veh_id_list",veh_id_list,"ts",ts,"te",te)
JLD.save("media/upper_$i.jld","m",m,"p",p,"md",md,"veh_id_list",veh_id_list,"ts",ts,"te",te)
end


#************Docstring example code from multiscenarios_pf in helpers.jl*****
# USEFUL to keep around for making tikz plots later on by rerunning this script
# Select a block of code and press shift+enter to run block selectively

# Lower merge
rmse_pos_mat_idm,rmse_vel_mat_idm,coll_mat_idm =
multiscenarios_idm(mergetype="lower",modelmaker=make_IDM_models);
rmse_pos_mat_cidm,rmse_vel_mat_cidm, coll_mat_cidm =
multiscenarios_idm(mergetype="lower",modelmaker=make_cidm_models);
rmse_pos_mat_lmidm, rmse_vel_mat_lmidm, coll_mat_lmidm =
multiscenarios_idm(mergetype="lower",modelmaker=make_lmidm_models);
rmse_pos_mat_pf,rmse_vel_mat_pf, coll_mat_pf = multiscenarios_pf(mergetype="lower");

rmse_pos_list = [rmse_pos_mat_idm,rmse_pos_mat_cidm,rmse_pos_mat_lmidm,rmse_pos_mat_pf];
rmse_plots_modelscompare(rmse_pos_list,filename = "media/rmse_pos_lower.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_lower.svg");

# Upper merge
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_idm(mergetype="upper",modelmaker=make_lmidm_models);
rmse_pos_mat_pf, rmse_vel_mat_pf, coll_mat_pf = multiscenarios_pf(mergetype="upper");

rmse_pos_list = [rmse_pos_mat_idm,rmse_pos_mat_cidm,rmse_pos_mat_lmidm,rmse_pos_mat_pf];
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


#************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)

# 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

# test_tdata = []
# for t in tdata
# push!(test_tdata,Dict("t"=>t))
# end

# curve_fit(test_lmfit,test_tdata,ydata,[0.5,0.5])
Loading