net.sourceforge.openforecast.models
Class DoubleExponentialSmoothingModel

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

public class DoubleExponentialSmoothingModel
extends AbstractTimeBasedModel

Double exponential smoothing - also known as Holt exponential smoothing - is a refinement of the popular simple exponential smoothing model but adds another component which takes into account any trend in the data. Simple exponential smoothing models work best with data where there are no trend or seasonality components to the data. When the data exhibits either an increasing or decreasing trend over time, simple exponential smoothing forecasts tend to lag behind observations. Double exponential smoothing is designed to address this type of data series by taking into account any trend in the data.

Note that double exponential smoothing still does not address seasonality. For better exponentially smoothed forecasts using data where there is expected or known to be seasonal variation in the data, use triple exponential smoothing.

As with simple exponential smoothing, in double exponential smoothing models past observations are given exponentially smaller weights as the observations get older. In other words, recent observations are given relatively more weight in forecasting than the older observations.

There are two equations associated with Double Exponential Smoothing.

where:

To initialize the double exponential smoothing model, f1 is set to Y1, and the initial slope b1 is set to the difference between the first two observations; i.e. Y2-Y1. Although there are other ways to initialize 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 values for the smoothing constants

The smoothing constants must be a values in the range 0.0-1.0. But, what are the "best" values to use for the smoothing constants? This depends on the data series being modeled.

In general, 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). The Forecaster class can help with selection of the best values for the smoothing constants.

Since:
0.4
Author:
Steven R. Gould
See Also:
Engineering Statistics Handbook, 6.4.3.3 Double Exponential Smoothing

Field Summary
 
Fields inherited from class net.sourceforge.openforecast.models.AbstractForecastingModel
accuracyIndicators, initialized
 
Constructor Summary
DoubleExponentialSmoothingModel(double alpha, double gamma)
          Constructs a new double exponential smoothing forecasting model, using the given smoothing constants - alpha and gamma.
 
Method Summary
protected  void calculateAccuracyIndicators(DataSet dataSet)
          Since this version of double exponential smoothing uses the current observation to calculate a smoothed value, we must override the calculation of the accuracy indicators.
protected  double forecast(double t)
          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 DoubleExponentialSmoothingModel getBestFitModel(DataSet dataSet)
          Factory method that returns a "best fit" double exponential smoothing model for the given data set.
static DoubleExponentialSmoothingModel getBestFitModel(DataSet dataSet, double alphaTolerance, double gammaTolerance)
          Factory method that returns a best fit double exponential smoothing model for the given data set.
 String getForecastType()
          Returns a one or two word name of this type of forecasting model.
 double getGamma()
          Returns the value of the trend smoothing constant, gamma, used in this 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
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

DoubleExponentialSmoothingModel

public DoubleExponentialSmoothingModel(double alpha,
                                       double gamma)
Constructs a new double exponential smoothing forecasting model, using the given smoothing constants - alpha and gamma. 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.
gamma - the second smoothing constant, gamma to use in this model to smooth the trend. Must be a value in the range 0.0-1.0.
Throws:
IllegalArgumentException - if the value of either smoothing constant is invalid - outside the range 0.0-1.0.
Method Detail

getBestFitModel

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

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

getBestFitModel

public static DoubleExponentialSmoothingModel getBestFitModel(DataSet dataSet,
                                                              double alphaTolerance,
                                                              double gammaTolerance)
Factory method that returns a best fit double exponential smoothing model for the given data set. This, like the overloaded getBestFitModel(DataSet), attempts to derive "good" - hopefully near optimal - values for the alpha and gamma smoothing constants.

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 values of alpha and gamma - is expected to be very similar either way.

Note that the approach used to calculate the best smoothing constants - alpha and gamma - may end up choosing values near a local optimum. In other words, there may be other values for alpha and gamma that result in an even better model.

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

forecast

protected double forecast(double t)
                   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. See the class documentation for details on the formulation used.

Specified by:
forecast in class AbstractTimeBasedModel
Parameters:
t - the value of the time variable for which a forecast value is required.
Returns:
the forecast value of the dependent variable at time, t.
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 double exponential smoothing only two previous periods are needed - though such a model would be of relatively little use. At least ten to fifteen 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

calculateAccuracyIndicators

protected void calculateAccuracyIndicators(DataSet dataSet)
Since this version of double exponential smoothing uses the current observation to calculate a smoothed value, we must override the calculation of the accuracy indicators.

Overrides:
calculateAccuracyIndicators in class AbstractForecastingModel
Parameters:
dataSet - the DataSet to use to evaluate this model, and to calculate the accuracy indicators against.

getAlpha

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

Returns:
the value of the smoothing constant, alpha.
See Also:
getGamma()

getGamma

public double getGamma()
Returns the value of the trend smoothing constant, gamma, used in this model.

Returns:
the value of the trend smoothing constant, gamma.
See Also:
getAlpha()

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