swarmsort.assignment module

SwarmSort Assignment Algorithms Module

This module contains assignment algorithms for solving the tracking assignment problem. It includes both Hungarian (optimal) and Greedy (fast) assignment methods, as well as hybrid approaches for different tracking scenarios.

Functions:

numba_greedy_assignment: Fast greedy assignment algorithm compute_assignment_priorities: Priority computation for assignments hungarian_assignment_wrapper: Wrapper for scipy’s Hungarian algorithm

swarmsort.assignment.compute_assignment_priorities(cost_matrix, max_distance)[source]

Compute priority scores for greedy assignment.

Lower scores indicate higher priority (better matches should be assigned first).

Parameters:
  • cost_matrix (ndarray) – Cost matrix [N_det, N_track]

  • max_distance (float) – Maximum allowed distance

Return type:

ndarray

Returns:

Priority matrix with same shape as cost_matrix

swarmsort.assignment.hungarian_assignment_wrapper(cost_matrix, max_distance)[source]

Wrapper for scipy’s Hungarian algorithm with distance thresholding.

Parameters:
  • cost_matrix (ndarray) – Cost matrix [N_det, N_track]

  • max_distance (float) – Maximum allowed distance for matching

Return type:

Tuple[List[Tuple[int, int]], List[int], List[int]]

Returns:

Tuple of (matches, unmatched_detections, unmatched_tracks)

swarmsort.assignment.hybrid_assignment(cost_matrix, max_distance, greedy_threshold=30.0, hungarian_fallback_threshold=100.0)[source]

Hybrid assignment using greedy for obvious matches and Hungarian for remainder.

This function first performs greedy assignment on high-confidence (low-cost) matches, then uses Hungarian algorithm for the remaining ambiguous cases.

Parameters:
  • cost_matrix (ndarray) – Cost matrix [N_det, N_track]

  • max_distance (float) – Maximum allowed distance

  • greedy_threshold (float) – Threshold for greedy assignment

  • hungarian_fallback_threshold (float) – Threshold for Hungarian assignment

Return type:

Tuple[List[Tuple[int, int]], List[int], List[int]]

Returns:

Tuple of (matches, unmatched_detections, unmatched_tracks)

swarmsort.assignment.numba_greedy_assignment(cost_matrix, max_distance)[source]

Optimized greedy assignment using vectorized operations.

This function performs greedy assignment by iteratively selecting the minimum cost match until all possible matches are made.

Parameters:
  • cost_matrix (ndarray) – Cost matrix [N_det, N_track]

  • max_distance (float) – Maximum allowed distance for matching

Returns:

  • matches: Array of matched pairs [(det_idx, track_idx), …]

  • unmatched_detections: Array of unmatched detection indices

  • unmatched_tracks: Array of unmatched track indices

Return type:

Tuple of (matches, unmatched_detections, unmatched_tracks) where