Skip to content

Commit

Permalink
remove damped_mean function
Browse files Browse the repository at this point in the history
  • Loading branch information
mdekstrand committed Dec 31, 2024
1 parent 76e5a6e commit 969a0a8
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 32 deletions.
3 changes: 1 addition & 2 deletions lenskit/lenskit/basic/bias.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from lenskit.data import ID, Dataset, ItemList, QueryInput, RecQuery, UITuple, Vocabulary
from lenskit.pipeline.components import Component
from lenskit.stats import damped_mean

_logger = logging.getLogger(__name__)
Damping: TypeAlias = float | UITuple[float] | tuple[float, float]
Expand Down Expand Up @@ -211,7 +210,7 @@ def compute_for_items(
r_mask = r_idxes >= 0
uoff[r_mask] -= self.item_biases[r_idxes[r_mask]]

user_bias = damped_mean(uoff, self.damping.user)
user_bias = np.sum(uoff) / (np.sum(np.isfinite(uoff)) + self.damping.user)
scores += user_bias

elif user_id is not None:
Expand Down
30 changes: 0 additions & 30 deletions lenskit/lenskit/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,36 +12,6 @@
from lenskit.diagnostics import DataWarning


def damped_mean(xs: ArrayLike, damping: float | None) -> float:
r"""
Compute a mean with Bayesian damping. It compute the formula:
.. math::
\begin{align*}
\bar{x} & = \frac{\sum_i x_i}{n} \\
\tilde{x} & = \frac{\sum_i (x_i - \bar{x})}{n + \gamma}
\end{align*}
Stability:
Caller
Args:
xs:
The array of values.
damping:
The Bayesian damping term :math:`\gamma`.
Returns:
The damped mean :math:`\tilde{x}`.
"""
xs = np.asarray(xs)
mean = np.mean(xs)
if damping is not None and damping > 0:
return np.sum(xs - mean) / (np.sum(np.isfinite(xs)).item() + damping)
else:
return mean.item()


def gini(xs: ArrayLike) -> float:
"""
Compute the Gini coefficient of an array of values.
Expand Down

0 comments on commit 969a0a8

Please sign in to comment.