Feature Extraction

In this example we demonstrate how to extract feature from trajectories using AutomotiveSimulator

Load a Dataset First let's create a synthetic dataset.

using AutomotiveSimulator
using AutomotiveVisualization
using Random

roadway = roadway = gen_straight_roadway(3, 1000.0)
veh_state = VehicleState(Frenet(roadway[LaneTag(1,2)], 0.0), roadway, 10.)
veh1 = Entity(veh_state, VehicleDef(), "bob")
veh_state = VehicleState(Frenet(roadway[LaneTag(1,2)], 20.0), roadway, 2.)
veh2 = Entity(veh_state, VehicleDef(), "alice")

dt = 0.5
n_steps = 10
models = Dict{String, DriverModel}()
models["bob"] = Tim2DDriver(mlane=MOBIL())
set_desired_speed!(models["bob"], 10.0)
models["alice"] = Tim2DDriver(mlane=MOBIL())
set_desired_speed!(models["alice"], 2.0)

scene = Scene([veh1, veh2])
scenes = simulate(scene, roadway, models, n_steps, dt)
camera = SceneFollowCamera()
update_camera!(camera, scene)
snapshot = render([roadway, scene], camera=camera)

initial state of feature extraction scenario

One can also load the data from the Stadium tutorial

load data from stadium tutorial
scenes = open("2Dstadium_listrec.txt", "r") do io
    read(io, Vector{EntityScene{VehicleState, VehicleDef, String}})
end

Extract features from a recorded trajectory Recorded trajectories are expected to be vectors of Scenes where each element correspond to one time step. To extract features, one can use the extract_features function which takes as input a list of feature we want to extract and the list of vehicle ids for which we want those features. For this example, let's first query two features, the longitudinal and lateral position of Bob, and whether or not Bob is colliding:

dfs = extract_features((posfs, posft, iscolliding), roadway, scenes, ["bob"])
dfs["bob"]

11 rows × 3 columns

posfsposftiscolliding
Float64Float64Bool
10.00.00
25.01.1250
39.87927-0.0468750
414.64730.6738280
519.48040.4387210
624.39050.02151490
729.3362-0.1510730
834.3063-0.1024890
939.2911-0.007403080
1044.2830.03380650
1149.27880.02390520

To query features for all traffic participants we can just add their ID to the list:

dfs = extract_features((posfs, posft, iscolliding), roadway, scenes, ["bob", "alice"])
dfs["alice"]

11 rows × 3 columns

posfsposftiscolliding
Float64Float64Bool
120.00.00
221.0-1.1250
321.63441.171880
421.93191.15430
522.27370.2819820
622.6469-0.2566220
723.1753-0.2661320
823.9193-0.07009940
924.77850.05598750
1025.70170.06127950
1126.66270.01730430

The output is a dictionary mapping ID to dataframes. To learn more about DataFrames visit DataFrames.jl.

For the list of all possible features available see the documentation. Features are generally just function. AutomotiveSimulator provides some convenience to automatically generate feature function like distance_to_$x The distance_to function takes as input a vehicle ID and returns a function to extract the distance between the queried vehicle and the vehicle given to distance_to

distance_to("alice")
distance_to_alice (generic function with 1 method)

we can use this newly generated funciton in the feature extraction pipeline

dfs = extract_features((distance_to_alice, posfs), roadway, scenes, ["bob"])
dfs["bob"].distance_to_alice[1] # distance between Bob and Alice in the first scene.
20.000000000000018

This page was generated using Literate.jl.