* Fix spike detection for short spikes at the tail of the data. * Update docs/changelog/119637.yaml
@@ -0,0 +1,5 @@
+pr: 119637
+summary: Fix spike detection for short spikes at the tail of the data
+area: Machine Learning
+type: bug
+issues: []
@@ -58,7 +58,7 @@ final class SpikeAndDipDetector {
int maxEnd = Math.min(maxStart + extent, values.length);
double maxSum = sum(values, maxStart, maxEnd, negate);
for (int start = maxStart + 1; start <= argmax; start++) {
- if (start + extent >= values.length) {
+ if (start + extent > values.length) {
break;
}
double average = sum(values, start, start + extent, negate);
@@ -184,4 +184,14 @@ public class SpikeAndDipDetectorTests extends ESTestCase {
assertThat(change, instanceOf(ChangeType.Spike.class));
assertThat(change.changePoint(), equalTo(10));
+
+ public void testSpikeAtTail() {
+ MlAggsHelper.DoubleBucketValues bucketValues = new MlAggsHelper.DoubleBucketValues(
+ null,
+ new double[] { 2, 2, 2, 2, 3, 2, 2, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 2, 9, 8 }
+ );
+ ChangeType change = new SpikeAndDipDetector(bucketValues).detect(0.01);
+ assertThat(change, instanceOf(ChangeType.Spike.class));
+ assertThat(change.changePoint(), equalTo(27));
+ }