コード例 #1
0
        /// <summary>
        /// Aan de hand van de ingevulde kolommen van ImproveSmoothingFactor de prediction berekenen.
        /// </summary>
        /// <param name="data">Lijst van Maand waarbij de forecasting data wordt opgeslagen</param>
        private void AddOptimizePrediction(Dictionary <int, Forecasting> data)
        {
            var preditionValue = new PredictionVariables();
            var predictionCalc = new SmoothingFormulas();
            var factorValues   = new FactorsVariables();

            factorValues.alpha = bestAlpha;
            factorValues.delta = bestBeta;
            factorValues.gamma = bestGamma;
            foreach (var item in data)
            {
                int timeValue = item.Key;

                if (timeValue == 36)
                {
                    preditionValue.tLock  = item.Key;
                    preditionValue.tTLock = item.Value.Trend;
                    preditionValue.lTLock = item.Value.Level;
                }
                else if (timeValue > 36)
                {
                    preditionValue.t  = timeValue;
                    preditionValue.sT = data[int.Parse(timeValue.ToString()) - 12].SeasonalAdjustment;
                    Console.WriteLine("Month: " + timeValue + ", " + "Predicted Demand Value: " + predictionCalc.Prediction(preditionValue, factorValues));
                    data[int.Parse(timeValue.ToString())].ActualDemand = predictionCalc.Prediction(preditionValue, factorValues);
                }
            }
        }
コード例 #2
0
        public float Prediction(PredictionVariables predictionVariables, FactorsVariables factorsVariables)
        {
            //(lT - 1 + (t.current - t - 1) * Tt - 1) * S(vorige 12 maanden);
            //---->($LevelsmoothingBekend + (PredictionT - $lastbekendeTijd) * $LastbekendeTrend) *-12Seasonal

            float prediction = (predictionVariables.lTLock + (predictionVariables.t - predictionVariables.tLock) * predictionVariables.tTLock) * predictionVariables.sT;

            return(prediction);
        }
コード例 #3
0
        /// <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++;
                }
            }
        }
コード例 #4
0
        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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }