From 9279ec639e60a4775e0acf6a73a9a8ec3b06a733 Mon Sep 17 00:00:00 2001 From: meadlai Date: Wed, 22 Feb 2023 19:56:38 +0800 Subject: [PATCH 1/3] Add config for Moving Average Model --- src/test/resources/sample_config.ini | 7 +++++++ 1 file changed, 7 insertions(+) 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 From a27110d96b7e7f2b0d1e13f4d646944e4e0bb683 Mon Sep 17 00:00:00 2001 From: meadlai Date: Wed, 22 Feb 2023 20:02:15 +0800 Subject: [PATCH 2/3] Add config for Moving Average Model Make window configurable, add move step in the config file --- .../egads/models/tsmm/MovingAverageModel.java | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) 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..eb371bb 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); From 4bcceb852e1f733b995dd239307c85cb75da3c15 Mon Sep 17 00:00:00 2001 From: meadlai Date: Wed, 22 Feb 2023 20:02:50 +0800 Subject: [PATCH 3/3] Update MovingAverageModel.java --- .../egads/models/tsmm/MovingAverageModel.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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 eb371bb..d69d3a6 100644 --- a/src/main/java/com/yahoo/egads/models/tsmm/MovingAverageModel.java +++ b/src/main/java/com/yahoo/egads/models/tsmm/MovingAverageModel.java @@ -38,17 +38,17 @@ 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); + 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() { @@ -67,7 +67,7 @@ public void train(TimeSeries.DataSequence data) { } observedData.setTimeVariable("x"); - forecaster = new net.sourceforge.openforecast.models.MovingAverageModel(this.period); + forecaster = new net.sourceforge.openforecast.models.MovingAverageModel(this.period); forecaster.init(observedData); initForecastErrors(forecaster, data);