Commit 1b137743 authored by Sören Henning's avatar Sören Henning

implemented new anomaly score

parent 14f9a7ca
package teead;
import teead.anomalyscore.AnomalyScoreCalculator;
import teead.anomalyscore.SimpleAnomalyScoreCalculator;
import teead.anomalyscore.DeviationAnomalyScoreCalculator;
import teead.measurement.AnomalyScoredMeasurement;
import teead.measurement.ForecastedMeassurement;
import teetime.stage.basic.AbstractTransformation;
......@@ -11,7 +11,7 @@ public class AnomalyScoreCalculatorStage extends AbstractTransformation<Forecast
private final AnomalyScoreCalculator anomalyScoreCalculator;
public AnomalyScoreCalculatorStage() {
this.anomalyScoreCalculator = new SimpleAnomalyScoreCalculator();
this.anomalyScoreCalculator = new DeviationAnomalyScoreCalculator();
}
public AnomalyScoreCalculatorStage(final AnomalyScoreCalculator anomalyScoreCalculator) {
......
package teead.anomalyscore;
/**
* {@link AnomalyScoreCalculator} that calculates a anomaly score based on the
* percentage deviation from measured value to predicted value.
*
* Formally this means: s = (m - p) / p
* Where m is the measurement, p is the prediction and s is the anomly score.
*
* @author Sören Henning
*
*/
public class DeviationAnomalyScoreCalculator implements AnomalyScoreCalculator {
@Override
public double calculate(final double measurement, final double prediction) {
if (Double.isNaN(prediction) && Double.isNaN(measurement)) {
return 0.0d;
} else if (Double.isNaN(prediction) || Double.isNaN(measurement)) {
return 1.0d;
} else {
return (measurement - prediction) / prediction;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment