-
Notifications
You must be signed in to change notification settings - Fork 103
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use *all* rated documents for ideal DCG computation. (#1242)
- Loading branch information
1 parent
2da6a30
commit 0e92b09
Showing
4 changed files
with
30 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class SyncCommunalScorerCode < ActiveRecord::Migration[8.0] | ||
def change | ||
Scorer.communal.each do |scorer| | ||
file_name = scorer.name.downcase + '.js' | ||
scorer.update( code: File.readlines("./db/scorers/#{file_name}",'\n').join('\n')) | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,33 @@ | ||
var k = 10 // @Rank | ||
var missing_rating = 0; // pessimistic assumption | ||
|
||
var ideal = topRatings(k) // could return less than k if less than k docs have ratings | ||
var scores = Array(k); | ||
for (var i = 0; i < k; i++) { | ||
if (!ideal[i]) { | ||
ideal[i] = missing_rating; | ||
const topK = 10 // @Rank | ||
const missing_rating = 0; | ||
const scores = Array(topK); | ||
const idealScores = [] | ||
eachDocWithRating(function(doc) { | ||
idealScores.push(doc.rating) | ||
}) | ||
idealScores.sort(function(a,b) { return b - a; }); | ||
for (var i = 0; i < topK; i++) { | ||
if (!idealScores[i]) { | ||
idealScores[i] = missing_rating; | ||
} | ||
if (hasDocRating(i)) { | ||
scores[i] = (docRating(i)); | ||
} else { | ||
scores[i] = missing_rating; | ||
} | ||
} | ||
|
||
function DCG(vals, k) { | ||
var dcg = 0; | ||
for (var i = 0; i < k; i++) { | ||
var d = Math.log2(i + 2); | ||
var n = Math.pow(2, vals[i]) - 1; | ||
dcg += d ? (n / d) : 0; | ||
let dcg = 0; | ||
for (var j = 0; j < k; j++) { | ||
const den = Math.log2(j + 2); | ||
const num = Math.pow(2, vals[j]) - 1; | ||
dcg += den ? (num / den) : 0; | ||
} | ||
return dcg; | ||
} | ||
|
||
function nDCG(vals, ideal, k) { | ||
var n = DCG(vals, k); | ||
var d = DCG(ideal, k); | ||
return d ? (n / d) : 0; | ||
const num = DCG(vals, k); | ||
const den = DCG(ideal, ideal.length); | ||
return den ? (num / den) : 0; | ||
} | ||
|
||
setScore(nDCG(scores, ideal, k)); | ||
|
||
setScore(nDCG(scores, idealScores, topK)); |