public Dictionary <ProductClass, PredictionClass> Predict(Dictionary <ProductClass, SortedDictionary <DateTime, int> > productsMonthsSummary) { Dictionary <ProductClass, PredictionClass> WeightedAverageResult = new Dictionary <ProductClass, PredictionClass>(); foreach (KeyValuePair <ProductClass, SortedDictionary <DateTime, int> > productMonthsSummary in productsMonthsSummary) { List <KeyValuePair <DateTime, int> > productMonthsSummaryList = productMonthsSummary.Value.ToList(); PredictionClass predictuinClass = calculateWeightedAverage(productMonthsSummaryList); WeightedAverageResult.Add(productMonthsSummary.Key, predictuinClass); } return(WeightedAverageResult); }
public Dictionary <ProductClass, PredictionClass> Predict(Dictionary <ProductClass, SortedDictionary <DateTime, int> > productsMonthsSummary) { Dictionary <ProductClass, PredictionClass> predictionResult = new Dictionary <ProductClass, PredictionClass>(); foreach (KeyValuePair <ProductClass, SortedDictionary <DateTime, int> > productMonthsSummary in productsMonthsSummary) { List <KeyValuePair <DateTime, int> > productMonthsSummaryList = productMonthsSummary.Value.ToList(); PredictionClass predictuinClass = calculateExponentialSmooting(productMonthsSummaryList); predictionResult.Add(productMonthsSummary.Key, predictuinClass); } return(predictionResult); }
// private int calculateSimpleAverag(SortedDictionary<DateTime, int> monthsSummary) private PredictionClass calculateSimpleAverage(List <KeyValuePair <DateTime, int> > monthsSummary) { if (monthsSummary.Count < NumberOfMonths) { return(null); } PredictionClass predictionClass = new PredictionClass(); for (int i = NumberOfMonths; i <= monthsSummary.Count; i++) { double sum = 0; for (int j = i - NumberOfMonths; j < i; j++) { sum = sum + monthsSummary[j].Value; } predictionClass.PredictionResults.Add(monthsSummary[i - 1].Key.AddMonths(1), (double)sum / NumberOfMonths); } return(predictionClass); }
private PredictionClass calculateExponentialSmooting(List <KeyValuePair <DateTime, int> > monthsSummary) { if (monthsSummary.Count < 1) { return(null); } PredictionClass predictionClass = new PredictionClass(); predictionClass.PredictionResults.Add(monthsSummary.First().Key, monthsSummary.First().Value); for (int i = 0; i < monthsSummary.Count; i++) { int observation = monthsSummary[i].Value; double previousPrediction; bool test = predictionClass.PredictionResults.TryGetValue(monthsSummary[i].Key, out previousPrediction); predictionClass.PredictionResults.Add(monthsSummary[i].Key.AddMonths(1), observation * SmootingFactor + previousPrediction * (1 - SmootingFactor)); } return(predictionClass); }
private PredictionClass calculateWeightedAverage(List <KeyValuePair <DateTime, int> > monthsSummary) { if (monthsSummary.Count < WeightedFactor.Count) { return(null); } PredictionClass predictionClass = new PredictionClass(); for (int i = WeightedFactor.Count; i <= monthsSummary.Count; i++) { double sum = 0; for (int j = 0; j < WeightedFactor.Count; j++) { sum = sum + monthsSummary[i - j - 1].Value * WeightedFactor[j]; } predictionClass.PredictionResults.Add(monthsSummary[i - 1].Key.AddMonths(1), (double)sum); } return(predictionClass); }