# Initiator & Deleter deleter = CovarianceBasedDeleter(covar_trace_thresh=1E3) initiator = MultiMeasurementInitiator( GaussianState(np.array([[0], [0], [0], [0]]), np.diag([0, 100, 0, 1000])), measurement_model=measurement_model, deleter=deleter, data_associator=data_associator, updater=updater, min_points=3, ) # Tracker tracker = MultiTargetTracker( initiator=initiator, deleter=deleter, detector=detection_sim, data_associator=data_associator, updater=updater, ) # %% # Create Metric Generators # ------------------------ # Here we are going to create a variety of metrics. First up is some "Basic Metrics", that simply # computes the number of tracks, number to targets and the ratio of tracks to targets. Basic but # useful information, that requires no additional properties. from stonesoup.metricgenerator.basicmetrics import BasicMetrics basic_generator = BasicMetrics() # %%
from stonesoup.hypothesiser.distance import DistanceHypothesiser from stonesoup.measures import Mahalanobis hypothesiser = DistanceHypothesiser(predictor, updater, measure=Mahalanobis(), missed_distance=3) from stonesoup.dataassociator.neighbour import NearestNeighbour data_associator = NearestNeighbour(hypothesiser) deleter = UpdateTimeStepsDeleter(time_steps_since_update=2) # Create a Kalman multi-target tracker kalman_tracker = MultiTargetTracker(initiator=initiator, deleter=deleter, detector=sim, data_associator=data_associator, updater=updater) # %% # The final step is to iterate our tracker over the simulation: kalman_tracks = {} # Store for plotting later groundtruth_paths = {} # Store for plotting later detections = [] # Store for plotting later for time, ctracks in kalman_tracker.tracks_gen(): for track in ctracks: loc = (track.state_vector[0], track.state_vector[2]) if track not in kalman_tracks: kalman_tracks[track] = [] kalman_tracks[track].append(loc)
# been updated for a defined time period, in this case 10 minutes. from stonesoup.deleter.time import UpdateTimeDeleter deleter = UpdateTimeDeleter(datetime.timedelta(minutes=10)) # %% # Building and running the tracker # -------------------------------- # With all the individual components specified we can now build our tracker. This is as simple as # passing in the components. from stonesoup.tracker.simple import MultiTargetTracker tracker = MultiTargetTracker( initiator=initiator, deleter=deleter, detector=detector, data_associator=data_associator, updater=updater, ) # %% # Our tracker is built and our detections are ready to be read in from the CSV file, now we set the # tracker to work. This is done by initiating a loop to generate tracks at each time interval. # We'll keep a record of all tracks generated over time in a :class:`set` called `tracks`; as a # :class:`set` we can simply update this with `current_tracks` at each timestep, not worrying about # duplicates. tracks = set() for step, (time, current_tracks) in enumerate(tracker.tracks_gen(), 1): tracks.update(current_tracks) if not step % 10: print("Step: {} Time: {}".format(step, time))
data_associator=data_associator, updater=updater, min_points=min_detections) # %% # Run the Tracker # --------------- # With the components created, the multi-target tracker component is created, constructed from # the components specified above. This is logically the same as tracking code in the previous # tutorial section :ref:`auto_tutorials/09_Initiators_&_Deleters:Running the Tracker` from stonesoup.tracker.simple import MultiTargetTracker tracker = MultiTargetTracker( initiator=initiator, deleter=deleter, detector=detection_sim, data_associator=data_associator, updater=updater, ) # %% # In the case of using (J)PDA like in :ref:`auto_tutorials/07_PDATutorial:Run the PDA Filter` # and :ref:`auto_tutorials/08_JPDATutorial:Running the JPDA filter`, then the # :class:`~.MultiTargetMixtureTracker` would be used instead on the # :class:`~.MultiTargetTracker` used above. # # Plot the outputs # ^^^^^^^^^^^^^^^^ # We plot the output using a Stone Soup :class:`MetricGenerator` which does plots (in this instance # :class:`TwoDPlotter`. This will produce plots equivalent to that seen in previous tutorials. groundtruth = set()