lenskit.basic.random#
Classes
|
Randomly select items from a candidate list. |
|
Stochastic top-N ranking with softmax sampling. |
- class lenskit.basic.random.RandomSelector(n=-1, rng=None)#
Bases:
Component
Randomly select items from a candidate list.
- Parameters:
n (int) – The number of items to select, or
-1
to randomly permute the items.rng (int | integer[Any] | Sequence[int] | SeedSequence | Literal['user'] | tuple[int | ~numpy.integer[~typing.Any] | ~typing.Sequence[int] | ~numpy.random.bit_generator.SeedSequence, ~typing.Literal['user']] | None) – The random number generator or specification (see Random Seeds). This class supports derivable RNGs.
- class lenskit.basic.random.SoftmaxRanker(n=-1, rng=None)#
Bases:
Component
Stochastic top-N ranking with softmax sampling.
This uses the “softmax” sampling method, a more efficient approximation of Plackett-Luce sampling than even the Gumbell trick, as documented by `Tim Vieira`_. It expects a scored list of input items, and samples
n
items, with selection probabilities proportional to their scores.Note
Negative scores are clamped to (approximately) zero.
- Parameters:
n (int) – The number of items to return (-1 to return unlimited).
rng (int | integer[Any] | Sequence[int] | SeedSequence | Literal['user'] | tuple[int | ~numpy.integer[~typing.Any] | ~typing.Sequence[int] | ~numpy.random.bit_generator.SeedSequence, ~typing.Literal['user']] | None) – The random number generator or specification (see Random Seeds). This class supports derivable RNGs.