Skip to content

Hausdorff metric (hausdorff)#

Compute the Hausdorff distance between changepoints.

Parameters:

Name Type Description Default
bkps1 list

list of the last index of each regime.

required
bkps2 list

list of the last index of each regime.

required

Returns:

Name Type Description
float

Hausdorff distance.

Source code in ruptures/metrics/hausdorff.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
def hausdorff(bkps1, bkps2):
    """Compute the Hausdorff distance between changepoints.

    Args:
        bkps1 (list): list of the last index of each regime.
        bkps2 (list): list of the last index of each regime.

    Returns:
        float: Hausdorff distance.
    """
    sanity_check(bkps1, bkps2)
    bkps1_arr = np.array(bkps1[:-1]).reshape(-1, 1)
    bkps2_arr = np.array(bkps2[:-1]).reshape(-1, 1)
    pw_dist = cdist(bkps1_arr, bkps2_arr)
    res = max(pw_dist.min(axis=0).max(), pw_dist.min(axis=1).max())
    return res