Skip to content

Commit 5dafe6a

Browse files
committed
Fix change point detection for uncertain non-stationary distributions.
1 parent 7a21e82 commit 5dafe6a

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,12 @@ private TestStats testDistributionChange(
378378
// before we run the tests.
379379
SampleData sampleData = sample(values, weights, discoveredChangePoints);
380380
final double[] sampleValues = sampleData.values();
381-
final double[] sampleWeights = sampleData.weights();
382381

383382
double pValue = 1;
384383
for (int cp : sampleData.changePoints()) {
384+
if (cp == -1) {
385+
continue;
386+
}
385387
double[] x = Arrays.copyOfRange(sampleValues, 0, cp);
386388
double[] y = Arrays.copyOfRange(sampleValues, cp, sampleValues.length);
387389
double statistic = KOLMOGOROV_SMIRNOV_TEST.kolmogorovSmirnovStatistic(x, y);

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import java.util.concurrent.atomic.AtomicInteger;
1818
import java.util.stream.DoubleStream;
1919

20+
import static org.hamcrest.Matchers.equalTo;
2021
import static org.hamcrest.Matchers.greaterThan;
2122
import static org.hamcrest.Matchers.instanceOf;
2223
import static org.hamcrest.Matchers.lessThan;
@@ -243,4 +244,14 @@ public void testProblemDistributionChange() {
243244
ChangeType type = new ChangeDetector(bucketValues).detect(0.05);
244245
assertThat(type, instanceOf(ChangeType.DistributionChange.class));
245246
}
247+
248+
public void testUncertainNonStationary() {
249+
MlAggsHelper.DoubleBucketValues bucketValues = new MlAggsHelper.DoubleBucketValues(
250+
null,
251+
new double[] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 700, 735, 715 }
252+
);
253+
ChangeType type = new ChangeDetector(bucketValues).detect(0.01);
254+
assertThat(type, instanceOf(ChangeType.NonStationary.class));
255+
assertThat(((ChangeType.NonStationary) type).getTrend(), equalTo("increasing"));
256+
}
246257
}

0 commit comments

Comments
 (0)