Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private interface KernelFunction {
}

private ValueAndMagnitude evaluate(IntervalComplementFunction complement, KernelFunction kernel, double x) {
if (bandwidth == 0.0 || orderedValues.length == 0) {
if (orderedValues.length == 0) {
return new ValueAndMagnitude(1.0, 0.0);
}
int a = Math.min(lowerBound(orderedValues, x - 3.0 * bandwidth), orderedValues.length - 1);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

package org.elasticsearch.xpack.ml.aggs.changepoint;

import org.elasticsearch.test.ESTestCase;
import org.elasticsearch.xpack.ml.aggs.MlAggsHelper;

import java.util.Arrays;

import static org.hamcrest.Matchers.instanceOf;

public class ChangePointDetectorTests extends ESTestCase {

/**
* Testing the special case where values without the spike have a variance of 0.
*/
public void testConstantWithSpike() {
double[] values = new double[25];
Arrays.fill(values, 51);
values[12] = 500001;

MlAggsHelper.DoubleBucketValues bucketValues = new MlAggsHelper.DoubleBucketValues(null, values);

ChangeType change = ChangePointDetector.getChangeType(bucketValues);

assertEquals(12, change.changePoint());
assertThat(change, instanceOf(ChangeType.Spike.class));
}

public void testRandomWithSpike() {
double[] values = new double[25];
for (int i = 0; i < values.length; i++) {
values[i] = randomLongBetween(50, 53);
}
values[12] = 500001;

MlAggsHelper.DoubleBucketValues bucketValues = new MlAggsHelper.DoubleBucketValues(null, values);

ChangeType change = ChangePointDetector.getChangeType(bucketValues);

assertEquals(12, change.changePoint());
assertThat(change, instanceOf(ChangeType.Spike.class));
}
}