Skip to content
Browse files

memoize repo cluster results

  • Loading branch information...
1 parent d05a5f6 commit 2b7a2d4332a510602ecf20e7917b55b62b66d4ff @danielsdeleo committed Aug 13, 2009
Showing with 6 additions and 7 deletions.
  1. +6 −7 benchmark/github_contest_helper.rb
View
13 benchmark/github_contest_helper.rb
@@ -9,6 +9,7 @@ def initialize(vector_type=nil)
p :initialize
@users_repos_cluster = Decider::Clustering::NearestNeighbors.new(vector_type) { |doc| doc.verbatim }
@repos_watchers_cluster = Decider::Clustering::NearestNeighbors.new(vector_type) { |doc| doc.verbatim }
+ @repos_similar_repos = {}
@results = nil
load_sample_set
load_test_set
@@ -43,7 +44,7 @@ def load_users_repos_into_cluster
p :load_users_repos_into_cluster
@users_repos.each do |user, repos|
# everyone who only watches rails is a fail.
- @users_repos_cluster.push(user, repos) unless repos.size > 3
+ @users_repos_cluster.push(user, repos) unless repos.size > 5
end
end
@@ -55,7 +56,7 @@ def generate_users_repos_tree
def load_repos_watchers_into_cluster
p :load_repos_watchers_into_cluster
@repos_watchers.each do |repo, watchers|
- @repos_watchers_cluster.push(repo, watchers) unless watchers.size > 3
+ @repos_watchers_cluster.push(repo, watchers) unless watchers.size > 5
end
end
@@ -100,15 +101,13 @@ def find_similar_repos(k=5)
unless @results
@results = each_test_user do |user_id, results|
this_users_repos_watchers = {}
- #p "collecting repo-watchers pairs for #{user_id}"
@users_repos[user_id].each do |repo|
this_users_repos_watchers[repo] = @repos_watchers[repo]
end
- #p :finding_recommendations
r = Recommendation.new(user_id, @users_repos)
- this_users_repos_watchers.each do |repo, watchers, swimming|
- k_nearest_repos = @repos_watchers_cluster.knn(k, watchers).map { |repo_doc| repo_doc.name}
- r.recommend_repos(k_nearest_repos)
+ this_users_repos_watchers.each do |repo, watchers|
+ @repos_similar_repos[repo] ||= @repos_watchers_cluster.knn(k, watchers).map { |repo_doc| repo_doc.name}
+ r.recommend_repos(@repos_similar_repos[repo])
end
results << r

0 comments on commit 2b7a2d4

Please sign in to comment.
Something went wrong with that request. Please try again.