Talk:Decreasing contiguous subsequences
Non increasing or decreasing?
The first non-increasing subsequence would be 90, 90, 90 the second would be 91, 91. We then arrive at 92, 92, 92, 91, 91, 91, 90, 90, 90, 89, 89, 88, 87, 87, 87, 86, 86, 86, 85, 85 which might be the first decreasing subsequence, though looking at the graph you have plotted the first 2 92s seem to be omitted and maybe the last 85. Anyway the task description does not make it clear!--Nigel Galloway (talk) 12:58, 5 September 2024 (UTC)
- "non-increasing" was my intention, as opposed to "strictly decreasing". I see that the use of "decreasing" in the task's title is ambiguous and it should probably be "Non-increasing contiguous subsequences" instead. Do you agree?
- As for "trimming the plateaus" (as I've called it in the Python solution. Maybe not the best name considering it also trims the "tails"), that I deliberately left undefined, pending feedback, because the task's output should not be effected. I'll happily remove that part of the Python solution and change the graph to highlight full non-increasing subsequences. --Jgrprior (talk) 14:19, 5 September 2024 (UTC)
Values or percentages?
Is the given sequence values or percentages? If they are values, what should we use as our span to determine percent change? 0..100? The minimum and maximum values seen in the sequence? --Thundergnat (talk) 13:22, 5 September 2024 (UTC)
- The python defines percentage_change(s: list[int]) -> float as 100 - ((s[-1] / s[0]) * 100). Why? maybe we shall find out.--Nigel Galloway (talk) 13:37, 5 September 2024 (UTC)
- I was thinking percentage change from local maximum to local minimum, so neither 100 or global maximum. The task description currently says "the difference between the local maximum and the local minimum, as a percentage of the local maximum", which I thought was reasonably unambiguous.
- The real world data that the values came from does happen to be percentages. They are blood oxygen saturation readings (SpO2) over time. The idea being that we're looking for concerning events in the form of significant drops in SpO2. It's a case of "how much did it drop by?". I can include a description of this scenario if you think it makes the task clearer. --Jgrprior (talk) 14:44, 5 September 2024 (UTC)
Query re Python code
Although it doesn't make any difference for this particular data set, shouldn't the 'for' statement in the 'subsequence_group' function be as follows:
for bucket in GROUPS:
if change >= bucket[0] and change < bucket[1]: # < rather than <= the end-point
return bucket
--PureFox (talk) 16:09, 5 September 2024 (UTC)
- On second thoughts, if the change could conceivably be 100%, then we need to deal with that. Perhaps:
def subsequence_group(s: list[int]) -> tuple[int, int]:
change = percentage_change(s)
if change == 100:
return GROUPS[-1]
for bucket in GROUPS:
if change >= bucket[0] and change < bucket[1]:
return bucket
raise ValueError(f"subsequence out of range: {change}")
--PureFox (talk) 16:23, 5 September 2024 (UTC)
The data must be non-negative
... or e.g.: ( 0, -1 ) will resullt in division by zero. --Tigerofdarkness (talk) 21:39, 5 September 2024 (UTC)