Skip to content

Commit

Permalink
Fix spike detection for short spikes at the tail of the data. (elasti…
Browse files Browse the repository at this point in the history
…c#119637) (elastic#119641)

* Fix spike detection for short spikes at the tail of the data.

* Update docs/changelog/119637.yaml
  • Loading branch information
jan-elastic authored Jan 7, 2025
1 parent 7fc7f2a commit 3f87b3c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
5 changes: 5 additions & 0 deletions docs/changelog/119637.yaml
Original file line number Diff line number Diff line change
@@ -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: []
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private SpikeOrDip findSpikeOrDip(double[] values, int extent, boolean negate) {
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,4 +184,14 @@ public void testMissingBuckets() {
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));
}
}

0 comments on commit 3f87b3c

Please sign in to comment.