{ "metadata": { "language": "Julia", "name": "", "signature": "sha256:c37e0bd8814d14817a84c0a09bb19e05ada76caaab79e4dda32ec3a0a65f55e3" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "Model Application\n", "=================\n", "\n", "This documentation covers the use of a model in simulation and tuning of the model parameters." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "# Process\n", "\n", "Model application is the process of using a model in simulation. A scene is propagated by a single time-step by applying the relevant vehicle-specific action model. Models were developed for free-flow, car following, and lane-changing.\n", "\n", "For each vehicle, the relevant behavior is identified and the appropriate features are extracted. These are used to condition on the target variables in the Bayesian network and a discrete sample is made. The discrete sample must then be converted to a continuous action. This action, composed of both an acceleration and a turnrate, is used to propagate the vehicle forward by one frame.\n", "\n", "" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Dynamics\n", "\n", "The vehicle dynamics take the form of simple linear Euler updates:\n", "\n", "$$\n", "v^{(t+1)} \\leftarrow v^{(t)} + a^\\text{fut} \\Delta t\n", "$$\n", "\n", "$$\n", "\\psi^{(t+1)} \\leftarrow \\psi^{(t)} + \\dot{\\psi}^\\text{fut} \\Delta t\n", "$$\n", "\n", "$$\n", "x^{(t+1)} \\leftarrow x^{(t)} + v^{(t+1)} \\cos (\\psi^{(t+1)}) \\Delta t\n", "$$\n", "\n", "$$\n", "y^{(t+1)} \\leftarrow y^{(t)} + v^{(t+1)} \\sin (\\psi^{(t+1)}) \\Delta t\n", "$$\n", "\n", "Improved accuracy was obtained by running a series of smaller updates for each frame." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Application Parameters\n", "\n", "Several parameters in the application can be tuned to produce better results. These parameters include the method we use in converting a discrete sample into a continuous sample, and a method for smoothing the input. Input smoothing is, *a-priori*, perhaps not necessary, but was shown to improve performance.\n", "\n", "Variable sampling and smoothing parameters\n", "\n", "| Parameter | Values |\n", "| ------------- | -------------|\n", "| sample scheme | uniform, zero-binned |\n", "| smoothing | none, SMA, WMA |\n", "| smoothing history | 2,3,4,5,6,7,8,9,10,11,12 frames |\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "There are two sampling schemes, a uniform sampling scheme and a zero-binning sampling scheme. The first assumes that variables within bins are distributed uniformally and samples from the bin accordingly. The second augments uniform sampling to return zero if the bin contains zero. This is especially useful in turn-rate, as it is often likely that a vehicle will continue travelling straight, and even small fluctuations in angle can cause significant deviations from the lane centerline at highway speeds.\n", "\n", "Smoothing is the act of fixing the input based on the previous inputs. Three methods were considered: no smoothing (just using the sampled value), sequential moving average (SMA), and a weighted moving average (WMA). The sequential moving average assigns equal weight to the final $n$ frames:\n", "\n", "$$\n", "SMA(n) = \\frac{1}{n} \\sum_{i=0}^{n-1} x^{(t-i)}\n", "$$\n", "\n", "The weighted moving average assigns older frames less weight in a linear fassion:\n", "\n", "$$\n", "WMA(n) = \\frac{\\sum_{i=0}^{n-1} (n-i) x^{(t-i)}}{\\sum_{i=0}^{n-1} (n-i)}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Training\n", "\n", "Models are trained using cyclic coordinate ascent, which sequentially optimizes each parameter. The objective function is the Kullback-Leibler divergence of the generated density from propagating a vehicle using the model compared to the density from real-world four-second trajectories. The KL-divergence measures the information loss when using distribution $Q$ to estimate $P$. Here $P$ is the true 2D histogram distribution from the real-world data and $Q$ is the distribution obtained with the model.\n", "\n", "$$\n", "D_{KL}(P||Q) = \\sum_i P(i) \\frac{P(i)}{Q(i)}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Two candidate distributions were considered for the 2D histogram: a categorical distribution and a Dirchlet distribution.\n", "\n", "A Dirichlet distribution $Dir(x, \\alpha = [\\alpha_1, \\ldots, \\alpha_K])$ is a multivariate distribution with probability density function\n", "\n", "$$\n", "p(x; \\alpha) = \\frac{\n", " \\Gamma\\left( \n", " \\sum^K_{k=1} \\alpha_k\n", " \\right)\n", "}{\n", " \\prod^K_{k=1} \\Gamma(\\alpha_k)\n", "} \n", "\\prod^K_{k=1} x^{\\alpha_k-1}_k\n", "$$\n", "\n", "For two Dirichlet distributions, $p(x; \\alpha)$ and $q(x; \\beta)$, the KL divergence is given by\n", "\n", "$$\n", "\\begin{align}\n", "\\textstyle\n", "KL(p\\parallel q) = & \\int p(x; \\alpha) \\log \\frac{p(x; \\alpha)}{q(x; \\beta)} dx \\nonumber \\\\\n", " = & \\> \\log \\frac{\\Gamma(\\alpha_0)}{\\Gamma(\\beta_0)} + \\sum^K_{k=1} \\log \\frac{\\Gamma(\\beta_k)}{\\Gamma(\\alpha_k)} \\\\\n", " & + \\sum^K_{k=1} (\\alpha_k-\\beta_k)\\left(\n", " \\psi(\\alpha_k) - \\psi(\\alpha_0)\n", " \\right) \\nonumber\n", "\\end{align}\n", "$$" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "This training is conducted in `calibrate_sim_params.jl`." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### Emergent Variables\n", "\n", "Emergent variables can be extracted from simulation. These include the number of lane changes, mean distance to lane centerline, lane speed, etc. Emergent variables are *not* directly represented in the model, but emerge from propagation. They can thus be used to validate a model, as is done in the paper.\n", "\n", "The code associated with emergent variable extraction is in `sim.jl` in the CarEM module." ] } ], "metadata": {} } ] }