1

Create compatibility feature

This commit is contained in:
Alex Yatskov 2015-03-20 20:15:47 +09:00
parent 850274efdf
commit 1402d60100

View File

@ -193,6 +193,9 @@ function computeRecordGeo(records, context) {
} }
function computeRecordPopularity(records, context, callback) { function computeRecordPopularity(records, context, callback) {
var scoreMin = 0;
var scoreMax = 0;
async.each( async.each(
records, records,
function(record, callback) { function(record, callback) {
@ -213,12 +216,18 @@ function computeRecordPopularity(records, context, callback) {
}); });
var groupScore = innerProduct(context.profile, reviewFeatures); var groupScore = innerProduct(context.profile, reviewFeatures);
scoreMin = Math.min(scoreMin, groupScore);
scoreMax = Math.max(scoreMax, groupScore);
callback(err, groupScore); callback(err, groupScore);
} }
); );
}, },
function(err, groupScores) { function(err, groupScores) {
record.groupScores = groupScores; var scoreSum = _.reduce(groupScores, function(a, b) { return a + b; });
var scoreAvg = scoreSum / groupScores.length;
record.features.compatibility = (scoreAvg - scoreMin) / (scoreMax - scoreMin);
callback(err); callback(err);
} }
); );