net.sourceforge.openforecast.models
Class TripleExponentialSmoothingModel

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

public class TripleExponentialSmoothingModel
extends AbstractTimeBasedModel

Triple exponential smoothing - also known as the Winters method - is a refinement of the popular double exponential smoothing model but adds another component which takes into account any seasonality - or periodicity - 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. However, neither of these exponential smoothing models address any seasonality in the data.

For better exponentially smoothed forecasts of data where there is expected or known to be seasonal variation in the data, use triple exponential smoothing.

As with simple exponential smoothing, in triple 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. This is true for all terms involved - namely, the base level Lt, the trend Tt as well as the seasonality index st.

There are four equations associated with Triple Exponential Smoothing.

where:

There are a variety of different ways to come up with initial values for the triple exponential smoothing model. The approach implemented here uses the first two "years" (or complete cycles) of data to come up with initial values for Lt, Tt and st. Therefore, at least two complete cycles of data are required to initialize the model. For best results, more data is recommended - ideally a minimum of 4 or 5 complete cycles. This gives the model chance to better adapt to the data, instead of relying on getting - guessing - good estimates for the initial conditions.

Choosing values for the smoothing constants

The smoothing constants a, b, and g each must be a value 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 getBestFitModel(net.sourceforge.openforecast.DataSet) static methods can help with the selection of the best values for the smoothing constants, though the results obtained from these methods should always be validated. If any of the "best fit" smoothing constants turns out to be 1.0, you may want to be a little suspicious. This may be an indication that you really need to use more data to initialize the model.

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

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

TripleExponentialSmoothingModel

public TripleExponentialSmoothingModel(double alpha,
                                       double beta,
                                       double gamma)
Constructs a new triple exponential smoothing forecasting model, using the given smoothing constants - alpha, beta 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. Values above 0.5 are uncommon - though they are still valid and are supported by this implementation.
beta - the second smoothing constant, beta to use in this model to smooth the trend. Must be a value in the range 0.0-1.0. Values above 0.5 are uncommon - though they are still valid and are supported by this implementation.
gamma - the third smoothing constant, gamma to use in this model to smooth the seasonality. Must be a value in the range 0.0-1.0.
Throws:
IllegalArgumentException - if the value of any of the smoothing constants are invalid - outside the range 0.0-1.0.
Method Detail

getBestFitModel

public static TripleExponentialSmoothingModel getBestFitModel(DataSet dataSet)
Factory method that returns a "best fit" triple 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 beta smoothing constants.

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

getBestFitModel

public static TripleExponentialSmoothingModel getBestFitModel(DataSet dataSet,
                                                              double alphaTolerance,
                                                              double betaTolerance)
Factory method that returns a best fit triple 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 beta 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 beta - is expected to be very similar either way.

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

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

init

public void init(DataSet dataSet)
Used to initialize the time based model. This method must be called before any other method in the class. Since the time based model does not derive any equation for forecasting, this method uses the input DataSet to calculate forecast values for all values of the independent time variable within the initial data set.

Specified by:
init in interface ForecastingModel
Overrides:
init in class AbstractTimeBasedModel
Parameters:
dataSet - a data set of observations that can be used to initialize the forecasting parameters of the forecasting model.

forecast

protected double forecast(double time)
                   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:
time - 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.

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

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 triple 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.

calculateAccuracyIndicators

protected void calculateAccuracyIndicators(DataSet dataSet)
Since this version of triple 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:
getBeta(), getGamma()

getBeta

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

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

getGamma

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

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

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