Commit eba5b5e3 authored by Sören Henning's avatar Sören Henning

added incredible good RegressionForecaster

parent eb1c3fea
......@@ -9,7 +9,7 @@ public class AnomalyDetectionConfiguration extends Configuration {
public AnomalyDetectionConfiguration() {
// Create the stages
final MeassurementsGeneratorStage generator = new MeassurementsGeneratorStage(x -> 500 * Math.sin(x / 60) + 2000, 250, 0.01, 1000, Duration.ofSeconds(1),
final MeassurementsGeneratorStage generator = new MeassurementsGeneratorStage(x -> 500 * Math.sin(x / 240) + 2000, 250, 0.01, 1000, Duration.ofSeconds(1),
3600);
final AnomalyDetectionStage anomalyDetector = new AnomalyDetectionStage();
final SimpleAlertStage alerter = new SimpleAlertStage();
......
......@@ -4,8 +4,7 @@ import java.io.File;
import java.time.Duration;
import anomalydetection.aggregation.MeanAggregator;
import anomalydetection.forecast.WeightedForecaster;
import anomalydetection.forecast.WeightedForecaster.WeightMethod;
import anomalydetection.forecast.RegressionForecaster;
import anomalydetection.measurement.AnomalyScoredMeasurement;
import anomalydetection.measurement.Measurement;
import anomalydetection.timeseries.BoundedTimeSeries;
......@@ -27,7 +26,7 @@ public class AnomalyDetectionStage extends CompositeStage {
final Distributor<Measurement> measurementDistributor = new Distributor<>(new CopyByReferenceStrategy());
final ExtractorStage extractor = new ExtractorStage(new BoundedTimeSeries(Duration.ofHours(1)));
final NormalizerStage normalizerStage = new NormalizerStage(Duration.ofSeconds(5), new MeanAggregator());
final ForecastStage forecaster = new ForecastStage(new WeightedForecaster(WeightMethod.LINEAR));
final ForecastStage forecaster = new ForecastStage(new RegressionForecaster());
final MeasurementForecastDecorationStage measurementForecastDecorator = new MeasurementForecastDecorationStage();
final AnomalyScoreCalculatorStage anomalyScoreCalculator = new AnomalyScoreCalculatorStage();
final PrinterStage printer = new PrinterStage(); // TODO Temp
......
package anomalydetection.forecast;
import org.apache.commons.math3.stat.regression.SimpleRegression;
import anomalydetection.timeseries.EquidistantTimeSeries;
import anomalydetection.timeseries.TimeSeriesPoint;
public class RegressionForecaster implements Forecaster {
@Override
public double forecast(final EquidistantTimeSeries timeSeries) {
final SimpleRegression regression = new SimpleRegression();
for (TimeSeriesPoint point : timeSeries) {
regression.addData(point.getTime().toEpochMilli(), point.getValue());
}
double prediction = regression.predict(timeSeries.getNextEndTime().toEpochMilli());
// TODO Temp
if (Double.isNaN(prediction)
|| prediction < 0
|| Double.isInfinite(prediction)) {
prediction = 0;
}
return 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