Skip to content

Commit

Permalink
change the iterators and detectors, removed unused metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
A-acuto committed Apr 18, 2024
1 parent 88edd70 commit b7fc563
Showing 1 changed file with 22 additions and 40 deletions.
62 changes: 22 additions & 40 deletions docs/examples/Example_data_fusion_from_sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
# ^^^^^^^^^^^^^^^
import numpy as np
from datetime import datetime, timedelta
from itertools import tee

# %%
# Stone Soup general imports
Expand Down Expand Up @@ -210,8 +211,7 @@
from stonesoup.tracker.simple import MultiTargetTracker

# Load a detection reader
from stonesoup.buffered_generator import BufferedGenerator
from stonesoup.reader.base import DetectionReader
from stonesoup.feeder.multi import MultiDataFeeder

# %%
# Design the trackers components
Expand All @@ -220,18 +220,12 @@
# %%
# Detection reader and track deleter

# Detection reader
detection_reader = MultiDataFeeder([radar_simulator1, radar_simulator2])

# define a track deleter based on time measurements
deleter = UpdateTimeDeleter(timedelta(seconds=3), delete_last_pred=False)

# Create a dummy detector to parse the detections
class DummyDetector(DetectionReader):
def __init__(self, *args, **kwargs):
self.current = kwargs['current']

@BufferedGenerator.generator_method
def detections_gen(self):
yield self.current

# %%
# Unscented Kalman Filter

Expand Down Expand Up @@ -321,6 +315,10 @@ def detections_gen(self):
initiator=initiator_particles,
number_particles=n_particles)


# Create multiple copies of the detection reader for each tracker
dr1, dr2, dr3 = tee(detection_reader, 3)

# %%
# Instantiate each of the Trackers, without specifying the detector

Expand All @@ -329,22 +327,22 @@ def detections_gen(self):
deleter=deleter,
data_associator=data_associator_UKF,
updater=UKF_updater,
detector=None)
detector=dr1)

EKF_tracker = MultiTargetTracker(
initiator=EKF_initiator,
deleter=deleter,
data_associator=data_associator_EKF,
updater=EKF_updater,
detector=None)
detector=dr2)

# Instantiate the Particle filter as well
PF_tracker = MultiTargetTracker(
initiator=PF_initiator,
deleter=deleter,
data_associator=data_associator_PF,
updater=PF_updater,
detector=None)
detector=dr3)

# %%
# 3. Perform the measurement fusion algorithm and run the trackers
Expand All @@ -361,9 +359,6 @@ def detections_gen(self):
# Load the plotter
from stonesoup.plotter import Plotterly

# Load the metric manager
from stonesoup.metricgenerator.basicmetrics import BasicMetrics

# Load the OSPA metric managers
from stonesoup.metricgenerator.ospametric import OSPAMetric

Expand All @@ -380,14 +375,6 @@ def detections_gen(self):
# Set up the metrics
# ^^^^^^^^^^^^^^^^^^

# load the metrics for the filters
basic_UKF = BasicMetrics(generator_name='Unscented Kalman Filter', tracks_key='UKF_tracks',
truths_key='truths')
basic_EKF = BasicMetrics(generator_name='Extended Kalman Filter', tracks_key='EKF_tracks',
truths_key='truths')
basic_PF = BasicMetrics(generator_name='Particle Filter', tracks_key='PF_tracks',
truths_key='truths')

# OSPA
ospa_UKF_truth = OSPAMetric(c=40, p=1, generator_name='OSPA_UKF_truths',
tracks_key='UKF_tracks', truths_key='truths')
Expand All @@ -400,10 +387,7 @@ def detections_gen(self):
associator = TrackToTruth(association_threshold=30)

# Use a metric manager to deal with the various metrics
metric_manager = MultiManager([basic_UKF,
basic_EKF,
basic_PF,
ospa_UKF_truth,
metric_manager = MultiManager([ospa_UKF_truth,
ospa_EKF_truth,
ospa_PF_truth],
associator)
Expand All @@ -427,6 +411,11 @@ def detections_gen(self):
pf_tracks = set()
truths = set()

# create tracker iterators
UKF_tracker_iter = iter(UKF_tracker)
EKF_tracker_iter = iter(EKF_tracker)
PF_tracker_iter = iter(PF_tracker)

# list for all detections
full_detections = []

Expand All @@ -438,26 +427,19 @@ def detections_gen(self):
full_detections.extend(detections_1[1])
full_detections.extend(detections_2[1])

for detections in [detections_1, detections_2]:

for _ in (0, 1):
# Run the Unscented Kalman tracker
UKF_tracker.detector = DummyDetector(current=detections)
UKF_tracker.__iter__()
_, tracks = next(UKF_tracker)
_, tracks = next(UKF_tracker_iter)
ukf_tracks.update(tracks)
del tracks

# Run the Extended Kalman filter
EKF_tracker.detector = DummyDetector(current=detections)
EKF_tracker.__iter__()
_, tracks = next(EKF_tracker)
_, tracks = next(EKF_tracker_iter)
ekf_tracks.update(tracks)
del tracks

# Run the Particle filter Tracker
PF_tracker.detector = DummyDetector(current=detections)
PF_tracker.__iter__()
_, tracks = next(PF_tracker)
_, tracks = next(PF_tracker_iter)
pf_tracks.update(tracks)

# Add data to the metric manager
Expand Down

0 comments on commit b7fc563

Please sign in to comment.