forked from opensearch-project/anomaly-detection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump RCF Version and Fix Default Rules Bug in AnomalyDetector (opense…
…arch-project#1334) * Updated RCF version to the latest release. * Fixed a bug in AnomalyDetector where default rules were not applied when the user provided an empty ruleset. Testing: * Added unit tests to cover the bug fix Signed-off-by: Kaituo Li <kaituo@amazon.com>
- Loading branch information
Showing
15 changed files
with
452 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.ad.ml; | ||
|
||
import java.io.IOException; | ||
import java.util.ArrayList; | ||
|
||
import org.opensearch.ad.model.AnomalyDetector; | ||
import org.opensearch.test.OpenSearchTestCase; | ||
import org.opensearch.timeseries.TestHelpers; | ||
|
||
import com.amazon.randomcutforest.parkservices.ThresholdedRandomCutForest; | ||
|
||
public class ADColdStartTests extends OpenSearchTestCase { | ||
private int baseDimensions = 1; | ||
private int shingleSize = 8; | ||
private int dimensions; | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
super.setUp(); | ||
dimensions = baseDimensions * shingleSize; | ||
} | ||
|
||
/** | ||
* Test if no explicit rule is provided, we apply 20% rule. | ||
* @throws IOException when failing to constructor detector | ||
*/ | ||
public void testEmptyRule() throws IOException { | ||
AnomalyDetector detector = TestHelpers.AnomalyDetectorBuilder.newInstance(1).setRules(new ArrayList<>()).build(); | ||
ThresholdedRandomCutForest.Builder builder = new ThresholdedRandomCutForest.Builder<>() | ||
.dimensions(dimensions) | ||
.shingleSize(shingleSize); | ||
ADColdStart.applyRule(builder, detector); | ||
|
||
ThresholdedRandomCutForest forest = builder.build(); | ||
double[] ignore = forest.getPredictorCorrector().getIgnoreNearExpected(); | ||
|
||
// Specify a small delta for floating-point comparison | ||
double delta = 1e-6; | ||
|
||
assertArrayEquals("The double arrays are not equal", new double[] { 0, 0, 0.2, 0.2 }, ignore, delta); | ||
} | ||
|
||
public void testNullRule() throws IOException { | ||
AnomalyDetector detector = TestHelpers.AnomalyDetectorBuilder.newInstance(1).setRules(null).build(); | ||
ThresholdedRandomCutForest.Builder builder = new ThresholdedRandomCutForest.Builder<>() | ||
.dimensions(dimensions) | ||
.shingleSize(shingleSize); | ||
ADColdStart.applyRule(builder, detector); | ||
|
||
ThresholdedRandomCutForest forest = builder.build(); | ||
double[] ignore = forest.getPredictorCorrector().getIgnoreNearExpected(); | ||
|
||
// Specify a small delta for floating-point comparison | ||
double delta = 1e-6; | ||
|
||
assertArrayEquals("The double arrays are not equal", new double[] { 0, 0, 0.2, 0.2 }, ignore, delta); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.