Skip to content

Commit 732c1de

Browse files
committed
Replace -1 by ChangeType.NO_CHANGE_POINT
1 parent 5dafe6a commit 732c1de

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ private TestStats testTrendVs(TestStats H0, double[] values, double[] weights) {
189189
private TestStats testStepChangeVs(TestStats H0, double[] values, double[] weights, int[] candidateChangePoints) {
190190

191191
double vStep = Double.MAX_VALUE;
192-
int changePoint = -1;
192+
int changePoint = ChangeType.NO_CHANGE_POINT;
193193

194194
// Initialize running stats so that they are only missing the individual changepoint values
195195
RunningStats lowerRange = new RunningStats();
@@ -226,7 +226,7 @@ private TestStats testStepChangeVs(TestStats H0, double[] values, double[] weigh
226226
private TestStats testTrendChangeVs(TestStats H0, double[] values, double[] weights, int[] candidateChangePoints) {
227227

228228
double vChange = Double.MAX_VALUE;
229-
int changePoint = -1;
229+
int changePoint = ChangeType.NO_CHANGE_POINT;
230230

231231
// Initialize running stats so that they are only missing the individual changepoint values
232232
RunningStats lowerRange = new RunningStats();
@@ -349,7 +349,7 @@ private TestStats testDistributionChange(
349349
) {
350350

351351
double maxDiff = 0.0;
352-
int changePoint = -1;
352+
int changePoint = ChangeType.NO_CHANGE_POINT;
353353

354354
// Initialize running stats so that they are only missing the individual changepoint values
355355
RunningStats lowerRange = new RunningStats();
@@ -381,7 +381,7 @@ private TestStats testDistributionChange(
381381

382382
double pValue = 1;
383383
for (int cp : sampleData.changePoints()) {
384-
if (cp == -1) {
384+
if (cp == ChangeType.NO_CHANGE_POINT) {
385385
continue;
386386
}
387387
double[] x = Arrays.copyOfRange(sampleValues, 0, cp);
@@ -453,7 +453,7 @@ private record TestStats(Type type, double pValue, double var, double nParams, i
453453
}
454454

455455
TestStats(Type type, double pValue, double var, double nParams, DataStats dataStats) {
456-
this(type, pValue, var, nParams, -1, dataStats);
456+
this(type, pValue, var, nParams, ChangeType.NO_CHANGE_POINT, dataStats);
457457
}
458458

459459
boolean accept(double pValueThreshold) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public InternalAggregation doReduce(InternalAggregations aggregations, Aggregati
4747
ChangeType change = ChangePointDetector.getChangeType(bucketValues);
4848

4949
ChangePointBucket changePointBucket = null;
50-
if (change.changePoint() >= 0) {
50+
if (change.changePoint() != ChangeType.NO_CHANGE_POINT) {
5151
changePointBucket = extractBucket(bucketsPaths()[0], aggregations, change.changePoint()).map(
5252
b -> new ChangePointBucket(b.getKey(), b.getDocCount(), b.getAggregations())
5353
).orElse(null);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,10 @@
2121
*/
2222
public interface ChangeType extends NamedWriteable, NamedXContentObject {
2323

24+
int NO_CHANGE_POINT = -1;
25+
2426
default int changePoint() {
25-
return -1;
27+
return NO_CHANGE_POINT;
2628
}
2729

2830
default double pValue() {

0 commit comments

Comments
 (0)