Class SimpleExponentialSmoothingModel
- java.lang.Object
-
- net.sourceforge.openforecast.models.AbstractForecastingModel
-
- net.sourceforge.openforecast.models.AbstractTimeBasedModel
-
- 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 constructorand specifyROBERTSas the third argument.- Since:
- 0.4
- See Also:
- Engineering Statistics Handbook, 6.4.3.1 Simple Expnential Smoothing
-
-
Field Summary
Fields Modifier and Type Field and Description static intHUNTERUsed in thethree argument constructorto specify that Hunter's formula is to be used for calculating forecast values.static intROBERTSUsed in thethree argument constructorto specify that Robert's formula is to be used for calculating forecast values.
-
Constructor Summary
Constructors Constructor and Description 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(java.lang.String independentVariable, double alpha)Deprecated.As of 0.4, replaced bySimpleExponentialSmoothingModel(double).SimpleExponentialSmoothingModel(java.lang.String independentVariable, double alpha, int approach)Deprecated.As of 0.4, replaced bySimpleExponentialSmoothingModel(double,int).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description doublegetAlpha()Returns the value of the smoothing constant, alpha, used in this model.static SimpleExponentialSmoothingModelgetBestFitModel(DataSet dataSet)Factory method that returns a "best fit" simple exponential smoothing model for the given data set.static SimpleExponentialSmoothingModelgetBestFitModel(DataSet dataSet, double alphaTolerance)Factory method that returns a best fit simple exponential smoothing model for the given data set.java.lang.StringgetForecastType()Returns a one or two word name of this type of forecasting model.intgetNumberOfPredictors()Returns the number of predictors used by the underlying model.java.lang.StringtoString()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, getIndependentVariable, getMaximumTimeValue, getMinimumTimeValue, getTimeVariable, init
-
-
-
-
Field Detail
-
HUNTER
public static final int HUNTER
Used in thethree argument constructorto 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 thethree argument constructorto 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:
java.lang.IllegalArgumentException- if the value of the smoothing constant is invalid - outside the range 0.0-1.0.
-
SimpleExponentialSmoothingModel
public SimpleExponentialSmoothingModel(java.lang.String independentVariable, double alpha)Deprecated. As of 0.4, replaced bySimpleExponentialSmoothingModel(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:
java.lang.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 eitherHUNTER- the default - orROBERTS.- Throws:
java.lang.IllegalArgumentException- if the value of the smoothing constant is invalid - outside the range 0.0-1.0.
-
SimpleExponentialSmoothingModel
public SimpleExponentialSmoothingModel(java.lang.String independentVariable, double alpha, int approach)Deprecated. As of 0.4, replaced bySimpleExponentialSmoothingModel(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 eitherHUNTER- the default - orROBERTS.- Throws:
java.lang.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 overloadedgetBestFitModel(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 overloadedgetBestFitModel(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.
-
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 java.lang.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:
getForecastTypein interfaceForecastingModel- Overrides:
getForecastTypein classAbstractTimeBasedModel- Returns:
- a string representation of the type of forecasting model implemented.
-
toString
public java.lang.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:
toStringin interfaceForecastingModel- Overrides:
toStringin classAbstractTimeBasedModel- Returns:
- a string representation of the current forecast model, and its parameters.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG