public class WeightedTau extends CorrelationIndex
Instances of this class are immutable. At creation time you can specify a
weigher that turns indices into weights, and
whether to combine weights additively or multiplicatively.
Ready-made weighers include
HYPERBOLIC_WEIGHER, which is the weigher of choice. Alternatives include
Additional methods inherited from
CorrelationIndex make it possible to
compute directly the weighted τ bewteen two files, to bound the number of significant digits, or
to reverse the standard association between scores and ranks (by default,
a larger score corresponds to a higher rank, i.e., to a smaller rank index; the largest score gets
The weighted τ is defined as follows: consider a rank function ρ (returning natural numbers or ∞) that provides a ground truth—it tells us which elements are more or less important. Consider also a weight function w(−, −) associating with each pair of ranks a nonnegative real number. We define the rank-weighted τ by
The weight function can be specified by giving a weigher f (e.g.,
HYPERBOLIC_WEIGHER) and a combination
strategy, which can be additive or multiplicative.
The weight of the exchange between i and j
is then f(i) ● f(j), where ● is the chosen combinator.
Now, consider the rank function ρr, s induced by the lexicographical order by r and s. We define
In particular, the (additive) hyperbolic τ is defined by the weight function h(i) = 1 / (i + 1) combined additively:
The methods inherited from
CorrelationIndex compute the formula above using the provided weigher
and combination method. A ready-made instance
HYPERBOLIC can be used to compute the additive hyperbolic τ. An
ad hoc method can instead compute τρ,w.
A main method is provided for command-line usage.
Nested Class Summary
Nested Classes Modifier and Type Class Description
Fields Modifier and Type Field Description
static WeightedTauA singleton instance of the symmetric hyperbolic additive τ.
static Int2DoubleFunctionA hyperbolic weigher (the default one).
static Int2DoubleFunctionA logarithmic weigher.
static Int2DoubleFunctionA quadratic weigher.
static Int2DoubleFunctionA constant zero weigher.
Constructors Constructor Description
()Create an additive hyperbolic τ.
Int2DoubleFunction weigher)(Create an additive weighted τ using the specified weigher.
Int2DoubleFunction weigher, boolean multiplicative)(Create an additive or multiplicative weighted τ using the specified weigher and combination strategy.
Modifier and Type Method Description
(double v0, double v1)Computes the symmetrized weighted τ between two score vectors.
(double v0, double v1, int rank)Computes the weighted τ between two score vectors, given a reference rank.
Methods inherited from class it.unimi.dsi.law.stat.CorrelationIndex
compute, compute, compute, compute, computeDoubles, computeDoubles, computeDoubles, computeDoubles, computeFloats, computeFloats, computeFloats, computeFloats, computeInts, computeInts, computeLongs, computeLongs, loadAsDoubles, parseInputTypes
HYPERBOLIC_WEIGHERpublic static final Int2DoubleFunction HYPERBOLIC_WEIGHERA hyperbolic weigher (the default one). Rank x has weight 1 / (x + 1).
QUADRATIC_WEIGHERpublic static final Int2DoubleFunction QUADRATIC_WEIGHERA quadratic weigher. Rank x has weight 1 / (x + 1)2.
LOGARITHMIC_WEIGHERpublic static final Int2DoubleFunction LOGARITHMIC_WEIGHERA logarithmic weigher. Rank x has weight 1 / ln(x + e).
ZERO_WEIGHERpublic static final Int2DoubleFunction ZERO_WEIGHERA constant zero weigher.
HYPERBOLICpublic static final WeightedTau HYPERBOLICA singleton instance of the symmetric hyperbolic additive τ.
WeightedTaupublic WeightedTau()Create an additive hyperbolic τ.
WeightedTaupublic WeightedTau(Int2DoubleFunction weigher)Create an additive weighted τ using the specified weigher.
weigher- a weigher.
WeightedTaupublic WeightedTau(Int2DoubleFunction weigher, boolean multiplicative)Create an additive or multiplicative weighted τ using the specified weigher and combination strategy.
weigher- a weigher.
multiplicative- if true, weights are combined multiplicatively, rather than additively.
computepublic double compute(double v0, double v1)Computes the symmetrized weighted τ between two score vectors.
computepublic double compute(double v0, double v1, int rank)Computes the weighted τ between two score vectors, given a reference rank.
Note that this method must be called with some care. More precisely, the two arguments should be built on-the-fly in the method call, and not stored in variables, as the first argument array will be
null'd during the execution of this method to free some memory: if the array is referenced elsewhere the garbage collector will not be able to collect it.
v0- the first score vector.
v1- the second score vector.
rank- the “ground truth” ranking used to weight exchanges, or
nullto use the ranking induced lexicographically by
v0as ground truth.
- the weighted τ.