/// <summary> /// Vullen kolommen van Forecasting volgens de formules /// </summary> /// <param name="data">Lijst van Maand waarbij de forecasting data wordt opgeslagen</param> private void ImproveSmoothingFactor(Dictionary <int, Forecasting> data) { var formulas = new SmoothingFormulas(); FactorsVariables newFactorsVariables = new FactorsVariables(); newFactorsVariables.alpha = alpha; newFactorsVariables.delta = beta; newFactorsVariables.gamma = gamma; SmoothingVariables newSmoothingVariables = new SmoothingVariables(); int key = -11; foreach (var item in data) { if (item.Key == 1) { //magic sequence item.Value.OneStepForecast = formulas.OneStepErrorCalc(data[0].Level, data[0].Trend, data[key].SeasonalAdjustment); item.Value.ForecastError = formulas.ForecastErrorCalc(item.Value.ActualDemand, item.Value.OneStepForecast); item.Value.SquaredError = formulas.SquardErrorCalc(item.Value.ForecastError);// debug newSmoothingVariables.forecastError = item.Value.ForecastError; newSmoothingVariables.oneStepForecastError = item.Value.OneStepForecast; newSmoothingVariables.xT = data[item.Key - 1].ActualDemand; newSmoothingVariables.lT = data[item.Key - 1].Level; newSmoothingVariables.sT = data[key].SeasonalAdjustment; newSmoothingVariables.tT = data[item.Key - 1].Trend; //TODO make formulas simple newSmoothingVariables.lT = item.Value.Level = formulas.SmoothLevelCalc(newSmoothingVariables, newFactorsVariables); newSmoothingVariables.tT = item.Value.Trend = formulas.SmoothTrendCalc(newSmoothingVariables, newFactorsVariables); newSmoothingVariables.sT = item.Value.SeasonalAdjustment = formulas.SmoothSeasonalCalc(newSmoothingVariables, newFactorsVariables); key++; } else if (item.Key > 1 && item.Key <= 36) { //magic all //Paint item.Value.OneStepForecast = formulas.OneStepErrorCalc(data[item.Key - 1].Level, data[item.Key - 1].Trend, data[key].SeasonalAdjustment); item.Value.ForecastError = formulas.ForecastErrorCalc(item.Value.ActualDemand, item.Value.OneStepForecast); item.Value.SquaredError = formulas.SquardErrorCalc(item.Value.ForecastError); newSmoothingVariables.forecastError = item.Value.ForecastError; newSmoothingVariables.oneStepForecastError = item.Value.OneStepForecast; newSmoothingVariables.xT = data[item.Key - 1].ActualDemand; newSmoothingVariables.lT = data[item.Key - 1].Level; newSmoothingVariables.sT = data[key].SeasonalAdjustment; newSmoothingVariables.tT = data[item.Key - 1].Trend; //TODO make formulas simple newSmoothingVariables.lT = item.Value.Level = formulas.SmoothLevelCalc(newSmoothingVariables, newFactorsVariables); newSmoothingVariables.tT = item.Value.Trend = formulas.SmoothTrendCalc(newSmoothingVariables, newFactorsVariables); newSmoothingVariables.sT = item.Value.SeasonalAdjustment = formulas.SmoothSeasonalCalc(newSmoothingVariables, newFactorsVariables); key++; } } }
public float SmoothSeasonalCalc(SmoothingVariables seasonalVariables, FactorsVariables factorsVariables) { // Ct = sT + delta * (1 - alpha ) * ForecastError /(lT-1 + tT-1) // seasonalVariables.oneStepForecastError = OneStepErrorCalc(seasonalVariables.lT,seasonalVariables.tT,seasonalVariables.sT); // seasonalVariables.forecastError = ForecastErrorCalc(seasonalVariables.xT, seasonalVariables.oneStepForecastError); float sT = seasonalVariables.sT + factorsVariables.delta * (1 - factorsVariables.alpha) * seasonalVariables.forecastError / (seasonalVariables.lT + seasonalVariables.tT); return(sT); }
public float SmoothTrendCalc(SmoothingVariables trendVariables, FactorsVariables factorsVariables) { // Bt = bt-1 + gemma * alpha * (forecastError/ct) //trendVariables.oneStepForecastError = OneStepErrorCalc(trendVariables.lT, trendVariables.tT, trendVariables.sT); //trendVariables.forecastError = ForecastErrorCalc(trendVariables.xT, trendVariables.oneStepForecastError); float tT = trendVariables.tT + factorsVariables.gamma * factorsVariables.alpha * (trendVariables.forecastError / trendVariables.sT); return(tT); }
public float SmoothLevelCalc(SmoothingVariables levelVariables, FactorsVariables factorsVariables) { //lT-1 + Bt-1 + alpha * (forecastError/Ct) //levelVariables.oneStepForecastError = OneStepErrorCalc(levelVariables.lT, levelVariables.tT, levelVariables.sT); //levelVariables.forecastError = ForecastErrorCalc(levelVariables.xT, levelVariables.oneStepForecastError); float lT = levelVariables.lT + levelVariables.tT + factorsVariables.alpha * (levelVariables.forecastError / levelVariables.sT); return(lT); }