def test_mota_motp():
    """Tests values of MOTA and MOTP."""
    acc = mm.MOTAccumulator()

    # All FP
    acc.update([], [1, 2], [], frameid=0)
    # All miss
    acc.update([1, 2], [], [], frameid=1)
    # Match
    acc.update([1, 2], [1, 2], [[1, 0.5], [0.3, 1]], frameid=2)
    # Switch
    acc.update([1, 2], [1, 2], [[0.2, np.nan], [np.nan, 0.1]], frameid=3)
    # Match. Better new match is available but should prefer history
    acc.update([1, 2], [1, 2], [[5, 1], [1, 5]], frameid=4)
    # No data
    acc.update([], [], [], frameid=5)

    mh = mm.metrics.create()
    metr = mh.compute(acc, return_dataframe=False, return_cached=True, metrics=[
        'num_matches', 'num_false_positives', 'num_misses', 'num_switches', 'num_detections',
        'num_objects', 'num_predictions', 'mota', 'motp', 'num_frames'
    ])

    assert metr['num_matches'] == 4
    assert metr['num_false_positives'] == 2
    assert metr['num_misses'] == 2
    assert metr['num_switches'] == 2
    assert metr['num_detections'] == 6
    assert metr['num_objects'] == 8
    assert metr['num_predictions'] == 8
    assert metr['mota'] == approx(1. - (2 + 2 + 2) / 8)
    assert metr['motp'] == approx(11.1 / 6)
    assert metr['num_frames'] == 6
Tests values of MOTA and MOTP.
motmetrics/tests/test_metrics.py