Skip to content

Instantly share code, notes, and snippets.

@MollsReis
Last active January 17, 2019 18:13
Show Gist options
  • Save MollsReis/164973f672995191f756e3dbb629b22b to your computer and use it in GitHub Desktop.
Save MollsReis/164973f672995191f756e3dbb629b22b to your computer and use it in GitHub Desktop.
Rank Biased Overlap (Base) implementation (javascript)
// http://blog.mobile.codalism.com/research/papers/wmz10_tois.pdf
// used for a list of 50 items
const P_VALUE = 0.8;
export const intersection = (a, b) => a.filter(x => b.indexOf(x) > -1);
export const overlap = (a, b) => intersection(a, b).length;
export const agreement = (a, b) => overlap(a, b) / a.length;
// used for comparing two indefinite ordinal lists
// RBO(base) = (1 - p) * sum{ p^(d-1) * agreement(a[0..d], b[0..d]) }
export const rankBiasedOverlap = (a, b) => {
const sum = a.reduce((memo, _v, d) => {
const p = P_VALUE ** d;
const agg = agreement(a.slice(0, d + 1), b.slice(0, d + 1));
return memo + (p * agg);
}, 0);
return parseFloat(((1 - P_VALUE) * sum).toFixed(4));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment