lenskit.metrics.ranking.LogRBP#
- class lenskit.metrics.ranking.LogRBP(n=None, *, k=None, patience=0.85)#
Bases:
lenskit.metrics.ranking._base.RankingMetricBaseEvaluate recommendations with the natural logarithm of rank-biased precision, aggregated as \(\log(\overline{\operatorname{RBP}})\).
This metric measures the same quantity as
RBP, but carries each list’s score in log space so that the summary can be computed as \(\log(\operatorname{mean}(\operatorname{RBP}))\) rather than \(\operatorname{mean}(\operatorname{RBP})\). The two are different quantities: the summary is obtained by log-sum-exp accumulation,\[\log\!\left(\frac{1}{n}\sum_i \operatorname{RBP}_i\right) = \operatorname{logsumexp}_i \ln \operatorname{RBP}_i - \ln n,\]which keeps resolving for scores far below the
float64subnormal floor. With geometric weighting and patience \(p\), a single relevant item at rank \(r\) scores \((1-p)p^{r-1}\); at \(p=0.85\) and \(r=5001\) this underflows to exactly0.0in normal space (its log is \(\approx -814.5\)) and is therefore still finite here.Only the geometric rank weighting used by RBP is supported. Custom
RankWeightobjects andweight_fieldare deliberately not accepted: the baselog_weight()falls back to \(\ln w = \ln(e^{\ln w})\), which exponentiates the very discounts this metric exists to avoid.Like
RBP, it distinguishes two different cases that must not be conflated:a list with test items but no retrieved items scores \(0\), and is reported as \(-\infty\) and retained in the aggregate (it lowers the mean);
a list with an empty test list has no defined score, is reported as
NaN, and is excluded from both the numerator and the denominator — matchingRBPand the existing accumulator behaviour.
Consequently a collection whose valid lists all score zero aggregates to \(-\infty\), while a collection with no valid lists at all aggregates to
NaNrather than a fabricated zero.Note
The summary key is provisionally named
logmeanand appears in collected results asLogRBP.logmean. The name is not settled upstream; see 🐞 1159.Warning
Experimental prototype.
- Parameters:
- Stability:
Experimental
- measure_list(recs, test)#
Compute measurements for a single list.
- Returns:
A float for simple metrics
Intermediate data for decomposed metrics
A dict mapping metric names to values for multi-metric classes
- Parameters:
recs (lenskit.data.ItemList)
test (lenskit.data.ItemList)
- Return type:
- extract_list_metrics(data)#
Expose the per-list log-RBP value in the collected list metrics.
- create_accumulator()#
Create the accumulator implementing this metric’s summary semantics.
The aggregate is \(\log(\operatorname{mean}(\operatorname{RBP}))\), computed as \(\operatorname{logsumexp}_i \ell_i - \ln n_{\text{valid}}\) over the retained per-list log measurements \(\ell_i\). A measurement is retained when it is neither
NonenorNaN; \(-\infty\) is retained, since it encodes a genuine zero-valued RBP and contributes \(e^{-\infty} = 0\) to the sum while still counting in the denominator. That is what separates this aggregate from the mean of the logs, which would be \(-\infty\) whenever any list scores zero.Returns
nandlogmeanonly. It deliberately reports nomean,medianorstdof the log values: those statistics are not meaningful once \(-\infty\) is a legitimate observation.logmeanisNaNwhen there are no valid measurements, and \(-\infty\) when every valid measurement came from a zero-scoring list.Storage is delegated to
ValueStatAccumulator, whoseadddrops exactlyNoneandNaNand keeps every other value.test_accumulator_drops_missing_keeps_neginfpins that \(-\infty\) is retained, so a future narrowing ofaddto finite values fails loudly instead of silently discarding zero-RBP lists.- Return type:
LogRBPAccumulator