blob: a0a1f62c8eec940e1cbc885c8a1265f670adeb80 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright (c) 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/extras/rail/rail_interaction_record.html">
<script>
'use strict';
tr.exportTo('tr.e.rail', function() {
function RAILScore(opt_irs) {
this.interactionRecords_ = [];
if (opt_irs)
this.interactionRecords_.push.apply(this.interactionRecords_, opt_irs);
};
RAILScore.prototype = {
get interactionRecords() {
return this.interactionRecords_;
},
get overallScore() {
// The design of this algorithm is discussed here: https://goo.gl/Cc0H1z
// TODO(benjhayden): Make doc public and remove below comment?
// Until the doc is made public, this is basically a weighted average,
// where the weights are tunable. The weights are recommended to be higher
// for lower scores, so that lower scores will bring down the overallScore
// more than higher scores bring it up. The optional fields provide an
// opportunity to customize the tunable parameters based on IR type,
// duration, etc. The continuity and monotonicity of the weighting
// function are also important characteristics. The weighting function is
// not composed of meaningful sub-expressions; it is a monolithic
// combination of the score and tunable parameters, and is open to
// reformulation.
// The weighting function is graphed here: https://goo.gl/1blsXW
if (!this.interactionRecords.length)
return undefined;
var numerator = 0;
var denominator = 0;
this.interactionRecords.forEach(function(ir) {
var score = ir.railScore;
var scale = ir.railScoreScale;
if (scale === undefined)
scale = 3;
var power = ir.railScorePower;
if (power === undefined)
power = 0.3;
var base = ir.railScoreBase;
if (base === undefined)
base = Math.exp(1);
var weight = Math.pow(base, -scale * Math.pow(score, power));
numerator += score * weight;
denominator += weight;
});
return numerator / denominator;
}
};
RAILScore.fromModel = function(model) {
var rirs = model.interaction_records.filter(function(ir) {
return ir instanceof tr.e.rail.RAILInteractionRecord;
});
if (rirs.length === 0)
return undefined;
return new RAILScore(rirs);
};
return {
RAILScore: RAILScore
};
});
</script>