diff --git a/src/main/java/com/yahoo/egads/models/tsmm/MovingAverageModel.java b/src/main/java/com/yahoo/egads/models/tsmm/MovingAverageModel.java index ccc4978..d69d3a6 100644 --- a/src/main/java/com/yahoo/egads/models/tsmm/MovingAverageModel.java +++ b/src/main/java/com/yahoo/egads/models/tsmm/MovingAverageModel.java @@ -28,12 +28,27 @@ public class MovingAverageModel extends TimeSeriesAbstractModel { // The model that will be used for forecasting. private ForecastingModel forecaster; + // The default value + private int period = 2; + // Stores the historical values. private TimeSeries.DataSequence data; public MovingAverageModel(Properties config) { super(config); modelName = "MovingAverageModel"; + // + String moveStep = config.getProperty("MOVE_STEPS"); + if (moveStep != null) { + try { + int ms = Integer.parseInt(moveStep); + if (ms > period) { + this.period = ms; + } + } catch (NumberFormatException e) { + logger.warn("Wrong move step value set for MovingAverageModel: " + moveStep, e); + } + } } public void reset() { @@ -52,8 +67,7 @@ public void train(TimeSeries.DataSequence data) { } observedData.setTimeVariable("x"); - // TODO: Make window configurable. - forecaster = new net.sourceforge.openforecast.models.MovingAverageModel(2); + forecaster = new net.sourceforge.openforecast.models.MovingAverageModel(this.period); forecaster.init(observedData); initForecastErrors(forecaster, data); diff --git a/src/test/resources/sample_config.ini b/src/test/resources/sample_config.ini index d1e1740..b3d63a6 100644 --- a/src/test/resources/sample_config.ini +++ b/src/test/resources/sample_config.ini @@ -164,3 +164,10 @@ BETA 0.001 # Smoothing factor for the seasonal component GAMMA 0.001 + +##################################### +### Moving Average Model Config ### +##################################### +# Move steps +# see: https://otexts.com/fpp2/moving-averages.html +MOVE_STEPS 5