|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sourceforge.openforecast.models.AbstractForecastingModel net.sourceforge.openforecast.models.AbstractTimeBasedModel net.sourceforge.openforecast.models.WeightedMovingAverageModel
public class WeightedMovingAverageModel
A weighted moving average forecast model is based on an artificially constructed time series in which the value for a given time period is replaced by the weighted mean of that value and the values for some number of preceding time periods. As you may have guessed from the description, this model is best suited to time-series data; i.e. data that changes over time.
Since the forecast value for any given period is a weighted average of the previous periods, then the forecast will always appear to "lag" behind either increases or decreases in the observed (dependent) values. For example, if a data series has a noticable upward trend then a weighted moving average forecast will generally provide an underestimate of the values of the dependent variable.
The weighted moving average model, like the moving average model, has an advantage over other forecasting models in that it does smooth out peaks and troughs (or valleys) in a set of observations. However, like the moving average model, it also has several disadvantages. In particular this model does not produce an actual equation. Therefore, it is not all that useful as a medium-long range forecasting tool. It can only reliably be used to forecast a few periods into the future.
Field Summary |
---|
Fields inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel |
---|
accuracyIndicators, initialized |
Constructor Summary | |
---|---|
protected |
WeightedMovingAverageModel()
Constructs a new weighted moving average forecasting model. |
|
WeightedMovingAverageModel(double[] weights)
Constructs a new weighted moving average forecasting model, using the specified weights. |
protected |
WeightedMovingAverageModel(String independentVariable)
Deprecated. As of 0.4, replaced by WeightedMovingAverageModel(java.lang.String) . |
|
WeightedMovingAverageModel(String independentVariable,
double[] weights)
Deprecated. As of 0.4, replaced by WeightedMovingAverageModel(double[]) . |
Method Summary | |
---|---|
protected double |
forecast(double timeValue)
Returns the forecast value of the dependent variable for the given value of the independent time variable. |
String |
getForecastType()
Returns a one or two word name of this type of forecasting model. |
protected int |
getNumberOfPeriods()
Returns the current number of periods used in this model. |
int |
getNumberOfPredictors()
Returns the number of predictors used by the underlying model. |
protected void |
setWeights(double[] weights)
Sets the weights used by this weighted moving average forecasting model to the given weights. |
String |
toString()
This should be overridden to provide a textual description of the current forecasting model including, where possible, any derived parameters used. |
Methods inherited from class net.sourceforge.openforecast.models.AbstractTimeBasedModel |
---|
forecast, getForecastValue, getIndependentVariable, getMaximumTimeValue, getMinimumTimeValue, getObservedValue, getTimeInterval, getTimeVariable, init, initTimeVariable |
Methods inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel |
---|
calculateAccuracyIndicators, forecast, getAIC, getBias, getMAD, getMAPE, getMSE, getSAE |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public WeightedMovingAverageModel(double[] weights)
The size of the weights array is used to determine the number of
observations to be used to calculate the weighted moving average.
Additionally, the most recent period will be given the weight defined
by the first element of the array; i.e. weights[0]
.
The size of the weights array is also used to determine the amount of future periods that can effectively be forecast. With a 50 day weighted moving average, then we cannot reasonably - with any degree of accuracy - forecast more than 50 days beyond the last period for which data is available. Even forecasting near the end of this range is likely be be unreliable.
In general, the weights passed to this constructor should add up to 1.0. However, as a convenience, if the sum of the weights does not add up to 1.0, this implementation scales all weights proportionally so that they do sum to 1.0.
weights
- an array of weights to assign to the historical
observations when calculating the weighted moving average.public WeightedMovingAverageModel(String independentVariable, double[] weights)
WeightedMovingAverageModel(double[])
.
independentVariable
- the name of the independent variable to use
in this model.weights
- an array of weights to assign to the historical
observations when calculating the weighted moving average.protected WeightedMovingAverageModel()
protected WeightedMovingAverageModel(String independentVariable)
WeightedMovingAverageModel(java.lang.String)
.
independentVariable
- the name of the independent variable to use
in this model.Method Detail |
---|
protected void setWeights(double[] weights)
Any subclass using the one-argument constructor must subsequently
call setWeights before invoking the AbstractTimeBasedModel.init(net.sourceforge.openforecast.DataSet)
method to
initialize the model.
In general, the weights passed to this method should add up to 1.0. However, as a convenience, if the sum of the weights does not add up to 1.0, this implementation scales all weights proportionally so that they do sum to 1.0.
weights
- an array of weights to assign to the historical
observations when calculating the weighted moving average.protected double forecast(double timeValue) throws IllegalArgumentException
forecast
in class AbstractTimeBasedModel
timeValue
- the value of the time variable for which a forecast
value is required.
IllegalArgumentException
- if there is insufficient historical
data - observations passed to init - to generate a forecast for the
given time value.public int getNumberOfPredictors()
protected int getNumberOfPeriods()
getNumberOfPeriods
in class AbstractTimeBasedModel
public String getForecastType()
getForecastType
in interface ForecastingModel
getForecastType
in class AbstractTimeBasedModel
public String toString()
toString
in interface ForecastingModel
toString
in class AbstractTimeBasedModel
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |