⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 simpleexponentialsmoothingmodel.java

📁 搞算法预测的可以来看。有移动平均法
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            case 1:                // Reduce maximums                // Can discard models 3 and 4                model[3] = null;                model[4] = null;                return findBestFit( dataSet, model[0], model[1], model[2],                                    alphaTolerance );            case 2:                // Can discard models 0 and 4                model[0] = null;                model[4] = null;                return findBestFit( dataSet, model[1], model[2], model[3],                                    alphaTolerance );                            case 3:                // Reduce minimums                // Can discard models 0 and 1                model[0] = null;                model[1] = null;                return findBestFit( dataSet, model[2], model[3], model[4],                                    alphaTolerance );            case 0:            case 4:                // We're done???                //  - these cases should not occur, unless the MSE for model[0]                //    and model[1], or model[3] and model[4] are equal                break;            }        // Release all but the best model constructed so far        for ( int m=0; m<5; m++ )            if ( m != bestModelIndex )                model[m] = null;                return model[bestModelIndex];    }    /**     * 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.     * @param 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.     */    public SimpleExponentialSmoothingModel( double alpha )    {        this(alpha,HUNTER);    }        /**     * Constructs a new exponential smoothing forecasting model, using the     * given name as the independent variable and the specified smoothing     * constant.     * @param independentVariable the name of the independent variable - or     * time variable - to use in this model.     * @param 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.     * @deprecated As of 0.4, replaced by {@link #SimpleExponentialSmoothingModel(double)}.     */    public SimpleExponentialSmoothingModel( String independentVariable,                                            double alpha )    {        this(independentVariable,alpha,HUNTER);    }        /**     * 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.     * @param alpha the smoothing constant to use for this exponential     * smoothing model. Must be a value in the range 0.0-1.0.     * @param approach determines which approach to use for the forecasting.     * This must be either {@link #HUNTER} - the default - or {@link #ROBERTS}.     * @throws IllegalArgumentException if the value of the smoothing constant     * is invalid - outside the range 0.0-1.0.     */    public SimpleExponentialSmoothingModel( double alpha,                                            int approach )    {        if ( alpha < 0.0 || alpha > 1.0 )            throw new IllegalArgumentException("SimpleExponentialSmoothingModel: Invalid smoothing constant, " + alpha + " - must be in the range 0.0-1.0.");                this.alpha = alpha;        this.approach = approach;    }        /**     * Constructs a new exponential smoothing forecasting model, using the     * given name as the independent variable and the specified smoothing     * constant.     * @param independentVariable the name of the independent variable - or     * time variable - to use in this model.     * @param alpha the smoothing constant to use for this exponential     * smoothing model. Must be a value in the range 0.0-1.0.     * @param approach determines which approach to use for the forecasting.     * This must be either {@link #HUNTER} - the default - or {@link #ROBERTS}.     * @throws IllegalArgumentException if the value of the smoothing constant     * is invalid - outside the range 0.0-1.0.     * @deprecated As of 0.4, replaced by {@link #SimpleExponentialSmoothingModel(double,int)}.     */    public SimpleExponentialSmoothingModel( String independentVariable,                                            double alpha,                                            int approach )    {        super(independentVariable);                if ( alpha < 0.0 || alpha > 1.0 )            throw new IllegalArgumentException("SimpleExponentialSmoothingModel: Invalid smoothing constant, " + alpha + " - must be in the range 0.0-1.0.");                this.alpha = alpha;        this.approach = approach;    }        /**     * 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.     * @param timeValue the value of the time variable for which a forecast     * value is required.     * @return 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.     */    protected double forecast( double timeValue )        throws IllegalArgumentException    {        // As a starting point, we set the first forecast value to be the        //  same as the first observed value        if ( timeValue-getMinimumTimeValue() < TOLERANCE )            return getObservedValue( timeValue );        double previousTime = timeValue - getTimeInterval();                double forecast;        try            {                if ( approach == ROBERTS )                    forecast                        = alpha*getObservedValue(timeValue)                        + (1.0-alpha)*getForecastValue(previousTime);                else // Default - Hunter's formula                    forecast                        = alpha*getObservedValue(previousTime)                        + (1.0-alpha)*getForecastValue(previousTime);            }        catch ( IllegalArgumentException iaex )            {                // For "future" forecasts, all we can do is use the forecast                //  from the last period                if ( timeValue > getMaximumTimeValue()-TOLERANCE )                    return getForecastValue( getMaximumTimeValue() );                throw iaex;            }                        return forecast;    }        /**     * 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.     * @return the minimum number of periods used in this model.     */    protected int getNumberOfPeriods()    {        return 1;    }        /**     * Returns the value of the smoothing constant, alpha, used in this model.     * @return the value of the smoothing constant, alpha.     */    public double getAlpha()    {        return alpha;    }    /**     * 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.     * @return a string representation of the type of forecasting model     *         implemented.     */    public String getForecastType()    {        return "simple exponential smoothing";    }        /**     * This should be overridden to provide a textual description of the     * current forecasting model including, where possible, any derived     * parameters used.     * @return a string representation of the current forecast model, and its     *         parameters.     */    public String toString()    {        return "Simple exponential smoothing model (using "            + (approach==ROBERTS?"Roberts":"Hunters")            + " formula), with a smoothing constant of "            + alpha + " and using an independent variable of "            + getIndependentVariable();    }}// Local Variables:// tab-width: 4// End:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -