private static Dictionary <double, Dictionary <double, DeviationObject> > AddRatingUpdateDeviations(Dictionary <int, Dictionary <int, double> > data, Dictionary <double, Dictionary <double, DeviationObject> > deviationsDictionary, int userId)
        {
            var user = data[userId];

            var userRatedList = user.Keys.ToList();

            //Update deviations after a new rating has been added by a user
            foreach (var ratingId in userRatedList)
            {
                var deviation = Slope.GenerateDeviationObject(data, userId, ratingId);
                deviationsDictionary[userId][ratingId] = Slope.GenerateDeviationObject(data, userId, ratingId);
                deviationsDictionary[ratingId][userId] = new DeviationObject {
                    AmountOfRatings = deviation.AmountOfRatings, Deviation = deviation.Deviation * -1
                };
            }
            return(deviationsDictionary);
        }
        private static Dictionary <int, Dictionary <int, DeviationObject> > GenerateDeviationsDictionary(Dictionary <int, Dictionary <int, double> > data, int[] uniqueIds)
        {
            var deviations = new Dictionary <int, Dictionary <int, DeviationObject> >();

            //Loop over half the data and calulate the deviations
            for (int i = 0; i < uniqueIds.Length; i++)
            {
                //Add a new row
                deviations.Add(uniqueIds[i], new Dictionary <int, DeviationObject>());
                for (int j = i; j < uniqueIds.Length; j++)
                {
                    //Skip comparing the item to itself
                    if (i == j)
                    {
                        deviations[uniqueIds[i]].Add(uniqueIds[j], new DeviationObject());
                        continue;
                    }
                    //Add the deviation values at the correct index
                    deviations[uniqueIds[i]].Add(uniqueIds[j], Slope.GenerateDeviationObject(data, uniqueIds[i], uniqueIds[j]));
                }
            }

            //Loop over the other half and inverse the deviation values
            for (int a = 1; a < uniqueIds.Length; a++)
            {
                for (int b = 0; b < a; b++)
                {
                    if (a == b)
                    {
                        continue;
                    }
                    var deviationObject    = deviations[uniqueIds[b]][uniqueIds[a]];
                    var newDeviationObject = new DeviationObject()
                    {
                        AmountOfRatings = deviationObject.AmountOfRatings,
                        Deviation       = deviationObject.Deviation * -1
                    };
                    deviations[uniqueIds[a]].Add(uniqueIds[b], newDeviationObject);
                }
            }

            return(deviations);
        }