Skip to content
Snippets Groups Projects
Commit dd325dfa authored by Anton Kullberg's avatar Anton Kullberg
Browse files

ipynb: added saving of ex2 results for use in ex3

parent 60c98edf
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id:7b4f552e-2590-44c2-ad81-13866058fb1e tags:
## <center> Target Tracking -- Exercise 2 </center>
### <center> Anton Kullberg </center>
This report contains solutions for the second set of exercises in the Target Tracking course given at Linköping University during fall 2021.
%% Cell type:code id:3e6fa80c-07ba-4112-a0d3-2b3aec744e1d tags:
``` python
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
sns.set()
rng = np.random.default_rng(13)
from src.sim import generate_data
from src.trajectories import get_ex2_trajectories
import src.gaters as gaters
import src.filters as filters
import src.associators as associators
import src.trackers as trackers
import src.plotters as plotters
import src.models as models
import src.logic as logic
from src.utility import match_tracks_to_ground_truth, save_result
# Get the necessary trajectories
trajectories = get_ex2_trajectories()
trajs = ['T1', 'T3', 'T5', 'T6'] # Select the trajectories to use
filtered_trajs = {key: T for key, T in trajectories.items() if key in trajs}
```
%% Cell type:markdown id:1f7e085f-ebe1-4f9c-a38b-79917e802d32 tags:
### Task 2.2 - 2.3 - GNN and JPDA
A GNN tracker and a JPDA tracker were implemented, see src.trackers. The model setup is as follows
##### **Sensor Model**
The sensor model is the standard distance and bearing radar with $\mathbf{R}=\mathrm{diag}[10, 0.001]^2$. The probability of detection is set to $P_D=0.9$.
##### **Gating**
Mahalanobis gating is used with $\gamma=9.2$.
##### **Clutter Model**
The volume is rectangular with $0\leq x\leq 2500$ and $0\leq y\leq2000$. Further, $\beta_{FA}V=2$.
##### **Track Logic**
A score-based track logic was used with an exponential forgetting factor to avoid integrator wind-up. The forgetting factor was tuned to $\lambda=0.6$. The new target rate $\beta_{NT}=\beta_{FA}$. Further, the probability of confirming false tracks $P_{FC}0.1\%$ and the probability of rejecting true tracks is $P_{TM}=1\%$.
##### **Motion Model**
The motion model is chosen as a CV model with $\mathbf{Q}=10\mathbf{I}$ which yielded good tracking performance for both GNN and JPDA.
##### **Filter**
The filter was chosen as an EKF for simplicity (and it seemed to work fine).
##### **Initialization**
The tracks were initialized at the measurement (converted to the positional domain) with a $0$ velocity. The initial uncertainty was set to $\mathbf{P}_0=\mathsc{diag}[10, 10, 100, 100]$ to account for the unknown initial velocity. The track score is initially set to $L_t=0$.
%% Cell type:code id:ad8aeebb tags:
``` python
R = np.diag([10, 0.001])**2
PD = 0.9
lam = 2
volume = dict(xmin=0, xmax=2500, ymin=0, ymax=2000)
V = (volume['xmax']-volume['xmin'])*(volume['ymax']-volume['ymin'])
Bfa = lam/V
sensor_model = models.radar_model(R=R, PD=PD)
clutter_model = dict(volume=volume, lam=lam, Bfa=Bfa)
Bnt = Bfa
q = 10
motion_model = models.cv_model(Q=q*np.identity(2), D=2, T=1)
# Setup Gater
gamma = 9.2
gater = gaters.MahalanobisGater(sensor_model, gamma)
P0 = np.diag([10, 10, 100, 100])
Ptm = 0.01
Pfc = 0.001
lam = 0.6
logic_params = dict(PD=sensor_model['PD'], PG=1, lam=lam, Ptm=Ptm, Pfc=Pfc, Bfa=Bfa, Ldel=1*np.log(Ptm/(1-Pfc)), Bnt=Bnt)
def init_track(y, k, identity, filt):
track = dict(stage='tentative', Lt=0, x=[], P=[], t=[k], identity=identity, associations=[k], filt=filt)
x0 = np.concatenate(plotters.radar_to_pos(y[:, None])).flatten()
x0 = np.hstack([x0, np.zeros((2,))])
track['x'] = [x0]
track['P'] = [P0]
return track
filt = filters.EKF(motion_model, sensor_model)
```
%% Cell type:markdown id:30f60524-b6cb-48c6-bbee-c69d8f72bdf2 tags:
#### Apply GNN and JPDA
Generates measurements from the true tracks and evaluates those measurements with the JPDA and GNN tracker.
%% Cell type:code id:31e8ca55-8bb0-4662-977a-857d8cdf4ea2 tags:
``` python
jpda = trackers.JPDA(logic.score_logic, logic_params, init_track, filt, gater, clutter_model)
gnn = trackers.GNN(logic.score_logic, logic_params, init_track, filt, gater, clutter_model)
Y = generate_data(filtered_trajs, sensor_model, clutter_model, rng)
jpda_tracks, jpda_confirmed_tracks = jpda.evaluate(Y)
gnn_tracks, gnn_confirmed_tracks = gnn.evaluate(Y)
```
%% Cell type:markdown id:16eb8a37-895f-40a6-aefd-3d523e035d64 tags:
#### Match the tracks to ground truth
The tracks are matched according to the following criteria:
- The initial point of each track is matched to the closest point of each true trajectory.
- The RMSE to each track is then calculated and the lowest RMSE is chosen as the true trajectory for this track.
Limitations: several tracks can match a specific true trajectory. (Hopefully not an issue, at least not here).
%% Cell type:code id:0c29b3fb-55ac-4c19-9acb-b493e536bd8d tags:
``` python
from src.utility import match_tracks_to_ground_truth
jpda_matches = match_tracks_to_ground_truth(jpda_confirmed_tracks, filtered_trajs)
gnn_matches = match_tracks_to_ground_truth(gnn_confirmed_tracks, filtered_trajs)
jpdaresult = dict(matches=jpda_matches,
tracks=jpda_tracks,
confirmed_tracks=jpda_confirmed_tracks,
Y=Y)
gnnresult = dict(matches=gnn_matches,
tracks=gnn_tracks,
confirmed_tracks=gnn_confirmed_tracks,
Y=Y)
save_result('jpda_result_sim', jpdaresult)
save_result('gnn_result_sim', gnnresult)
```
%% Cell type:markdown id:3be8ea4b-7d23-42a3-a4b2-bff1ab331767 tags:
#### Plots
Produces three plots for each tracker.
- Plot 1: All the confirmed tracks over time with their birth and death.
- Plot 2: RMSE of each confirmed track to its matched true trajectory. Plotted over the normalized trajectory length.
- Plot 3: The tracks and all of the measurements together with the ground truths.
%% Cell type:code id:41a6fabc-4074-4c6e-8e44-80693c4409a9 tags:
``` python
gnnfig = plotters.plot_result_ex2_2(gnnresult, filtered_trajs)
plt.suptitle('GNN', fontsize=20)
jpdafig = plotters.plot_result_ex2_2(jpdaresult, filtered_trajs)
plt.suptitle('JPDA', fontsize=20)
plt.show()
```
%% Cell type:markdown id:2681a406-0615-49f7-8043-b306887d5fe0 tags:
#### Comments
Both the GNN and JPDA capture all four tracks good. The GNN has a slightly lower RMSE overall which seems reasonable given the "low" clutter rate and only a few track cross-overs.
%% Cell type:markdown id:8058636f-682b-493c-aad5-374fb6f845df tags:
### Task 2.4 - Mysterious Data
A GNN and a JPDA tracker were applied to the mysterious data set. The design choices are listed below.
##### **Sensor Model**
The sensor model is the standard distance and bearing radar as before with the same noise parameters. The probability of detection was set to $P_D=0.9$.
##### **Gating**
Mahalanobis gating was used with $\gamma=9.2$.
##### **Clutter Model**
The tracking volume was established by inspecting the measurement data in the positional domain. The volume is rectangular with $-2000\leq x\leq 2000$ and $-21000\leq y\leq-17000$. As before $\beta_{FA}V=2$.
##### **Track Logic**
A score-based track logic was used with an exponential forgetting factor to avoid integrator wind-up. The forgetting factor was tuned to $\lambda=0.95$. The new target rate $\beta_{NT}=\beta_{FA}$. Further, the probability of confirming false tracks $P_{FC}0.1\%$ and the probability of rejecting true tracks is $P_{TM}=1\%$.
##### **Motion Model**
After inspection of the measurement data in the positional domain, a CV model was chosen as the motion model. The process noise was tuned to $\mathbf{Q}=5e4\mathbf{I}$ which yielded good tracking performance for both GNN and JPDA.
##### **Filter**
The filter was chosen as an EKF for simplicity (and it seemed to work fine).
##### **Initialization**
The tracks were initialized at the measurement (converted to the positional domain) with a $0$ velocity. The initial uncertainty was set to $\mathbf{P}_0=\mathsc{diag}[100, 100, 1000, 1000]$ to account for the unknown initial velocity. The track score is initially set to $L_t=0$.
The tracks were initialized at the measurement (converted to the positional domain) with a $0$ velocity. The initial uncertainty was set to $\mathbf{P}_0=\mathrm{diag}[100, 100, 1000, 1000]$ to account for the unknown initial velocity. The track score is initially set to $L_t=0$.
%% Cell type:markdown id:dd9637ca-ccc3-46fe-bdfe-4f32faddd2a8 tags:
##### **Model setup**
Makes the necessary changes to the model setup.
%% Cell type:code id:e8add90a-bb80-446d-9380-74d26ee43661 tags:
``` python
from scipy.io import loadmat
dat = loadmat('data/ex2data.mat')
dat['Y'] = [yk.reshape(2, -1) for yk in dat['Y'].flatten()]
T = 0.26
volume = dict(xmin=-2000, xmax=2000, ymin=-21000, ymax=-17000)
q = 5e4
motion_model = models.cv_model(Q=q*np.identity(2), D=2, T=T)
V = (volume['xmax']-volume['xmin'])*(volume['ymax']-volume['ymin'])
Bfa = lam/V
clutter_model = dict(volume=volume, lam=lam, Bfa=Bfa)
P0 = np.diag([100, 100, 1000, 1000])
logic_params['lam'] = 0.95
logic_params['Bnt'] = Bfa
filt = filters.EKF(motion_model, sensor_model)
```
%% Cell type:markdown id:62d5a1a0-fd3d-4419-87bb-b989d2c1b1d4 tags:
#### Apply the JPDA and GNN trackers
Applies the JPDA and GNN to the provided data.
%% Cell type:code id:d955d2bc-9ee6-4ca2-bd0f-4ddf9c88ff68 tags:
``` python
jpda = trackers.JPDA(logic.score_logic, logic_params, init_track, filt, gater, clutter_model)
gnn = trackers.GNN(logic.score_logic, logic_params, init_track, filt, gater, clutter_model)
jpda_tracks, jpda_confirmed_tracks = jpda.evaluate(dat['Y'])
gnn_tracks, gnn_confirmed_tracks = gnn.evaluate(dat['Y'])
```
%% Cell type:markdown id:c1038ba5-c8e7-46d0-a91a-7be7cd9ef4bc tags:
#### Plots
Produces two plots per tracker.
- Plot 1: Confirmed tracks over time with birth and possible death of tracks.
- Plot 2: The tracks and all of the measurements.
%% Cell type:code id:059a5880-31fe-40ba-acf7-755e1b002ec5 tags:
``` python
jpda_result = dict(Y=dat['Y'],
tracks=jpda_tracks,
confirmed_tracks=jpda_confirmed_tracks)
gnn_result = dict(Y=dat['Y'],
tracks=gnn_tracks,
confirmed_tracks=gnn_confirmed_tracks)
plotters.plot_result_ex2_24(gnn_result)
plt.suptitle('GNN', fontsize=20)
plotters.plot_result_ex2_24(jpda_result)
plt.suptitle('JPDA', fontsize=20)
plt.show()
```
%% Cell type:markdown id:50563376-26b3-40f8-98bc-6ded016a0eb3 tags:
#### Comments
Both the GNN and JPDA manage to keep both tracks the entire time. The GNN results in two "U"-shaped tracks whereas the JPDA results in "S"-shaped tracks. Without more information, it is impossible to say which is correct. However, the JPDA tracker results in a smoother trajectory, probably because of the soft measurement assignments.
%% Cell type:code id:99bb7ff2-1b69-4468-b9d6-7590a4870863 tags:
``` python
save_result('jpda_result_myst', jpda_result)
save_result('gnn_result_myst', gnn_result)
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment