public static int LogBase2(long v) { return((int)PopCount.LogBase2(v)); }
public static string predict(int user) { string output = user + ":"; int num = 0; List<int> parents_choosen = new List<int>(); List<int> parents_parents_choosen = new List<int>(); List<int> predicted = new List<int>(); // follow parents foreach (int x in user_store[user].following) { if (repo_store[x].parent != -1 && !user_store[user].following.Contains(repo_store[x].parent) && !parents_choosen.Contains(repo_store[x].parent)) { num++; parents_choosen.Add(repo_store[x].parent); output += repo_store[x].parent; predicted.Add(repo_store[x].parent); if (num < 10) output += ","; if (num == 2) { parent_max++; break; } if (num == 10) { return output; } } } // follow parents of parents /* foreach (int x in parents_choosen) { if (repo_store[x].parent != -1 && !user_store[user].following.Contains(repo_store[x].parent) && !parents_parents_choosen.Contains(repo_store[x].parent)) { num++; parents_parents_choosen.Add(repo_store[x].parent); output += repo_store[x].parent; if (num < 10) output += ","; if (num == 10) { return output; } if (num == 8) { break; } } } */ // follow popular amongst authors other projects PopCount[] pops = new PopCount[repo_store.Length]; for (int p = 0; p < pops.Length; p++) { pops[p] = new PopCount(p, 0); } List<string> authors = new List<string>(); for (int z = 0; z < user_store[user].following.Count; z++) { authors.Add(repo_store[user_store[user].following[z]].author); } /* for (int f = 0; f < repo_store.Length; f++) { try { if (authors.Contains(repo_store[f].author)) { pops[f].pop = repo_store[f].followers.Count; } } catch (Exception) { //empty } } */ foreach (string a in authors) { List<Repo> r_list = (List<Repo>)author_set[a]; foreach (Repo rep in r_list) { pops[rep.id].pop = rep.followers.Count; } } Array.Sort(pops, delegate(PopCount r1, PopCount r2) { if (r1 == null && r2 == null) return 0; if (r1 == null) return 1; if (r2 == null) return -1; return r2.pop.CompareTo(r1.pop); }); foreach (PopCount popp in pops) { if (!user_store[user].following.Contains(popp.repo) && !predicted.Contains(popp.repo)) { num++; output += popp.repo; if (repo_store[popp.repo].followers.Count < 5) { low_follows++; } predicted.Add(popp.repo); if (num < 10) output += ","; if (num == 7) break; if (num == 10) return output; } } // follow popular amongst followers of followed ??? ! pops = new PopCount[repo_store.Length]; for (int q = 0; q < pops.Length; q++) { pops[q] = new PopCount(q, 0); } for (int w = 0; w < user_store[user].following.Count; w++) { for (int x = 0; x < repo_store[user_store[user].following[w]].followers.Count; x++) { Person peep = user_store[ repo_store[user_store[user].following[w]].followers[x]]; for (int y = 0; y < peep.following.Count; y++) { pops[peep.following[y]].pop++; } } } Array.Sort(pops, delegate(PopCount r1, PopCount r2) { if (r1 == null && r2 == null) return 0; if (r1 == null) return 1; if (r2 == null) return -1; return r2.pop.CompareTo(r1.pop); }); foreach (PopCount popp in pops) { if (!user_store[user].following.Contains(popp.repo) && !predicted.Contains(popp.repo)) { num++; output += popp.repo; predicted.Add(popp.repo); if (num < 10) output += ","; if (num == 10) return output; } } // follow popular foreach (Repo r in popular_repos) { if (!user_store[user].following.Contains(r.id) && !predicted.Contains(r.id)) { num++; output += r.id; if (num < 10) output += ","; if (num == 10) break; } } return output; }