Skip to content

Hausdorff metric (hausdorff)#

ruptures.metrics.hausdorff.hausdorff(bkps1, bkps2) #

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:

Type Description
float

Hausdorff distance.

Source code in ruptures/metrics/hausdorff.py
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