@@ -594,33 +594,20 @@ def check_window_size(m, max_size=None, n=None):
594594 raise ValueError (f"The window size must be less than or equal to { max_size } " )
595595
596596 if n is not None :
597- # The following code raises warning if there is at least one subsequence
598- # with no non-trivial neighbor. The following logic does not check if
599- # a subsequence has a non-finite value.
600-
601- # Logic: For each subsequnece `S_i = T[i : i + m]`, its neighbor `S_j`
602- # is non-trivial if |i - j| > excl_zone. Let's denote `S_jmax` as
603- # the neighbor that is furthest away from `S_i` (index-wise). So:
604- # |i - jmax| >= |i - j|
605- # Therefore, if `S_i` has at least one non-trivial neighbor, then `S_jmax` is
606- # definitely a non-trivial neighbor. Because:
607- # |i - jmax| >= |i - j| > excl_zone
608- # To ensure ALL subsequences have at least one non-trivial neighbor, we can just
609- # check the subsequence `S_i` that has the minimum |i - jmax|. Let's denote `d`
610- # as that minimum value. So, if d > excl_zone, then:
611- # For any `i` and its corresponding `jmax`, we have:
612- # |i - jmax| >= d > excl_zone
613-
614- # Hence, as long as the `S_i` that corresponds to `d` has one non-trivial
615- # neighbour, any other subsequence has one non-trivial neighbour as well.
616-
617- # The minimum |i - jmax| is achieved when `S_i` is the middle ubsequence,
618- # i.e. i == int(ceil((n - m) / 2)). Its corresponding `jmax` is 0. Hence,
619- # we just need to make sure the following inequality is satisfied:
620- # |int(ceil((n - m) / 2)) - 0| > excl_zone`
597+ # Raise warning if there is at least one subsequence with no
598+ # non-trivial neighbour in a self-join case
621599
622600 excl_zone = int (math .ceil (m / config .STUMPY_EXCL_ZONE_DENOM ))
623- if (int (math .ceil ((n - m ) / 2 )) - 0 ) <= excl_zone :
601+
602+ l = n - m + 1
603+ indices = np .arange (l )
604+
605+ # Compute the maximum index-wise gap between each subsequence
606+ # and its neighbours. For any subsequence:
607+ # The leftmost neighbor is at index `0`
608+ # The rightmost neighbor is at index `l-1`
609+ max_gaps = np .maximum (indices - 0 , (l - 1 ) - indices )
610+ if np .any (max_gaps <= excl_zone ):
624611 msg = (
625612 f"The window size, 'm = { m } ', may be too large and could lead to "
626613 + "meaningless results. Consider reducing 'm' where necessary"
0 commit comments