Skip to content

Instantly share code, notes, and snippets.

@morr
Created May 2, 2013 20:09
Show Gist options
  • Select an option

  • Save morr/5505009 to your computer and use it in GitHub Desktop.

Select an option

Save morr/5505009 to your computer and use it in GitHub Desktop.
# encoding: utf-8
class Recommendations::Metrics::Svd < Recommendations::Metrics::MetricBase
def initialize(klass, svd)
@klass = klass
@svd = svd
end
def compare(user_id, user_rates, sampler_id, sampler_rates)
(@svd.user_ids.include?(sampler_id) ? @svd.rank(user_rates)[sampler_id] : nil) || 0
end
def cache_key(*args)
"#{super(*args)}_#{@svd.id}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment