public SimilarUser[] GetSimilarUsers(User u, int count) { BestKeeper <SimilarUser> best = new BestKeeper <SimilarUser>(count, (s1, s2) => Math.Sign(s2.Similarity - s1.Similarity)); //BestKeeper<SimilarUser> worst = new BestKeeper<SimilarUser>( count, // (s1,s2) => Math.Sign( s1.Similarity - s2.Similarity ) ); foreach (var other in Users) { if (other == u) { continue; } SimilarUser sU = new SimilarUser(other, SimilarityPearson(u, other)); best.Add(sU); } return(best.ToArray()); }
public IReadOnlyList <SimilarUser> GetSimilarUsers( User u, int nbSimilarUser, bool onlyPositiveUserSimilarity) { var best = onlyPositiveUserSimilarity ? new BestKeeper <SimilarUser>(nbSimilarUser, (s1, s2) => Math.Sign(s2.Similarity - s1.Similarity)) : new BestKeeper <SimilarUser>(nbSimilarUser, (s1, s2) => Math.Sign(Math.Abs(s2.Similarity) - Math.Abs(s1.Similarity))); foreach (var other in Users) { if (other == u) { continue; } SimilarUser sU = new SimilarUser(other, SimilarityPearson(u, other)); best.Add(sU); } return(best); }