best_detection(detections, predictions, [minimum_overlap], [relative_prediction_threshold]) -> bounding_box, prediction

  Computes the best detection for the given detections and according predictions.

  This is achieved by computing a weighted sum of detections that overlap with the best detection (the one with the highest prediction), where the weights are based on the predictions.
  Only detections with according prediction values > 0 are considered.

  **Parameters:**

  ``detections`` : [:py:class:`BoundingBox`]
    The detected bounding boxes.

  ``predictions`` : [float]
    The predictions for the ``detections``.

  ``minimum_overlap`` : float between 0 and 1
    The minimum overlap (in terms of Jaccard :py:meth:`BoundingBox.similarity`) of bounding boxes with the best detection to be considered.

  ``relative_prediction_threshold`` : float between 0 and 1
    Limits the bounding boxes to those that have a prediction value higher then ``relative_prediction_threshold * max(predictions)``

  **Returns:**

  ``bounding_box`` : :py:class:`BoundingBox`
    The bounding box which has been merged from the detections

  ``prediction`` : float
    The prediction value of the bounding box, which is a weighted sum of the predictions with minimum overlap

def best_detection(detections, predictions, minimum_overlap = 0.2, relative_prediction_threshold = 0.25):
  """best_detection(detections, predictions, [minimum_overlap], [relative_prediction_threshold]) -> bounding_box, prediction

  Computes the best detection for the given detections and according predictions.

  This is achieved by computing a weighted sum of detections that overlap with the best detection (the one with the highest prediction), where the weights are based on the predictions.
  Only detections with according prediction values > 0 are considered.

  **Parameters:**

  ``detections`` : [:py:class:`BoundingBox`]
    The detected bounding boxes.

  ``predictions`` : [float]
    The predictions for the ``detections``.

  ``minimum_overlap`` : float between 0 and 1
    The minimum overlap (in terms of Jaccard :py:meth:`BoundingBox.similarity`) of bounding boxes with the best detection to be considered.

  ``relative_prediction_threshold`` : float between 0 and 1
    Limits the bounding boxes to those that have a prediction value higher then ``relative_prediction_threshold * max(predictions)``

  **Returns:**

  ``bounding_box`` : :py:class:`BoundingBox`
    The bounding box which has been merged from the detections

  ``prediction`` : float
    The prediction value of the bounding box, which is a weighted sum of the predictions with minimum overlap
  """
  # remove all negative predictions since they harm the calculation of the weights
  detections = [detections[i] for i in range(len(detections)) if predictions[i] > 0]
  predictions = [predictions[i] for i in range(len(predictions)) if predictions[i] > 0]

  if not detections:
    raise ValueError("No detections with a prediction value > 0 have been found")

  # keep only the bounding boxes with the highest overlap
  detections, predictions = overlapping_detections(detections, numpy.array(predictions), minimum_overlap)

  return average_detections(detections, predictions, relative_prediction_threshold)