@Override public AnomalyScore calculateAnomalyScore(final IForecastResult forecast, final ITimeSeriesPoint<Double> current) { if (forecast.getForecast().getPoints().size() == 0) { return null; } final Double nextpredicted = forecast.getForecast().getPoints().get(0).getValue(); if (null == nextpredicted) { return null; } double measuredValue = 0.0; measuredValue = current.getValue(); double difference = nextpredicted - measuredValue; final double sum = nextpredicted + measuredValue; difference = Math.abs(difference / sum); return new AnomalyScore(difference); } }
@Override public AnomalyScore calculateAnomalyScore(final IForecastResult forecast, final ITimeSeriesPoint<Double> current) { if (forecast.getForecast().getPoints().size() == 0) { return null; } final Double nextpredicted = forecast.getForecast().getPoints().get(0).getValue(); if (null == nextpredicted) { return null; } double measuredValue = 0.0; measuredValue = current.getValue(); double difference = nextpredicted - measuredValue; final double sum = nextpredicted + measuredValue; difference = Math.abs(difference / sum); return new AnomalyScore(difference); } }
if (result.getForecast().getPoints().size() > 0) { result.getForecast().getPoints().get(0).getValue(), input.getValue(), timestamp,
if (result.getForecast().getPoints().size() > 0) { result.getForecast().getPoints().get(0).getValue(), input.getValue(), timestamp,
/** * One step of a mean calculation. */ @Test public void testMeanCalculationOneStep() { Assert.assertEquals(this.steps, this.forecastSeries.size()); final ITimeSeriesPoint<Double> stepFC = this.forecast.getForecast().getPoints().get(0); Assert.assertEquals(this.mean, stepFC.getValue()); }
final IForecastResult forecast = forecaster.forecast(ARIMA101ForecasterTest.STEPS); final ITimeSeries<Double> forecastSeries = forecast.getForecast(); final double expectedForecast = 4.210429; this.assertEqualsWithTolerance("Unexpected forecast value", expectedForecast, 0.1, forecastSeries.getPoints().get(0).getValue());
/** * Initiation of the test, setting up the test time series. * * @param timeUnit * Used time unit */ private void initForecastWithTimeUnit(final TimeUnit tu) { this.ts = new TimeSeries<Double>(this.startTime, TimeUnit.MILLISECONDS, this.deltaTime, tu); this.steps = 1; this.mean = Double.valueOf(2.0); this.ts.append(this.mean - 2); this.ts.append(this.mean - 1); this.ts.append(this.mean); this.ts.append(this.mean + 1); this.ts.append(this.mean + 2); this.forecaster = new MeanForecaster(this.ts, MeanForecasterTest.CONFIDENCE_LEVEL); this.forecast = this.forecaster.forecast(this.steps); this.forecastSeries = this.forecast.getForecast(); this.upperSeries = this.forecast.getUpper(); this.lowerSeries = this.forecast.getLower(); }
/** * Test of the ETSForecaster via Rserve. */ @Test public void testETSPredictor() { // NOPMD assertEqualsWithTolerance is a custom method final Double[] values = { 1.0, 2.0, 3.0, 4.0 }; final List<Double> expectedValues = new ArrayList<Double>(values.length); for (final Double curVal : values) { expectedValues.add(curVal); } final TimeSeries<Double> ts = new TimeSeries<Double>(ETSForecasterTest.START_TIME, TimeUnit.NANOSECONDS, ETSForecasterTest.DELTA_TIME_MILLIS, TimeUnit.MILLISECONDS); ts.appendAll(values); final ETSForecaster forecaster = new ETSForecaster(ts, ETSForecasterTest.CONFIDENCE_LEVEL); final IForecastResult forecast = forecaster.forecast(ETSForecasterTest.STEPS); final ITimeSeries<Double> forecastSeries = forecast.getForecast(); final double expectedForecast = 4.0; this.assertEqualsWithTolerance("Unexpected forecast value", expectedForecast, 0.1, AbstractKiekerRTest.getTsPoint(forecastSeries)); final ITimeSeries<Double> upperSeries = forecast.getUpper(); final double expectedUpper = 5.424480; this.assertEqualsWithTolerance("Unexpected upper value", expectedUpper, 0.1, AbstractKiekerRTest.getTsPoint(upperSeries)); final ITimeSeries<Double> lowerSeries = forecast.getLower(); final double expectedLower = 2.57531997; this.assertEqualsWithTolerance("Unexpected lower value", expectedLower, 0.1, AbstractKiekerRTest.getTsPoint(lowerSeries)); }
/** * Test of the SESRForecaster via Rserve. */ @Test public void test() { final int deltaTime = 1000; final TimeUnit timeUnit = TimeUnit.MILLISECONDS; final long startTime = System.currentTimeMillis() - (deltaTime * 10); final TimeSeries<Double> ts = new TimeSeries<Double>(startTime, TimeUnit.NANOSECONDS, deltaTime, timeUnit); ts.append(1.0); ts.append(2.0); ts.append(3.0); ts.append(1.0); ts.append(2.0); ts.append(3.0); final SESRForecaster forecaster = new SESRForecaster(ts); final IForecastResult forecast = forecaster.forecast(1); final ITimeSeries<Double> forecastSeries = forecast.getForecast(); // final ITimeSeriesPoint<Double> stepFC = forecastSeries.getPoints().get(0); Assert.assertEquals(2.000054d, AbstractKiekerRTest.getTsPoint(forecastSeries), 0.001d); } }