Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config for Moving Average Model #81

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions src/main/java/com/yahoo/egads/models/tsmm/MovingAverageModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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);

Expand Down
7 changes: 7 additions & 0 deletions src/test/resources/sample_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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