lenskit.util#

Miscellaneous utility functions.

Functions

cached(prop)

Decorator for property getters to cache the property value.

clean_str(s)

clone(algo)

Clone an algorithm, but not its fitted data.

cur_memory()

Get the current memory use for this process

last_memo([func, check_type])

max_memory()

Get the maximum memory use for this process

no_progress(obj, **kwargs)

Classes

LastMemo(func[, check_type])

ParamContainer(*args, **kwargs)

class lenskit.util.Stopwatch(start=True)#

Bases: object

Timer class for recording elapsed wall time in operations.

lenskit.util.derivable_rng(spec)#

Get a derivable RNG, for use cases where the code needs to be able to reproducibly derive sub-RNGs for different keys, such as user IDs.

Parameters:

spec

Any value supported by the seed parameter of seedbank.numpy_rng(), in addition to the following values:

  • the string 'user'

  • a tuple of the form (seed, 'user')

Either of these forms will cause the returned function to re-derive new RNGs.

Returns:

A function taking one (or more) key values, like derive_seed(), and returning a random number generator.

Return type:

function

lenskit.util.clone(algo)#

Clone an algorithm, but not its fitted data. This is like sklearn.base.clone(), but may not work on arbitrary SciKit estimators. LensKit algorithms are compatible with SciKit clone, however, so feel free to use that if you need more general capabilities.

This function is somewhat derived from the SciKit one.

>>> from lenskit.algorithms.bias import Bias
>>> orig = Bias()
>>> copy = clone(orig)
>>> copy is orig
False
>>> copy.damping == orig.damping
True
Parameters:

algo (A)

Return type:

A

Modules

envcheck

Inspect the Python environment setup.

logging

Utility code for logging and progress reporting from LensKit components.

random

Utilities to manage randomness in LensKit and LensKit experiments.

test

timing

Timing support