Skip to content

Commit

Permalink
Remove anomalySequence from AnomalyDetectionModel#detect
Browse files Browse the repository at this point in the history
  • Loading branch information
Patrick Gombert authored and manolama committed Dec 14, 2019
1 parent 2d56047 commit 04d61d4
Show file tree
Hide file tree
Showing 10 changed files with 12 additions and 23 deletions.
5 changes: 2 additions & 3 deletions src/main/java/com/yahoo/egads/control/AnomalyDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,15 +147,14 @@ public void reset() {
}
}

public void tune(TimeSeries.DataSequence expectedValues,
IntervalSequence anomalySequence) throws Exception {
public void tune(TimeSeries.DataSequence expectedValues) throws Exception {
int i = 0;

metric.data.setLogicalIndices(firstTimeStamp, period);

for (AnomalyDetectionModel model : models) {
if (!isTuned.get(i)) {
model.tune(metric.data, expectedValues, anomalySequence);
model.tune(metric.data, expectedValues);
isTuned.set(i, true);
}
i++;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public void process() throws Exception {
ad.reset();

// Unsupervised tuning of the anomaly detectors
ad.tune(ds, null);
ad.tune(ds);

// Detecting anomalies for each anomaly detection model in anomaly detector
anomalyList = ad.detect(ad.metric, ds);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public void reset() {
}

@Override
public void tune(DataSequence observedSeries, DataSequence expectedSeries, IntervalSequence anomalySequence)
public void tune(DataSequence observedSeries, DataSequence expectedSeries)
throws Exception {

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public interface AnomalyDetectionModel extends Model {

// tune the anomaly detection parameters based on the training data.
public void tune(TimeSeries.DataSequence observedSeries,
TimeSeries.DataSequence expectedSeries,
Anomaly.IntervalSequence anomalySequence) throws Exception;
TimeSeries.DataSequence expectedSeries) throws Exception;

// method to check whether the anomaly value is inside the
// detection window or not
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/yahoo/egads/models/adm/DBScanModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ public void reset() {

@Override
public void tune(DataSequence observedSeries,
DataSequence expectedSeries,
IntervalSequence anomalySequence) throws Exception {
DataSequence expectedSeries) throws Exception {
// Compute the time-series of errors.
HashMap<String, ArrayList<Float>> allErrors = aes.initAnomalyErrors(observedSeries, expectedSeries);
List<IdentifiedDoublePoint> points = new ArrayList<IdentifiedDoublePoint>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public void reset() {

@Override
public void tune(DataSequence observedSeries,
DataSequence expectedSeries,
IntervalSequence anomalySequence) throws Exception {
DataSequence expectedSeries) throws Exception {
// Compute the time-series of errors.
HashMap<String, ArrayList<Float>> allErrors = aes.initAnomalyErrors(observedSeries, expectedSeries);

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/yahoo/egads/models/adm/KSigmaModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public void reset() {
}

@Override
public void tune(DataSequence observedSeries, DataSequence expectedSeries,
IntervalSequence anomalySequence) throws Exception {
public void tune(DataSequence observedSeries, DataSequence expectedSeries) throws Exception {
HashMap<String, ArrayList<Float>> allErrors = aes.initAnomalyErrors(observedSeries, expectedSeries);

for (int i = 0; i < (aes.getIndexToError().keySet()).size(); i++) {
Expand Down
3 changes: 1 addition & 2 deletions src/main/java/com/yahoo/egads/models/adm/NaiveModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,7 @@ public void reset() {
}

@Override
public void tune(DataSequence observedSeries, DataSequence expectedSeries,
IntervalSequence anomalySequence) throws Exception {
public void tune(DataSequence observedSeries, DataSequence expectedSeries) throws Exception {
// TODO: auto detect thresholds.
}
// Returns true this point is identified as a potential anomaly.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ public void reset() {
}

@Override
public void tune(DataSequence observedSeries, DataSequence expectedSeries,
IntervalSequence anomalySequence) throws Exception {
public void tune(DataSequence observedSeries, DataSequence expectedSeries) throws Exception {
Float thr[] = null;
if (simpleThrType.equals("AdaptiveKSigmaSensitivity")) {
thr = AutoSensitivity.getAdaptiveKSigmaSensitivity(observedSeries.getValues(), amntAutoSensitivity);
Expand Down
8 changes: 2 additions & 6 deletions src/test/java/com/yahoo/egads/TestAnomalyDetect.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,14 @@

package com.yahoo.egads;

import com.yahoo.egads.data.Model;
import com.yahoo.egads.models.tsmm.OlympicModel;
import com.yahoo.egads.models.adm.*;
import com.yahoo.egads.data.Anomaly.IntervalSequence;
import com.yahoo.egads.utilities.*;
import com.yahoo.egads.data.*;
import java.util.ArrayList;
import java.util.Properties;
import java.io.FileInputStream;
import java.io.InputStream;
import com.yahoo.egads.control.ProcessableObject;
import com.yahoo.egads.control.ProcessableObjectFactory;
import org.testng.Assert;
import org.testng.annotations.Test;

Expand Down Expand Up @@ -59,13 +55,13 @@ public void testOlympicModel() throws Exception {
// Initialize the DBScan anomaly detector.
DBScanModel dbs = new DBScanModel(p);
IntervalSequence anomalies = bcm.detect(actual_metric.get(0).data, sequence);
dbs.tune(actual_metric.get(0).data, sequence, null);
dbs.tune(actual_metric.get(0).data, sequence);
IntervalSequence anomaliesdb = dbs.detect(actual_metric.get(0).data, sequence);

// Initialize the SimpleThreshold anomaly detector.
SimpleThresholdModel stm = new SimpleThresholdModel(p);

stm.tune(actual_metric.get(0).data, sequence, null);
stm.tune(actual_metric.get(0).data, sequence);
IntervalSequence anomaliesstm = stm.detect(actual_metric.get(0).data, sequence);
Assert.assertTrue(anomalies.size() > 10);
Assert.assertTrue(anomaliesdb.size() > 2);
Expand Down

0 comments on commit 04d61d4

Please sign in to comment.