Tracking

Scoring

Defines some functions that compare features and score them.

Deprecated scoring functions are not imported to the parent module!

Note

Functions with suffix _v are vectorized with numpy.

score_ids_best_fit(ids1, ids2, length=12)[source]

Compares two lists of ids by choosing the pair with the best score.

Deprecated since version September: 2016 This scoring is used with data from the old Computer Vision Pipeline.

Parameters:
  • ids1 (list of int) – Iterable with ids as integers as base ids
  • ids2 (list of int) – Iterable with ids as integers to compare base to
Keyword Arguments:
 

length (Optional int) – number of bits in the bit array used to compare ids

Returns:

Uses Hamming distance of best matching pair

Return type:

float

score_ids_best_fit_rotating(ids1, ids2, rotation_penalty=1, length=12)[source]

Compares two lists of ids by choosing the pair best score by rotating the bits.

Deprecated since version September: 2016 This scoring is used with data from the old Computer Vision Pipeline.

Parameters:
  • ids1 (list of int) – Iterable with ids as integers as base ids
  • ids2 (list of int) – Iterable with ids as integers to compare base to
Keyword Arguments:
 
  • rotation_penalty (Optional float) – the penalty that is added for a rotation of 1 to the left or right
  • length (Optional int) – number of bits in the bit array used to compare ids
Returns:

Uses Hamming distance of best matching (rotated) pair

Return type:

float

score_ids_and_orientation(id_orientation_tuple1, id_orientation_tuple2, length=12, range_bonus_orientation=30)[source]

Compares lists of ids by choosing the pair with the best score and considering orientation.

The bonus is equal to the negative score of one non matching bit.

Deprecated since version September: 2016 This scoring is used with data from the old Computer Vision Pipeline.

Parameters:
  • id_orientation_tuple1 (tuple) – (Iterable with ids, Iterable with orientations)
  • id_orientation_tuple2 (tuple) – (Iterable with ids, Iterable with orientations)
Keyword Arguments:
 
  • length (int) – number of bits in the bit array used to compare ids
  • range_bonus_orientation (float) – range in degrees, so that two orientations get a bonus
Returns:

Uses Hamming distance of best matching pair with bonus for same orientation

Return type:

float

score_id_sim(id1, id2)[source]

Compares two id frequency distributions for similarity

Parameters:
  • id1 (list of float) – id bit frequency distribution of base id
  • id2 (list of float) – id bit frequency distribution of id to compare base to
Returns:

Use Manhattan distance \(\sum_i |id1_i - id2_i|\)

Return type:

float

score_id_sim_v(detections1, detections2)[source]

Compares two id frequency distributions for similarity (vectorized)

Parameters:
Returns:

Use Manhattan distance \(\sum_i |id1_i - id2_i|\)

Return type:

np.array

score_id_sim_orientation(id1, or1, id2, or2, range_bonus_orientation=30, value_bonus_orientation=1.0)[source]

Compares two id frequency distributions for similarity

Parameters:
  • id1 (list of float) – id bit frequency distribution of base id
  • or1 (float) – orientation belonging to id1
  • id2 (list of float) – id bit frequency distribution of id to compare base to
  • or2 (float) – orientation belonging to id2
Keyword Arguments:
 
  • range_bonus_orientation (Optional float) – range in degrees, so that two orientations get a bonus
  • value_bonus_orientation (Optional float) – value to add if orientations are within range_bonus_orientation
Returns:

Use Manhattan distance \(\sum_i |id1_i - id2_i|\)

Return type:

float

score_id_sim_orientation_v(detections1, detections2, range_bonus_orientation=0.5235987755982988, value_bonus_orientation=1.0)[source]

Compares id frequency distributions for similarity (vectorized)

Parameters:
Keyword Arguments:
 
  • range_bonus_orientation (Optional float) – range in degrees, so that two orientations get a bonus
  • value_bonus_orientation (Optional float) – value to add if orientations are within range_bonus_orientation
Returns:

Use Manhattan distance \(\sum_i |id1_i - id2_i|\)

Return type:

np.array

score_id_sim_rotating(id1, id2, rotation_penalty=0.5)[source]

Compares two id frequency distributions for similarity by rotating them

Instead of only using the distance metric, one id is rotated to check for better results.

Parameters:
  • id1 (list) – id bit frequency distribution of base id
  • id2 (list) – id bit frequency distribution of id to compare base to
Keyword Arguments:
 

rotation_penalty (float) – the penalty that is added for a rotation of 1 to the left or right

Returns:

Manhattan distance but also rotated with added rotation_penalty.

Return type:

float

score_id_sim_rotating_v(detections1, detections2, rotation_penalty=0.5)[source]

Compares id frequency distributions for similarity by rotating them (vectorized)

Instead of only using the distance metric, one id is rotated to check for better results.

Note

The calculation of this feature is quite expensiv compared to score_id_sim_v()!

Parameters:
Keyword Arguments:
 

rotation_penalty (Optional float) – the penalty that is added for a rotation of 1 to the left or right

Returns:

Manhattan distance but also rotated with added rotation_penalty.

Return type:

np.array

score_id_sim_tracks_median_v(tracks1, tracks2)[source]

Compares id frequency distributions of tracks by comparing the median (vectorized)

Parameters:
  • tracks1 (list of Track) – Iterable with Tracks
  • tracks2 (list of Track) – Iterable with Tracks
Returns:

Use Manhattan distance \(\sum_i |Median(ids1)_i - Median(ids2)_i|\)

Return type:

np.array

distance_orientations(rad1, rad2)[source]

Calculates the distance between two orientations.

Orientations in rad are converted to degrees then the difference is calculated.

Parameters:
  • rad1 (float) – orientation of first detection in rad
  • rad2 (float) – orientation of second detection in rad
Returns:

distance between two orientation in degrees, e.g. 90 for -pi/2 and pi

Return type:

float

distance_orientations_v(detections1, detections2, meta_key=None)[source]

Calculates the distances between orientations (vectorized)

Orientations are expected to be in rad.

Parameters:
Keyword Arguments:
 

meta_key (Optional str) – Instead of Detection.orientation use value from Detection.meta

Returns:

distance between orientations of detections line by line in rad

Return type:

np.array

distance_positions_v(detections1, detections2)[source]

Calculates the euclidean distances between the x and y positions (vectorized)

Parameters:
Returns:

Euclidean distance between detections line by line

Return type:

np.array

bit_array_to_int_v(bit_arrays, threshold=0.5, endian='little')[source]

Converts the bit frequency distribution of the id to an integer representation.

Note

Instead of bit_arrays you could also pass lists with Detection objects. In this case the Detection.beeId is used and interpreted as bit array.

Parameters:

bit_arrays (list of arrays or Detection) – Iterable with ids to decode.

Keyword Arguments:
 
  • threshold (Optional float) – values >= threshold are interpreted as 1
  • endian (Optional str) – Either little for little endianess or big for big endianess.
Returns:

the decoded ids represented as integer

Return type:

list of int

calc_median_ids(tracks)[source]

Helper to calculate the median bit for all the ids in the given track.

Note

For performance reasons the median id is saved as meta key and only is recalculated if the length of the track changes.

Parameters:tracks (list of Track) – Iterable with Tracks
Returns:median for all the bits in the given track
Return type:np.array
calc_track_ids(tracks)[source]

Function to calculate an id for a Track.

This functions calculates the median for each bit of the detections in the track and then uses a threshold to decide whether a bit is set or not.

Note

Used as default implementation to calculate Score.calc_id.

Parameters:tracks (list of Track) – A list of Track object to calculate an id based on it’s list of Detection objects.
Returns:the calculated id for the Track
Return type:int

Training

Walker