/** * @param numForecastSteps * amount of to calculate FC steps * @return ForecastResult */ @Override public final IForecastResult forecast(final int numForecastSteps) { final ITimeSeries<Double> history = this.getTsOriginal(); IForecastResult forecast = null; if (this.satisfiesInputTSRequirements(history)) { try { forecast = this.forecastWithR(numForecastSteps); } catch (final InvalidREvaluationResultException exception) { LOGGER.warn("Exception occured when forecast with R", exception); } } if (forecast == null) { LOGGER.warn("Null result for forecast. Falling back to Double.NaN result."); forecast = this.createNaNForecast(history, numForecastSteps); } return forecast; }
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); }
/** * * @param historyTimeseries * timeseries * * @param modelFunc * modelFunction * @param forecastFunc * forecastfunction * @param strategy * FC strategy */ public AbstractRForecaster(final ITimeSeries<Double> historyTimeseries, final String modelFunc, final String forecastFunc, final ForecastMethod strategy) { super(historyTimeseries); this.modelFunc = modelFunc; this.forecastFunc = forecastFunc; this.strategy = strategy; if (!forecastPackageAvailable) { this.logForecastModuleNotAvailableOrLoaded(); } }
private ForecastResult forecastWithR(final int numForecastSteps) throws InvalidREvaluationResultException { final ITimeSeries<Double> history = this.getTsOriginal(); final ITimeSeries<Double> tsForecast = this.prepareForecastTS(); final Double[] histValuesNotNull = AbstractRForecaster.removeNullValues(allHistory); final double[] values = ArrayUtils.toPrimitive(histValuesNotNull); final String[] additionalModelParams = this.getModelFuncParams(); if ((this.getConfidenceLevel() == 0) || !this.supportsConfidence()) { AbstractRForecaster.RBRIDGE.evalWithR(String.format("%s <- %s(%s, h=%d)", varNameForecast, this.forecastFunc, varNameModel, numForecastSteps)); } else { AbstractRForecaster.RBRIDGE.evalWithR(String.format("%s <- %s(%s, h=%d, level=c(%d))", varNameForecast, this.forecastFunc, varNameModel, numForecastSteps, this.getConfidenceLevel())); final double[] forecastValues = AbstractRForecaster.RBRIDGE.eDblArr(this.forecastOperationOnResult(varNameForecast)); if ((this.getConfidenceLevel() == 0) || !this.supportsConfidence()) { tsLower = tsForecast; tsUpper = tsForecast; } else { final double[] lowerValues = AbstractRForecaster.RBRIDGE.eDblArr(this.lowerOperationOnResult(varNameForecast)); 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)); return new ForecastResult(tsForecast, this.getTsOriginal(), this.getConfidenceLevel(), fcQuality, tsLower, tsUpper, this.strategy);
private ForecastResult forecastWithR(final int numForecastSteps) throws InvalidREvaluationResultException { final ITimeSeries<Double> history = this.getTsOriginal(); final ITimeSeries<Double> tsForecast = this.prepareForecastTS(); final Double[] histValuesNotNull = AbstractRForecaster.removeNullValues(allHistory); final double[] values = ArrayUtils.toPrimitive(histValuesNotNull); final String[] additionalModelParams = this.getModelFuncParams(); if ((this.getConfidenceLevel() == 0) || !this.supportsConfidence()) { AbstractRForecaster.RBRIDGE.evalWithR(String.format("%s <- %s(%s, h=%d)", varNameForecast, this.forecastFunc, varNameModel, numForecastSteps)); } else { AbstractRForecaster.RBRIDGE.evalWithR(String.format("%s <- %s(%s, h=%d, level=c(%d))", varNameForecast, this.forecastFunc, varNameModel, numForecastSteps, this.getConfidenceLevel())); final double[] forecastValues = AbstractRForecaster.RBRIDGE.eDblArr(this.forecastOperationOnResult(varNameForecast)); if ((this.getConfidenceLevel() == 0) || !this.supportsConfidence()) { tsLower = tsForecast; tsUpper = tsForecast; } else { final double[] lowerValues = AbstractRForecaster.RBRIDGE.eDblArr(this.lowerOperationOnResult(varNameForecast)); 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)); return new ForecastResult(tsForecast, this.getTsOriginal(), this.getConfidenceLevel(), fcQuality, tsLower, tsUpper, this.strategy);
/** * @param numForecastSteps * amount of to calculate FC steps * @return ForecastResult */ @Override public final IForecastResult forecast(final int numForecastSteps) { final ITimeSeries<Double> history = this.getTsOriginal(); IForecastResult forecast = null; if (this.satisfiesInputTSRequirements(history)) { try { forecast = this.forecastWithR(numForecastSteps); } catch (final InvalidREvaluationResultException exception) { LOG.warn("Exception occured when forecast with R", exception); } } if (forecast == null) { LOG.warn("Null result for forecast. Falling back to Double.NaN result."); forecast = this.createNaNForecast(history, numForecastSteps); } return forecast; }
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); }
/** * * @param historyTimeseries * timeseries * @param modelFunc * modelFunction * @param forecastFunc * forecastfunction * @param confidenceLevel * value of confedenclevel * * @param strategy * FC strategy */ public AbstractRForecaster(final ITimeSeries<Double> historyTimeseries, final String modelFunc, final String forecastFunc, final int confidenceLevel, final ForecastMethod strategy) { super(historyTimeseries, confidenceLevel); this.modelFunc = modelFunc; this.forecastFunc = forecastFunc; this.strategy = strategy; if (!forecastPackageAvailable) { this.logForecastModuleNotAvailableOrLoaded(); } }
/** * * @param historyTimeseries * timeseries * * @param modelFunc * modelFunction * @param forecastFunc * forecastfunction * @param strategy * FC strategy */ public AbstractRForecaster(final ITimeSeries<Double> historyTimeseries, final String modelFunc, final String forecastFunc, final ForecastMethod strategy) { super(historyTimeseries); this.modelFunc = modelFunc; this.forecastFunc = forecastFunc; this.strategy = strategy; if (!forecastPackageAvailable) { this.logForecastModuleNotAvailableOrLoaded(); } }
/** * * @param historyTimeseries * timeseries * @param modelFunc * modelFunction * @param forecastFunc * forecastfunction * @param confidenceLevel * value of confedenclevel * * @param strategy * FC strategy */ public AbstractRForecaster(final ITimeSeries<Double> historyTimeseries, final String modelFunc, final String forecastFunc, final int confidenceLevel, final ForecastMethod strategy) { super(historyTimeseries, confidenceLevel); this.modelFunc = modelFunc; this.forecastFunc = forecastFunc; this.strategy = strategy; if (!forecastPackageAvailable) { this.logForecastModuleNotAvailableOrLoaded(); } }