Skip to content

Commit 1dddbd7

Browse files
authored
Fix spike detection for short spikes at the tail of the data. (#119637) (#119668)
* Fix spike detection for short spikes at the tail of the data. * Update docs/changelog/119637.yaml
1 parent e3352ad commit 1dddbd7

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

docs/changelog/119637.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 119637
2+
summary: Fix spike detection for short spikes at the tail of the data
3+
area: Machine Learning
4+
type: bug
5+
issues: []

x-pack/plugin/ml/src/main/java/org/elasticsearch/xpack/ml/aggs/changepoint/SpikeAndDipDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private SpikeOrDip findSpikeOrDip(double[] values, int extent, boolean negate) {
5858
int maxEnd = Math.min(maxStart + extent, values.length);
5959
double maxSum = sum(values, maxStart, maxEnd, negate);
6060
for (int start = maxStart + 1; start <= argmax; start++) {
61-
if (start + extent >= values.length) {
61+
if (start + extent > values.length) {
6262
break;
6363
}
6464
double average = sum(values, start, start + extent, negate);

x-pack/plugin/ml/src/test/java/org/elasticsearch/xpack/ml/aggs/changepoint/SpikeAndDipDetectorTests.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,14 @@ public void testMissingBuckets() {
184184
assertThat(change, instanceOf(ChangeType.Spike.class));
185185
assertThat(change.changePoint(), equalTo(10));
186186
}
187+
188+
public void testSpikeAtTail() {
189+
MlAggsHelper.DoubleBucketValues bucketValues = new MlAggsHelper.DoubleBucketValues(
190+
null,
191+
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 }
192+
);
193+
ChangeType change = new SpikeAndDipDetector(bucketValues).detect(0.01);
194+
assertThat(change, instanceOf(ChangeType.Spike.class));
195+
assertThat(change.changePoint(), equalTo(27));
196+
}
187197
}

0 commit comments

Comments
 (0)