public TResult RecommendItem <TResult>(string itemId, IResultBuilderFactory <TResult> resultBuilderFactory)
        {
            if (itemId == null)
            {
                throw new ArgumentNullException(nameof(itemId));
            }

            if (!this.itemMap.ContainsKey(itemId))
            {
                return(resultBuilderFactory.CreateEmpty());
            }

            var yi = this.itemFactors.Row(this.itemMap[itemId]);
            var yj = Vector <double> .Build.Dense(this.factors);

            var resultBuilder = resultBuilderFactory.CreateBuilder(maximumCapacity: this.itemMap.Count);

            foreach (var item in this.itemMap)
            {
                var j = item.Value;

                this.itemFactors.Row(j, yj);

                resultBuilder.Append(item.Key, yi.DotProduct(yj) / this.ItemNorms[j]);
            }

            return(resultBuilder.ToResult());
        }
        public TResult RecommendUser <TResult>(string userId, IResultBuilderFactory <TResult> resultBuilderFactory)
        {
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (!this.userMap.ContainsKey(userId))
            {
                return(resultBuilderFactory.CreateEmpty());
            }

            var xu   = this.userFactors.Row(this.userMap[userId]);
            var user = new UserFeatures(xu);

            return(this.RecommendUser(user, resultBuilderFactory));
        }
        public TResult RankUsers <TResult>(string userId, List <KeyValuePair <string, UserFeatures> > users, IResultBuilderFactory <TResult> resultBuilderFactory)
        {
            if (userId == null)
            {
                throw new ArgumentNullException(nameof(userId));
            }

            if (users == null)
            {
                throw new ArgumentNullException(nameof(users));
            }

            if (!this.userMap.ContainsKey(userId))
            {
                return(resultBuilderFactory.CreateEmpty());
            }

            var xu   = this.userFactors.Row(this.userMap[userId]);
            var user = new UserFeatures(xu);

            return(this.RankUsers(user, users, resultBuilderFactory));
        }