/** * Checks whether the given TimeSeries contains items. * * @param timeSeries * TimeSeries * @return true if TimeSeries contains one or more items, else false */ public static boolean tsContainsPoints(final ITimeSeries<Double> timeSeries) { return timeSeries.getPoints().size() > 0; }
/** * Returns a new time series object shortened to the last x values. * * @param ts * timeseries * @param x * last x value * @return new time series object */ private static ITimeSeries<Double> getLastXofTS(final ITimeSeries<Double> ts, final int x) { if (ts.size() >= x) { Double[] a = new Double[ts.size()]; a = ts.getValues().toArray(a); final Double[] b = new Double[x]; for (int i = 0; i < x; i++) { b[i] = a[(ts.size() - x) + i]; } long newStartTime = ts.getStartTime(); newStartTime += (ts.size() - x) * ts.getDeltaTimeUnit().toMillis(ts.getDeltaTime()); final ITimeSeries<Double> tsLastX = new TimeSeries<Double>(newStartTime, ts.getTimeSeriesTimeUnit(), ts.getDeltaTime(), ts.getDeltaTimeUnit(), ts.getCapacity()); tsLastX.appendAll(b); return tsLastX; } else { return ts; } } }
/** * * @return TS */ protected ITimeSeries<T> prepareForecastTS() { final ITimeSeries<T> history = this.getTsOriginal(); final long startTime = history.getStartTime(); final TimeSeries<T> tsFC = new TimeSeries<T>(startTime, history.getTimeSeriesTimeUnit(), history.getDeltaTime(), history.getDeltaTimeUnit()); return tsFC; }
currentWindow.append(input.getValue()); if (result.getForecast().getPoints().size() > 0) { if (result.getUpper().getValues().size() > 0) { confidenceUpper = result.getUpper().getValues().get(0); } else { confidenceUpper = Double.NaN; if (result.getLower().getValues().size() > 0) { confidenceLower = result.getLower().getValues().get(0); } else { confidenceLower = Double.NaN; result.getForecast().getPoints().get(0).getValue(), input.getValue(), timestamp,
final List<Double> allHistory = new ArrayList<Double>(history.getValues()); final Double[] histValuesNotNull = AbstractRForecaster.removeNullValues(allHistory); final double[] values = ArrayUtils.toPrimitive(histValuesNotNull); if (history.getFrequency() != 0) { if (this.strategy != ForecastMethod.ARIMA) { AbstractRForecaster.RBRIDGE.toTS(varNameValues, history.getFrequency()); } else { AbstractRForecaster.RBRIDGE.toTS(varNameValues); if (history.getFrequency() != 0) { if (this.strategy != ForecastMethod.ARIMA) { AbstractRForecaster.RBRIDGE.toTS(varNameValues, history.getFrequency()); } else { AbstractRForecaster.RBRIDGE.toTS(varNameValues); tsForecast.appendAll(ArrayUtils.toObject(forecastValues)); final ITimeSeries<Double> tsLower; final ITimeSeries<Double> tsUpper; final double[] upperValues = AbstractRForecaster.RBRIDGE.eDblArr(this.upperOperationOnResult(varNameForecast)); tsLower = this.prepareForecastTS(); tsLower.appendAll(ArrayUtils.toObject(lowerValues)); tsUpper = this.prepareForecastTS(); tsUpper.appendAll(ArrayUtils.toObject(upperValues));
/** * @param numForecastSteps * number of values the forecaster is going to forecast * * @return Forecast Result */ @Override public IForecastResult forecast(final int numForecastSteps) { final ITimeSeries<Double> history = this.getTsOriginal(); final ITimeSeries<Double> tsFC = this.prepareForecastTS(); final List<Double> allHistory = new ArrayList<Double>(history.getValues()); final Double[] histValuesNotNull = MeanForecasterJava.removeNullValues(allHistory); final double mean = StatUtils.mean(ArrayUtils.toPrimitive(histValuesNotNull)); final Double[] forecastValues = new Double[numForecastSteps]; Arrays.fill(forecastValues, mean); tsFC.appendAll(forecastValues); return new ForecastResult(tsFC, this.getTsOriginal(), ForecastMethod.MEAN); }
/** * Checks whether the requirements for the input TS are met. * This default implementation checks whether the length of the time series is greater or equal to {@value #MIN_TS_SIZE_DEFAULT}. * This method can be overridden by any forecaster if more specific requirements are needed. */ protected boolean satisfiesInputTSRequirements(final ITimeSeries<Double> timeSeries) { return timeSeries.size() >= MIN_TS_SIZE_DEFAULT; }
/** * Compute the starting point with a different time unit. */ @Test public void testForecastStartingIsAccordingToLastAppendSecondsTU() { this.initForecastWithTimeUnit(TimeUnit.SECONDS); final long expectedStartTime = this.startTime; Assert.assertEquals(expectedStartTime, this.forecastSeries.getStartTime()); }
protected IForecastResult createNaNForecast(final ITimeSeries<Double> timeseries, final int numForecastSteps) { final ITimeSeries<Double> tsForecast = this.prepareForecastTS(); final ITimeSeries<Double> tsLower = this.prepareForecastTS(); final ITimeSeries<Double> tsUpper = this.prepareForecastTS(); final Double fcQuality = Double.NaN; final Double[] nanArray = new Double[numForecastSteps]; Arrays.fill(nanArray, Double.NaN); tsForecast.appendAll(nanArray); tsLower.appendAll(nanArray); tsUpper.appendAll(nanArray); return new ForecastResult(tsForecast, this.getTsOriginal(), this.getConfidenceLevel(), fcQuality, tsLower, tsUpper, this.strategy); }
/** * * @return TS */ protected ITimeSeries<T> prepareForecastTS() { final ITimeSeries<T> history = this.getTsOriginal(); final long startTime = history.getStartTime(); final TimeSeries<T> tsFC = new TimeSeries<>(startTime, history.getTimeSeriesTimeUnit(), history.getDeltaTime(), history.getDeltaTimeUnit()); return tsFC; }
/** * Test if the correct calculation is done. In this case mean is bigger than the lower bounds. */ @Test public void testLowerCalculationOneStep() { Assert.assertEquals(this.steps, this.lowerSeries.size()); final ITimeSeriesPoint<Double> stepFC = this.forecast.getLower().getPoints().get(0); Assert.assertTrue(this.mean > stepFC.getValue()); }
currentWindow.append(input.getValue()); if (result.getForecast().getPoints().size() > 0) { if (result.getUpper().getValues().size() > 0) { confidenceUpper = result.getUpper().getValues().get(0); } else { confidenceUpper = Double.NaN; if (result.getLower().getValues().size() > 0) { confidenceLower = result.getLower().getValues().get(0); } else { confidenceLower = Double.NaN; result.getForecast().getPoints().get(0).getValue(), input.getValue(), timestamp,
final List<Double> allHistory = new ArrayList<>(history.getValues()); final Double[] histValuesNotNull = AbstractRForecaster.removeNullValues(allHistory); final double[] values = ArrayUtils.toPrimitive(histValuesNotNull); if (history.getFrequency() != 0) { if (this.strategy != ForecastMethod.ARIMA) { AbstractRForecaster.RBRIDGE.toTS(varNameValues, history.getFrequency()); } else { AbstractRForecaster.RBRIDGE.toTS(varNameValues); if (history.getFrequency() != 0) { if (this.strategy != ForecastMethod.ARIMA) { AbstractRForecaster.RBRIDGE.toTS(varNameValues, history.getFrequency()); } else { AbstractRForecaster.RBRIDGE.toTS(varNameValues); tsForecast.appendAll(ArrayUtils.toObject(forecastValues)); final ITimeSeries<Double> tsLower; final ITimeSeries<Double> tsUpper; final double[] upperValues = AbstractRForecaster.RBRIDGE.eDblArr(this.upperOperationOnResult(varNameForecast)); tsLower = this.prepareForecastTS(); tsLower.appendAll(ArrayUtils.toObject(lowerValues)); tsUpper = this.prepareForecastTS(); tsUpper.appendAll(ArrayUtils.toObject(upperValues));
/** * @param numForecastSteps * number of values the forecaster is going to forecast * * @return Forecast Result */ @Override public IForecastResult forecast(final int numForecastSteps) { final ITimeSeries<Double> history = this.getTsOriginal(); final ITimeSeries<Double> tsFC = this.prepareForecastTS(); final List<Double> allHistory = new ArrayList<Double>(history.getValues()); final Double[] histValuesNotNull = MeanForecasterJava.removeNullValues(allHistory); final double mean = StatUtils.mean(ArrayUtils.toPrimitive(histValuesNotNull)); final Double[] forecastValues = new Double[numForecastSteps]; Arrays.fill(forecastValues, mean); tsFC.appendAll(forecastValues); return new ForecastResult(tsFC, this.getTsOriginal(), ForecastMethod.MEAN); }
/** * Checks whether the requirements for the input TS are met. * This default implementation checks whether the length of the time series is greater or equal to {@value #MIN_TS_SIZE_DEFAULT}. * This method can be overridden by any forecaster if more specific requirements are needed. * * @param timeSeries time series * * @return returns true when requirements are met */ protected boolean satisfiesInputTSRequirements(final ITimeSeries<Double> timeSeries) { return timeSeries.size() >= MIN_TS_SIZE_DEFAULT; }
/** * Test of the MeanForecater via Rserve. */ @Test public void testForecastStartingIsAccordingToLastAppend() { Assert.assertEquals(this.ts, this.forecaster.getTsOriginal()); // we added three timepoints, so we must be here: final long expectedStartTime = this.startTime; Assert.assertEquals(expectedStartTime, this.forecastSeries.getStartTime()); }
protected IForecastResult createNaNForecast(final ITimeSeries<Double> timeseries, final int numForecastSteps) { final ITimeSeries<Double> tsForecast = this.prepareForecastTS(); final ITimeSeries<Double> tsLower = this.prepareForecastTS(); final ITimeSeries<Double> tsUpper = this.prepareForecastTS(); final Double fcQuality = Double.NaN; final Double[] nanArray = new Double[numForecastSteps]; Arrays.fill(nanArray, Double.NaN); tsForecast.appendAll(nanArray); tsLower.appendAll(nanArray); tsUpper.appendAll(nanArray); return new ForecastResult(tsForecast, this.getTsOriginal(), this.getConfidenceLevel(), fcQuality, tsLower, tsUpper, this.strategy); }
/** * Returns a new time series object shortened to the last x values. * * @param ts * timeseries * @param x * last x value * @return new time series object */ private static ITimeSeries<Double> getLastXofTS(final ITimeSeries<Double> ts, final int x) { if (ts.size() >= x) { Double[] a = new Double[ts.size()]; a = ts.getValues().toArray(a); final Double[] b = new Double[x]; for (int i = 0; i < x; i++) { b[i] = a[(ts.size() - x) + i]; } long newStartTime = ts.getStartTime(); newStartTime += (ts.size() - x) * ts.getDeltaTimeUnit().toMillis(ts.getDeltaTime()); final ITimeSeries<Double> tsLastX = new TimeSeries<Double>(newStartTime, ts.getTimeSeriesTimeUnit(), ts.getDeltaTime(), ts.getDeltaTimeUnit(), ts.getCapacity()); tsLastX.appendAll(b); return tsLastX; } else { return ts; } } }
/** * Test if the correct calculation is done. In this case mean is smaller than the upper bounds. */ @Test public void testUpperCalculationOneStep() { Assert.assertEquals(this.steps, this.upperSeries.size()); final ITimeSeriesPoint<Double> stepFC = this.forecast.getUpper().getPoints().get(0); Assert.assertTrue(this.mean < stepFC.getValue()); } }