public Dictionary <double, double> PredictAllRatings(PredictionMethod m, string sUID, string sIID)
        {
            SimilartyData <string> similarityData = null;

            switch (m)
            {
            case PredictionMethod.Pearson:
                similarityData = usr2usr[m];
                break;

            case PredictionMethod.Cosine:
                similarityData = usr2usr[m];
                break;

            case PredictionMethod.Random:
                break;

            case PredictionMethod.SVD:
                break;

            case PredictionMethod.Stereotypes:
                break;

            default:
                break;
            }
            if (similarityData == null)
            {
                throw new NotImplementedException();
            }

            IEnumerable <string> users = getUsers(sUID, sIID, similarityData).ToList();

            Dictionary <double, double> rankToSumSimilarity = new Dictionary <double, double>();

            foreach (var usr in users)
            {
                var rank = _db.GetRank(usr, sIID);
                if (!rankToSumSimilarity.ContainsKey(rank.Value))
                {
                    rankToSumSimilarity[rank.Value] = 0;
                }
                double sim = similarityData.GetSimilarity(sUID, usr);
                if (sim > 0)
                {
                    rankToSumSimilarity[rank.Value] += sim;
                }
            }

            return(rankToSumSimilarity);
        }
        private IEnumerable <string> getUsers(string sUID, string sIID, SimilartyData <string> similarityData)
        {
            IEnumerable <string> users;

            if (Mode == FilterMode.MaxUsers)
            {
                users = _db.GetRankersOfItem(sIID).Where(usr => usr != sUID).OrderByDescending(usr => similarityData.GetSimilarity(sUID, usr)).Take(MaxUsers);
            }
            else
            {
                users = _db.GetRankersOfItem(sIID).
                        Where(usr => usr != sUID &&
                              similarityData.GetSimilarity(sUID, usr) >= MinSimilarity).ToList();
            }
            return(users);
        }
        public double PredictRating(PredictionMethod m, string sUID, string sIID)
        {
            SimilartyData similarityData = null;

            switch (m)
            {
            case PredictionMethod.Pearson:
                similarityData = usr2usr[m];
                break;

            case PredictionMethod.Cosine:
                similarityData = usr2usr[m];
                break;

            case PredictionMethod.Random:
                return(GetRandomRank(sUID));

            case PredictionMethod.SVD:
                return(_svd.Predict(sUID, sIID));

            case PredictionMethod.Stereotypes:
                break;

            default:
                break;
            }
            if (similarityData == null)
            {
                throw new NotImplementedException();
            }
            IEnumerable <string> users = getUsers(sUID, sIID, similarityData).ToList();
            double mone = 0;

            foreach (var usr in users)
            {
                if (usr == sUID)
                {
                    continue;
                }
                double avg = _db.GetRanks(usr).Average();
                var    sim = similarityData.GetSimilarity(sUID, usr);
                if (sim > 0)
                {
                    mone += sim * (_db.GetRank(usr, sIID).Value - avg);
                }
            }

            double avgCurrent = 0;
            var    ranks      = _db.GetRanks(sUID).ToList();

            if (ranks.Count > 0)
            {
                avgCurrent = ranks.Average();
            }

            if (mone == 0)
            {
                return(avgCurrent);
            }

            double mechane = 0;

            foreach (var usr in users)
            {
                if (usr == sUID)
                {
                    continue;
                }
                var sim = similarityData.GetSimilarity(sUID, usr);
                if (sim > 0)
                {
                    mechane += sim;
                }
            }
            //mechne will be zero only if mone will be zero, and if move is zero
            //we already exit
            return(avgCurrent + mone / mechane);
        }