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)) # %% # Checking and plotting results # ----------------------------- # The tracker has now run over the full data set and produced an output tracks. In this data set, # from the below, we can see that we generated different number of tracks: len(tracks) # %% # Versus the number of unique vessels/|MMSI|_: len({track.metadata['MMSI'] for track in tracks})
# %% # Once we've created a set of metrics, these are added to a Metric Manager, along with the # associator. The associator can be used by multiple metric generators, only being run once as this # can be a computationally expensive process; in this case, only SIAP Metrics requires it. from stonesoup.metricgenerator.manager import SimpleManager metric_manager = SimpleManager([basic_generator, ospa_generator, siap_generator, plot_generator], associator=associator) # %% # Tracking and Generating Metrics # ------------------------------- # With this basic tracker built and metrics ready, we'll now run the tracker, adding the sets of # :class:`~.GroundTruthPath`, :class:`~.Detection` and :class:`~.Track` objects: to the metric # manager. for time, tracks in tracker.tracks_gen(): metric_manager.add_data( groundtruth_sim.groundtruth_paths, tracks, detection_sim.detections, overwrite=False, # Don't overwrite, instead add above as additional data ) # %% # With the tracker run and data in the metric manager, we'll now run the generate metrics method. # This will also generate the plot, which will be rendered automatically below, which will give a # visual overview plt.rcParams["figure.figsize"] = (10, 8) metrics = metric_manager.generate_metrics() # %% # So first we'll loop through the metrics and print out the basic metrics, which simply gives # details on number of tracks versus targets.
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) for truth in groundtruth_sim.current[1]: loc = (truth.state_vector[0], truth.state_vector[2]) if truth not in groundtruth_paths: groundtruth_paths[truth] = [] groundtruth_paths[truth].append(loc) for detection in sim.detections: detect_state = detection.measurement_model.inverse_function(detection) loc = (detect_state[0], detect_state[2])