@Test public void testHoltWintersSmoothing() { logger.info("holtWintersSmoothing"); FlatDataList flatDataList = generateFlatDataList(); int season_length = 3; double alpha = 0.2; double beta = 0.01; double gamma = 0.01; double dev_gamma = 0.1; double expResult = 30.631118229653282; double result = Smoothing.holtWintersSmoothing(flatDataList, season_length, alpha, beta, gamma, dev_gamma); assertEquals(expResult, result, Constants.DOUBLE_ACCURACY_HIGH); }
public static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma) { int n = flatDataList.size(); double trend1 = 0.0; for(int i = 0; i < season_length; ++i) { trend1 += flatDataList.getDouble(i); } trend1 /= season_length; double trend2 = 0.0; for(int i = season_length; i < 2*season_length; ++i) { trend2 += flatDataList.getDouble(i); } trend2 /= season_length; double initial_trend = (trend2 - trend1) / season_length; double initial_level = flatDataList.getDouble(0); double[] index = new double[n]; for(int i = 0; i<n; ++i) { double val = flatDataList.getDouble(i); index[i] = val / (initial_level + (i + 1.0) * initial_trend); } double[] season = new double[n+season_length]; double sum=0.0; for(int i = 0; i < season_length; ++i) { season[i] = (index[i] + index[i+season_length]) / 2; sum+=season[i]; } double season_factor = season_length / sum; for(int i = 0; i < season_length; ++i) { season[i] *= season_factor; } double alpha_level = initial_level; double beta_trend = initial_trend; int i = 0; for(; i < n; ++i) { double value = flatDataList.getDouble(i); double temp_level = alpha_level; double temp_trend = beta_trend; alpha_level = alpha * value / season[i] + (1.0 - alpha) * (temp_level + temp_trend); beta_trend = beta * (alpha_level - temp_level) + ( 1.0 - beta ) * temp_trend; season[i + season_length] = gamma * value / alpha_level + (1.0 - gamma) * season[i]; } double holtWinterTplus1=alpha_level + beta_trend * season[i + 1]; return holtWinterTplus1; }
Smoothing { public static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma) { int n = flatDataList.size(); double trend1 = 0.0; for(int i = 0; i < season_length; ++i) { trend1 += flatDataList.getDouble(i); } trend1 /= season_length; double trend2 = 0.0; for(int i = season_length; i < 2*season_length; ++i) { trend2 += flatDataList.getDouble(i); } trend2 /= season_length; double initial_trend = (trend2 - trend1) / season_length; double initial_level = flatDataList.getDouble(0); double[] index = new double[n]; for(int i = 0; i<n; ++i) { double val = flatDataList.getDouble(i); index[i] = val / (initial_level + (i + 1.0) * initial_trend); } double[] season = new double[n+season_length]; double sum=0.0; for(int i = 0; i < season_length; ++i) { season[i] = (index[i] + index[i+season_length]) / 2; sum+=season[i]; } double season_factor = season_length / sum; for(int i = 0; i < season_length; ++i) { season[i] *= season_factor; } double alpha_level = initial_level; double beta_trend = initial_trend; int i = 0; for(; i < n; ++i) { double value = flatDataList.getDouble(i); double temp_level = alpha_level; double temp_trend = beta_trend; alpha_level = alpha * value / season[i] + (1.0 - alpha) * (temp_level + temp_trend); beta_trend = beta * (alpha_level - temp_level) + ( 1.0 - beta ) * temp_trend; season[i + season_length] = gamma * value / alpha_level + (1.0 - gamma) * season[i]; } double holtWinterTplus1=alpha_level + beta_trend * season[i + 1]; return holtWinterTplus1; } }
Smoothing { public static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma) { int n = flatDataList.size(); double trend1 = 0.0; for(int i = 0; i < season_length; ++i) { trend1 += flatDataList.getDouble(i); } trend1 /= season_length; double trend2 = 0.0; for(int i = season_length; i < 2*season_length; ++i) { trend2 += flatDataList.getDouble(i); } trend2 /= season_length; double initial_trend = (trend2 - trend1) / season_length; double initial_level = flatDataList.getDouble(0); double[] index = new double[n]; for(int i = 0; i<n; ++i) { double val = flatDataList.getDouble(i); index[i] = val / (initial_level + (i + 1.0) * initial_trend); } double[] season = new double[n+season_length]; double sum=0.0; for(int i = 0; i < season_length; ++i) { season[i] = (index[i] + index[i+season_length]) / 2; sum+=season[i]; } double season_factor = season_length / sum; for(int i = 0; i < season_length; ++i) { season[i] *= season_factor; } double alpha_level = initial_level; double beta_trend = initial_trend; int i = 0; for(; i < n; ++i) { double value = flatDataList.getDouble(i); double temp_level = alpha_level; double temp_trend = beta_trend; alpha_level = alpha * value / season[i] + (1.0 - alpha) * (temp_level + temp_trend); beta_trend = beta * (alpha_level - temp_level) + ( 1.0 - beta ) * temp_trend; season[i + season_length] = gamma * value / alpha_level + (1.0 - gamma) * season[i]; } double holtWinterTplus1=alpha_level + beta_trend * season[i + 1]; return holtWinterTplus1; }  }
Smoothing { public static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma) { int n = flatDataList.size(); double trend1 = 0.0; for(int i = 0; i < season_length; ++i) { trend1 += flatDataList.getDouble(i); } trend1 /= season_length; double trend2 = 0.0; for(int i = season_length; i < 2*season_length; ++i) { trend2 += flatDataList.getDouble(i); } trend2 /= season_length; double initial_trend = (trend2 - trend1) / season_length; double initial_level = flatDataList.getDouble(0); double[] index = new double[n]; for(int i = 0; i<n; ++i) { double val = flatDataList.getDouble(i); index[i] = val / (initial_level + (i + 1.0) * initial_trend); } double[] season = new double[n+season_length]; double sum=0.0; for(int i = 0; i < season_length; ++i) { season[i] = (index[i] + index[i+season_length]) / 2; sum+=season[i]; } double season_factor = season_length / sum; for(int i = 0; i < season_length; ++i) { season[i] *= season_factor; } double alpha_level = initial_level; double beta_trend = initial_trend; int i = 0; for(; i < n; ++i) { double value = flatDataList.getDouble(i); double temp_level = alpha_level; double temp_trend = beta_trend; alpha_level = alpha * value / season[i] + (1.0 - alpha) * (temp_level + temp_trend); beta_trend = beta * (alpha_level - temp_level) + ( 1.0 - beta ) * temp_trend; season[i + season_length] = gamma * value / alpha_level + (1.0 - gamma) * season[i]; } double holtWinterTplus1=alpha_level + beta_trend * season[i + 1]; return holtWinterTplus1; }  static double simpleMovingAverage(FlatDataList flatDataList, int N); static double simpleMovingAverageQuick(double Yt, double YtminusN, double Ft, int N); static double weightedMovingAverage(FlatDataList flatDataList, int N); static double simpleExponentialSmoothing(FlatDataList flatDataList, double a); static double simpleExponentialSmoothingQuick(double Ytminus1, double Stminus1, double a); static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma); }
Smoothing { public static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma) { int n = flatDataList.size(); double trend1 = 0.0; for(int i = 0; i < season_length; ++i) { trend1 += flatDataList.getDouble(i); } trend1 /= season_length; double trend2 = 0.0; for(int i = season_length; i < 2*season_length; ++i) { trend2 += flatDataList.getDouble(i); } trend2 /= season_length; double initial_trend = (trend2 - trend1) / season_length; double initial_level = flatDataList.getDouble(0); double[] index = new double[n]; for(int i = 0; i<n; ++i) { double val = flatDataList.getDouble(i); index[i] = val / (initial_level + (i + 1.0) * initial_trend); } double[] season = new double[n+season_length]; double sum=0.0; for(int i = 0; i < season_length; ++i) { season[i] = (index[i] + index[i+season_length]) / 2; sum+=season[i]; } double season_factor = season_length / sum; for(int i = 0; i < season_length; ++i) { season[i] *= season_factor; } double alpha_level = initial_level; double beta_trend = initial_trend; int i = 0; for(; i < n; ++i) { double value = flatDataList.getDouble(i); double temp_level = alpha_level; double temp_trend = beta_trend; alpha_level = alpha * value / season[i] + (1.0 - alpha) * (temp_level + temp_trend); beta_trend = beta * (alpha_level - temp_level) + ( 1.0 - beta ) * temp_trend; season[i + season_length] = gamma * value / alpha_level + (1.0 - gamma) * season[i]; } double holtWinterTplus1=alpha_level + beta_trend * season[i + 1]; return holtWinterTplus1; }  static double simpleMovingAverage(FlatDataList flatDataList, int N); static double simpleMovingAverageQuick(double Yt, double YtminusN, double Ft, int N); static double weightedMovingAverage(FlatDataList flatDataList, int N); static double simpleExponentialSmoothing(FlatDataList flatDataList, double a); static double simpleExponentialSmoothingQuick(double Ytminus1, double Stminus1, double a); static double holtWintersSmoothing(FlatDataList flatDataList, int season_length, double alpha, double beta, double gamma, double dev_gamma);  }