torch_ecg.utils.max_disjoint_covering

torch_ecg.utils.max_disjoint_covering(intervals: Sequence[Sequence[Real] | list] | list, allow_book_endeds: bool = True, traceback: bool = True, verbose: int = 0) Tuple[Sequence[Sequence[Real] | list] | list, List[int]][source]

Find the largest (the largest interval length) covering of a sequence of intervals.

Parameters:
  • intervals (GeneralizedInterval) – A sequence of intervals.

  • allow_book_endeds (bool, default True) – If True, book-ended intervals will be considered valid (disjoint).

  • traceback (bool, default True) – If True, the indices of the intervals in the input intervals of the output covering will also be returned.

Returns:

  • covering (GeneralizedInterval) – The maximum non-overlapping (disjoint) subset of intervals.

  • covering_inds (List[int]) – Indices in intervals of the intervals of covering_inds.

Examples

>>> max_disjoint_covering([])
([], [])
>>> max_disjoint_covering([[0, 10]])
([[0, 10]], [0])
>>> max_disjoint_covering([[1, 4], [2, 3], [4, 6], [8, 9]])
([[1, 4], [4, 6], [8, 9]], [0, 2, 3])
>>> max_disjoint_covering([[1, 4], [2, 3], [4, 6], [8, 9]], allow_book_endeds=False, traceback=False)
([[2, 3], [4, 6], [8, 9]], [])

Note

  1. The problem seems slightly different from the problem discussed in reference [1] and [2].

  2. Intervals with non-positive length will be ignored

References