utils

Shared matching helpers for single-run metrics.

pysatl_cpd.analysis.metrics.single_run.utils.validate_error_margin(error_margin)[source]

Validate that both margin components are non-negative.

Parameters:

error_margin (tuple[int, int]) – Pair (left, right) margin bounds.

Returns:

The validated margin tuple.

Return type:

tuple[int, int]

Raises:

ValueError – If either component is negative.

pysatl_cpd.analysis.metrics.single_run.utils.match_change_points(detected_change_points, true_change_points, error_margin)[source]

Match detections to true change points using greedy left-to-right assignment.

For each true change point (in sorted order), the earliest unmatched detection within the error margin window is assigned.

Parameters:
  • detected_change_points (Sequence[int]) – Detected change-point indices.

  • true_change_points (Sequence[int]) – Ground-truth change-point indices.

  • error_margin (tuple[int, int]) – (left, right) tolerance around each true change point.

Returns:

Mapping from each true change point to the set of matched detections.

Return type:

dict[int, set[int]]