lenskit.stats#

LensKit statistical computations.

Functions

argtopn(xs, n)

Compute the ordered positions of the top n elements.

gini(xs)

Compute the Gini coefficient of an array of values.

lenskit.stats.gini(xs)#

Compute the Gini coefficient of an array of values.

This is inspired by Olivia Guest’s implementation and based on the StatsDirect reference. It does not include Olivia’s zero adjustment; the Gini coefficient is fine with some zeros, so long as the sum is strictly positive.

Stability:
Caller (see Stability Levels).
Parameters:

xs (numpy.typing.ArrayLike) – An array of values representing the “resource” allocated to each instance.

Returns:

The Gini coefficient of the values in xs.

Return type:

float

lenskit.stats.argtopn(xs, n)#

Compute the ordered positions of the top n elements. Similar to torch.topk(), but works with NumPy arrays and only returns the indices.

Parameters:
  • xs (numpy.typing.ArrayLike)

  • n (int)

Return type:

ndarray[int, dtype[int64]]