lib/disco/recommender.rb in disco-0.1.3 vs lib/disco/recommender.rb in disco-0.2.0

- old
+ new

@@ -137,11 +137,11 @@ def item_norms @item_norms ||= norms(@item_factors) end def norms(factors) - norms = Numo::DFloat::Math.sqrt((factors * factors).sum(axis: 1)) + norms = Numo::SFloat::Math.sqrt((factors * factors).sum(axis: 1)) norms[norms.eq(0)] = 1e-10 # no zeros norms end def similar(id, map, factors, norms, count, index) @@ -169,11 +169,10 @@ max_score = predictions.delete_at(i)[:score] predictions.sort_by! { |pred| -pred[:score] } # already sorted by id predictions = predictions.first(count) if count # divide by max score to get cosine similarity # only need to do for returned records - # could alternatively do cosine distance = 1 - cosine similarity - # predictions.each { |pred| pred[:score] /= max_score } + predictions.each { |pred| pred[:score] /= max_score } predictions end else [] end