sciquence.sequences.longest_segment¶
-
sciquence.sequences.
longest_segment
()¶ Find the longest subsequence which scores above a given threshold in O(n)
Parameters: - sequence (ndarray) – A sequence
- alpha (float) – Floating-point threshold being a lower bound for searched segment
Returns: segment – The longest segment with sum above given threshold
Return type: ndarray
Examples
>>> from sciquence.sequences import longest_segment >>> import numpy as np >>> X = np.array([-1, -2, -3, -23, -45, -3, -4, 5, -56, 67, 1, 3, 4, 5]) >>> ls1 = longest_segment(X, 30) >>> print ls1, sum(ls1) [67 1 3 4 5] 80 # Next, we change -56 into -50 >>> Z = np.array([-1, -2, -3, -23, -45, -3, -4, 5, -50, 67, 1, 3, 4, 5]) >>> ls2 = longest_segment(Z, 30) [ -4 5 -50 67 1 3 4 5] 31
Notes
Keep in mind that this algorithm maximizes segment length, not the segment total sum.
References
Csűrös M. (2008).
A linear-time algorithm for finding the longest segment which scores above a given threshold