def test_ids():
    """Test metrics with frame IDs specified manually."""
    acc = mm.MOTAccumulator()

    # No data
    acc.update([], [], [], frameid=0)
    # Match
    acc.update([1, 2], [1, 2], [[1, 0], [0, 1]], frameid=1)
    # Switch also Transfer
    acc.update([1, 2], [1, 2], [[0.4, np.nan], [np.nan, 0.4]], frameid=2)
    # Match
    acc.update([1, 2], [1, 2], [[0, 1], [1, 0]], frameid=3)
    # Ascend (switch)
    acc.update([1, 2], [2, 3], [[1, 0], [0.4, 0.7]], frameid=4)
    # Migrate (transfer)
    acc.update([1, 3], [2, 3], [[1, 0], [0.4, 0.7]], frameid=5)
    # No data
    acc.update([], [], [], frameid=6)

    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_transfer', 'num_ascend', 'num_migrate',
        'num_detections', 'num_objects', 'num_predictions',
        'mota', 'motp', 'num_frames',
    ])
    assert metr['num_matches'] == 7
    assert metr['num_false_positives'] == 0
    assert metr['num_misses'] == 0
    assert metr['num_switches'] == 3
    assert metr['num_transfer'] == 3
    assert metr['num_ascend'] == 1
    assert metr['num_migrate'] == 1
    assert metr['num_detections'] == 10
    assert metr['num_objects'] == 10
    assert metr['num_predictions'] == 10
    assert metr['mota'] == approx(1. - (0 + 0 + 3) / 10)
    assert metr['motp'] == approx(1.6 / 10)
    assert metr['num_frames'] == 7
Test metrics with frame IDs specified manually.
motmetrics/tests/test_metrics.py