lenskit.metrics.LogRankWeight#

class lenskit.metrics.LogRankWeight(*, base=2, offset=0)#

Bases: RankWeight

Logarithmic weighting for result ranks, as used in NDCG.

This is the ranking model typically used for DCG and NDCG.

Since \(\operatorname{lg} 1 = 0\), simply taking the log will result in division by 0 when weights are applied. The correction for this in the original NDCG paper [JarvelinKekalainen02] is to clip the ranks, so that both of the first two positions have discount \(\operatorname{lg} 2\). A different correction somtimes seen is to compute \(\operatorname{lg} (k+1)\). This discount supports both; the default is to clip, but if the offset option is set to a positive number, it is added to the ranks instead.

Parameters:
  • base (float) – The log base to use.

  • offset (int) – An offset to add to ranks before computing logs.

__init__(*, base=2, offset=0)#
Parameters:

Methods

__init__(*[, base, offset])

log_weight(ranks)

Compute the (natural) log of the discount for the specified ranks.

series_sum()

Get the sum of the infinite series of this discount function, if known.

weight(ranks)

Compute the discount for the specified ranks.

Attributes

base

offset

weight(ranks)#

Compute the discount for the specified ranks.

Ranks must start with 1.