net.sourceforge.openforecast.models
Class SimpleExponentialSmoothingModel

java.lang.Object
  extended by net.sourceforge.openforecast.models.AbstractForecastingModel
      extended by net.sourceforge.openforecast.models.AbstractTimeBasedModel
          extended by net.sourceforge.openforecast.models.SimpleExponentialSmoothingModel
All Implemented Interfaces:
ForecastingModel

public class SimpleExponentialSmoothingModel
extends AbstractTimeBasedModel

A simple exponential smoothing forecast model is a very popular model used to produce a smoothed Time Series. Whereas in simple Moving Average models the past observations are weighted equally, Exponential Smoothing assigns exponentially decreasing weights as the observations get older.

In other words, recent observations are given relatively more weight in forecasting than the older observations.

In the case of moving averages, the weights assigned to the observations are the same and are equal to 1/N. In simple exponential smoothing, however, a "smoothing parameter" - or "smoothing constant" - is used to determine the weights assigned to the observations.

This simple exponential smoothing model begins by setting the forecast for the second period equal to the observation of the first period. Note that there are ways of initializing the model. As of the time of writing, these alternatives are not available in this implementation. Future implementations of this model may offer these options.

Choosing a smoothing constant

The smoothing constant must be a value in the range 0.0-1.0. But, what is the "best" value to use for the smoothing constant? This depends on the data series being modeled. The speed at which the older responses are dampened (smoothed) is a function of the value of the smoothing constant. When this smoothing constant is close to 1.0, dampening is quick - more weight is given to recent observations - and when it is close to 0.0, dampening is slow - and relatively less weight is given to recent observations.

The best value for the smoothing constant is the one that results in the smallest mean of the squared errors (or other similar accuracy indicator).

Note on alternate formulations

This class supports two approaches to forecasting using Simple Exponential Smoothing. The first approach - and the default approach - is to use the formulation according to Hunter. Hunter's formulation uses the observed and forecast values from the previous period to come up with a forecast for the current period.

An alternative formulation is also supported - that proposed by Roberts. The formulation according to Roberts uses the observed value from the current period and the forecast value from the previous period to come up with a forecast for the current period.

By default, the formulation according to Hunter is used. To override this, use the three argument constructor and specify ROBERTS as the third argument.

Since:
0.4
Author:
Steven R. Gould
See Also:
Engineering Statistics Handbook, 6.4.3.1 Simple Expnential Smoothing

Field Summary
static int HUNTER
          Used in the three argument constructor to specify that Hunter's formula is to be used for calculating forecast values.
static int ROBERTS
          Used in the three argument constructor to specify that Robert's formula is to be used for calculating forecast values.
 
Fields inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel
accuracyIndicators, initialized
 
Constructor Summary
SimpleExponentialSmoothingModel(double alpha)
          Constructs a new simple exponential smoothing forecasting model, using the specified smoothing constant.
SimpleExponentialSmoothingModel(double alpha, int approach)
          Constructs a new exponential smoothing forecasting model, using the given name as the independent variable and the specified smoothing constant.
SimpleExponentialSmoothingModel(String independentVariable, double alpha)
          Deprecated. As of 0.4, replaced by SimpleExponentialSmoothingModel(double).
SimpleExponentialSmoothingModel(String independentVariable, double alpha, int approach)
          Deprecated. As of 0.4, replaced by SimpleExponentialSmoothingModel(double,int).
 
Method Summary
protected  double forecast(double timeValue)
          Returns the forecast value of the dependent variable for the given value of the independent time variable using a single exponential smoothing model.
 double getAlpha()
          Returns the value of the smoothing constant, alpha, used in this model.
static SimpleExponentialSmoothingModel getBestFitModel(DataSet dataSet)
          Factory method that returns a "best fit" simple exponential smoothing model for the given data set.
static SimpleExponentialSmoothingModel getBestFitModel(DataSet dataSet, double alphaTolerance)
          Factory method that returns a best fit simple exponential smoothing model for the given data set.
 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.
 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
 

Field Detail

HUNTER

public static final int HUNTER
Used in the three argument constructor to specify that Hunter's formula is to be used for calculating forecast values. The formulation according to Hunter uses the observed and forecast values from the previous period to come up with a forecast for the current period.

See Also:
Constant Field Values

ROBERTS

public static final int ROBERTS
Used in the three argument constructor to specify that Robert's formula is to be used for calculating forecast values. The formulation according to Roberts uses the observed value from the current period and the forecast value from the previous period to come up with a forecast for the current period.

See Also:
Constant Field Values
Constructor Detail

SimpleExponentialSmoothingModel

public SimpleExponentialSmoothingModel(double alpha)
Constructs a new simple exponential smoothing forecasting model, using the specified smoothing constant. For a valid model to be constructed, you should call init and pass in a data set containing a series of data points with the time variable initialized to identify the independent variable.

Parameters:
alpha - the smoothing constant to use for this exponential smoothing model. Must be a value in the range 0.0-1.0.
Throws:
IllegalArgumentException - if the value of the smoothing constant is invalid - outside the range 0.0-1.0.

SimpleExponentialSmoothingModel

public SimpleExponentialSmoothingModel(String independentVariable,
                                       double alpha)
Deprecated. As of 0.4, replaced by SimpleExponentialSmoothingModel(double).

Constructs a new exponential smoothing forecasting model, using the given name as the independent variable and the specified smoothing constant.

Parameters:
independentVariable - the name of the independent variable - or time variable - to use in this model.
alpha - the smoothing constant to use for this exponential smoothing model. Must be a value in the range 0.0-1.0.
Throws:
IllegalArgumentException - if the value of the smoothing constant is invalid - outside the range 0.0-1.0.

SimpleExponentialSmoothingModel

public SimpleExponentialSmoothingModel(double alpha,
                                       int approach)
Constructs a new exponential smoothing forecasting model, using the given name as the independent variable and the specified smoothing constant. For a valid model to be constructed, you should call init and pass in a data set containing a series of data points with the time variable initialized to identify the independent variable.

Parameters:
alpha - the smoothing constant to use for this exponential smoothing model. Must be a value in the range 0.0-1.0.
approach - determines which approach to use for the forecasting. This must be either HUNTER - the default - or ROBERTS.
Throws:
IllegalArgumentException - if the value of the smoothing constant is invalid - outside the range 0.0-1.0.

SimpleExponentialSmoothingModel

public SimpleExponentialSmoothingModel(String independentVariable,
                                       double alpha,
                                       int approach)
Deprecated. As of 0.4, replaced by SimpleExponentialSmoothingModel(double,int).

Constructs a new exponential smoothing forecasting model, using the given name as the independent variable and the specified smoothing constant.

Parameters:
independentVariable - the name of the independent variable - or time variable - to use in this model.
alpha - the smoothing constant to use for this exponential smoothing model. Must be a value in the range 0.0-1.0.
approach - determines which approach to use for the forecasting. This must be either HUNTER - the default - or ROBERTS.
Throws:
IllegalArgumentException - if the value of the smoothing constant is invalid - outside the range 0.0-1.0.
Method Detail

getBestFitModel

public static SimpleExponentialSmoothingModel getBestFitModel(DataSet dataSet)
Factory method that returns a "best fit" simple exponential smoothing model for the given data set. This, like the overloaded getBestFitModel(DataSet,double), attempts to derive a "good" - hopefully near optimal - value for the alpha smoothing constant.

Parameters:
dataSet - the observations for which a "best fit" simple exponential smoothing model is required.
Returns:
a best fit simple exponential smoothing model for the given data set.
See Also:
getBestFitModel(DataSet,double)

getBestFitModel

public static SimpleExponentialSmoothingModel getBestFitModel(DataSet dataSet,
                                                              double alphaTolerance)
Factory method that returns a best fit simple exponential smoothing model for the given data set. This, like the overloaded getBestFitModel(DataSet), attempts to derive a "good" - hopefully near optimal - value for the alpha smoothing constant.

To determine which model is "best", this method currently uses only the Mean Squared Error (MSE). Future versions may use other measures in addition to the MSE. However, the resulting "best fit" model - and the associated value of alpha - is expected to be very similar either way.

Note that the approach used to calculate the best smoothing constant, alpha, may end up choosing values near a local optimum. In other words, there may be other values for alpha and that result in a model with the same, or even better MSE.

Parameters:
dataSet - the observations for which a "best fit" simple exponential smoothing model is required.
alphaTolerance - the required precision/accuracy - or tolerance of error - required in the estimate of the alpha smoothing constant.
Returns:
a best fit simple exponential smoothing model for the given data set.

forecast

protected double forecast(double timeValue)
                   throws IllegalArgumentException
Returns the forecast value of the dependent variable for the given value of the independent time variable using a single exponential smoothing model. The model used here follows the formulation of Hunter that combines the observation and forecast values from the previous period.

Specified by:
forecast in class AbstractTimeBasedModel
Parameters:
timeValue - the value of the time variable for which a forecast value is required.
Returns:
the forecast value of the dependent variable for the given time.
Throws:
IllegalArgumentException - if there is insufficient historical data - observations passed to init - to generate a forecast for the given time value.

getNumberOfPeriods

protected int getNumberOfPeriods()
Returns the current number of periods used in this model. This is also the minimum number of periods required in order to produce a valid forecast. Strictly speaking, for simple exponential smoothing only one previous period is needed - though such a model would be of relatively little use. At least five to ten prior observations would be preferred.

Specified by:
getNumberOfPeriods in class AbstractTimeBasedModel
Returns:
the minimum number of periods used in this model.

getNumberOfPredictors

public int getNumberOfPredictors()
Returns the number of predictors used by the underlying model.

Returns:
the number of predictors used by the underlying model.
Since:
0.5

getAlpha

public double getAlpha()
Returns the value of the smoothing constant, alpha, used in this model.

Returns:
the value of the smoothing constant, alpha.

getForecastType

public String getForecastType()
Returns a one or two word name of this type of forecasting model. Keep this short. A longer description should be implemented in the toString method.

Specified by:
getForecastType in interface ForecastingModel
Overrides:
getForecastType in class AbstractTimeBasedModel
Returns:
a string representation of the type of forecasting model implemented.

toString

public String toString()
This should be overridden to provide a textual description of the current forecasting model including, where possible, any derived parameters used.

Specified by:
toString in interface ForecastingModel
Overrides:
toString in class AbstractTimeBasedModel
Returns:
a string representation of the current forecast model, and its parameters.


OpenForecast, Copyright (c) Steven Gould, 2002-2011