Skip to content

Commit

Permalink
[plugins-detector] add lower/upper sensitivty to meanVariance
Browse files Browse the repository at this point in the history
  • Loading branch information
cyrilou242 committed Dec 13, 2023
1 parent ed018e2 commit e3e6439
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ public class MeanVarianceRuleDetector implements AnomalyDetector<MeanVarianceRul
);

private Pattern pattern;
private double sensitivity;
private double lowerSensitivity;
private double upperSensitivity;
private int lookback;
private MeanVarianceRuleDetectorSpec spec;
private Period seasonality = Period.ZERO; // PT0S: special period for no seasonality
Expand Down Expand Up @@ -89,8 +90,16 @@ protected static int computeSteps(final String periodString,
@Override
public void init(final MeanVarianceRuleDetectorSpec spec) {
this.spec = spec;
pattern = spec.getPattern();
sensitivity = spec.getSensitivity();
this.pattern = spec.getPattern();
if (spec.getLowerSensitivity() != null || spec.getUpperSensitivity() != null) {
checkArgument(spec.getLowerSensitivity() != null, "lowerSensitivity is null. lowerSensitivity must be set when upperSensitivity is set.");
checkArgument(spec.getUpperSensitivity() != null, "upperSensitivity is null. upperSensitivity must be set when lowerSensitivity is set.");
this.lowerSensitivity = spec.getLowerSensitivity();
this.upperSensitivity = spec.getUpperSensitivity();
} else {
this.lowerSensitivity = spec.getSensitivity();
this.upperSensitivity = spec.getSensitivity();
}

if (spec.getLookbackPeriod() != null) {
checkArgument(spec.getMonitoringGranularity() != null,
Expand Down Expand Up @@ -204,9 +213,10 @@ private DataFrame computeBaseline(final DataFrame inputDF, final ReadableInterva
}
//calculate baseline, error , upper and lower bound for prediction window.
baselineArray[k] = mean;
final double error = sigma(sensitivity) * std;
upperBoundArray[k] = baselineArray[k] + error;
lowerBoundArray[k] = baselineArray[k] - error;
final double upperError = sigma(upperSensitivity) * std;
final double lowerError = sigma(lowerSensitivity) * std;
upperBoundArray[k] = baselineArray[k] + upperError;
lowerBoundArray[k] = baselineArray[k] - lowerError;
}
//Construct the dataframe.
resultDF
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class MeanVarianceRuleDetectorSpec extends AbstractSpec {
/**Biggest period in ISO-8601 format. Possible values are P7D and P1D. Used to take into account seasonality when computing mean-variance.*/
private String seasonalityPeriod = null;

// TODO CYRIL add tests for this feature
private Double upperSensitivity;
private Double lowerSensitivity;

public int getLookback() {
return lookback;
}
Expand Down Expand Up @@ -74,4 +78,22 @@ public MeanVarianceRuleDetectorSpec setSeasonalityPeriod(final String seasonalit
this.seasonalityPeriod = seasonalityPeriod;
return this;
}

public Double getUpperSensitivity() {
return upperSensitivity;
}

public MeanVarianceRuleDetectorSpec setUpperSensitivity(final Double upperSensitivity) {
this.upperSensitivity = upperSensitivity;
return this;
}

public Double getLowerSensitivity() {
return lowerSensitivity;
}

public MeanVarianceRuleDetectorSpec setLowerSensitivity(final Double lowerSensitivity) {
this.lowerSensitivity = lowerSensitivity;
return this;
}
}

0 comments on commit e3e6439

Please sign in to comment.