Optimal Sub-Pattern Assignment (OSPA) Metric

class stonesoup.metricgenerator.ospametric.GOSPAMetric(p: float, c: float, switching_penalty: float = 0.0, measure: Measure = Euclidean(mapping=None, mapping2=None), generator_name: str = 'gospa_generator', tracks_key: str = 'tracks', truths_key: str = 'groundtruth_paths')[source]

Bases: MetricGenerator

Computes the Generalized Optimal SubPattern Assignment (GOSPA) metric for two sets of Track objects. This implementation of GOSPA is based on the modified Jonker-Volgenant algorithm.

The GOSPA metric is calculated at each time step in which a Track object is present

Reference:

[1] A. S. Rahmathullah, A. F. García-Fernández, L. Svensson, Generalized optimal sub-pattern assignment metric, 2016, [online] Available: http://arxiv.org/abs/1601.05585.

Parameters:
  • p (float) – 1<=p<infty, exponent.

  • c (float) – c>0, cutoff distance.

  • switching_penalty (float, optional) – Penalty term for switching.

  • measure (Measure, optional) – Distance measure to use. Default Euclidean()

  • generator_name (str, optional) – Unique identifier to use when accessing generated metrics from MultiManager

  • tracks_key (str, optional) – Key to access set of tracks added to MetricManager

  • truths_key (str, optional) – Key to access set of ground truths added to MetricManager. Or key to access a second set of tracks for track-to-track metric generation

p: float

1<=p<infty, exponent.

c: float

c>0, cutoff distance.

switching_penalty: float

Penalty term for switching.

measure: Measure

Distance measure to use. Default Euclidean()

generator_name: str

Unique identifier to use when accessing generated metrics from MultiManager

tracks_key: str

Key to access set of tracks added to MetricManager

truths_key: str

Key to access set of ground truths added to MetricManager. Or key to access a second set of tracks for track-to-track metric generation

compute_metric(manager)[source]

Compute the metric using the data in the metric manager

Parameters:

manager (MetricManager) – contains the data to be used to create the metric(s)

Returns:

metric – Containing the metric information. The value of the metric is a list of metrics at each timestamp

Return type:

list Metric

static extract_states(object_with_states, return_ids=False)[source]

Extracts a list of states from a list of (or single) objects containing states. This method is defined to handle StateMutableSequence and State types.

Parameters:
  • object_with_states (object containing a list of states) – Method of state extraction depends on the type of the object

  • return_ids (If we should return obj ids as well.)

Return type:

list of State

compute_over_time(measured_states, measured_state_ids, truth_states, truth_state_ids)[source]

Compute the GOSPA metric at every timestep from a list of measured states and truth states.

Parameters:
  • measured_states (List of states created by a filter)

  • measured_state_ids (ids for which state belongs in)

  • truth_states (List of truth states to compare against)

  • truth_state_ids (ids for which truth state belongs in)

Returns:

  • metric (TimeRangeMetric covering the duration that states)

  • exist for in the parameters. metric.value contains a list of metrics

  • for the GOSPA metric at each timestamp

compute_assignments(cost_matrix)[source]

Compute assignments using modified Jonker-Volgenant algorithm

Parameters:

cost_matrix (Matrix (size mxn) that denotes the cost of assigning) – mth truth state to each of the n measured states.

Returns:

  • truth_to_measured (np.ndarray) – Vector of size m, which has indices of the measured objects or ‘-1’ if unassigned.

  • measured_to_truth (np.ndarray) – Vector of size n, which has indices of the truth objects or ‘-1’ if unassigned.

  • opt_cost (float) – Scalar value of the optimal assignment

compute_cost_matrix(track_states, truth_states, complete=False)[source]

Creates the cost matrix between two lists of states

This distance measure here will return distances minimum of either c or the distance calculated from Measure.

Parameters:
  • track_states (list of states)

  • truth_states (list of states)

  • complete (bool) – Cost matrix will be square, with c present for where there is a mismatch in cardinality

Returns:

cost_matrix – Matrix of distance between each element in each list of states

Return type:

np.ndarray

compute_gospa_metric(measured_states, truth_states)[source]

Computes GOSPA metric between measured and truth states.

Parameters:
  • measured_states (list of State) – list of state objects to be assigned to the truth

  • truth_states (list of State) – list of state objects for the truth points

Returns:

  • gospa_metric (Dictionary containing GOSPA metric for alpha = 2.) – GOSPA metric is divided into four components: 1. distance, 2. localisation, 3. missed, and 4. false. Note that distance = (localisation + missed + false)^1/p

  • truth_to_measured_assignment (Assignment matrix.)

class stonesoup.metricgenerator.ospametric.OSPAMetric(p: float, c: float, switching_penalty: float = 0.0, measure: Measure = Euclidean(mapping=None, mapping2=None), generator_name: str = 'ospa_generator', tracks_key: str = 'tracks', truths_key: str = 'groundtruth_paths')[source]

Bases: GOSPAMetric

Computes the Optimal SubPattern Assignment (OSPA) distance [1] for two sets of Track objects. The OSPA distance is measured between two point patterns.

The OSPA metric is calculated at each time step in which a Track object is present

Reference:

[1] A Consistent Metric for Performance Evaluation of Multi-Object Filters, D. Schuhmacher, B. Vo and B. Vo, IEEE Trans. Signal Processing 2008

Parameters:
  • p (float) – Norm associated to distance

  • c (float) – Maximum distance for possible association

  • switching_penalty (float, optional) – Penalty term for switching.

  • measure (Measure, optional) – Distance measure to use. Default Euclidean()

  • generator_name (str, optional) – Unique identifier to use when accessing generated metrics from MultiManager

  • tracks_key (str, optional) – Key to access set of tracks added to MetricManager

  • truths_key (str, optional) – Key to access set of ground truths added to MetricManager. Or key to access a second set of tracks for track-to-track metric generation

c: float

Maximum distance for possible association

p: float

Norm associated to distance

generator_name: str

Unique identifier to use when accessing generated metrics from MultiManager

compute_over_time(measured_states, meas_ids, truth_states, truth_ids)[source]

Compute the OSPA metric at every timestep from a list of measured states and truth states

Parameters:
  • measured_states (list of State) – Created by a filter

  • truth_states (list of State) – Truth states to compare against

Returns:

Covering the duration that states exist for in the parameters. Metric.value contains a list of metrics for the OSPA distance at each timestamp

Return type:

TimeRangeMetric

compute_OSPA_distance(track_states, truth_states)[source]

Computes the Optimal SubPattern Assignment (OSPA) metric for a single time step between two point patterns. Each point pattern consisting of a list of State objects.

The function \(\bar{d}_{p}^{(c)}\) is the OSPA metric of order \(p\) with cut-off \(c\). The OSPA metric is defined as:

\[\begin{equation*} \bar{d}_{p}^{(c)}({X},{Y}) := \Biggl( \frac{1}{n} \Bigl({min}_{\substack{ \pi\in\Pi_{n}}} \sum_{i=1}^{m} d^{(c)}(x_{i},y_{\pi(i)})^{p}+ c^{p}(n-m)\Bigr) \Biggr)^{ \frac{1}{p} } \end{equation*}\]
Parameters:
  • track_states (list of State)

  • truth_states (list of State)

Returns:

The OSPA distance

Return type:

SingleTimeMetric