lenskit.data.accum#

Data accumulation support

Classes#

Accumulator

Protocol implemented by data accumulators.

AccumulatorFactory

Base class for protocol classes.

ValueStatAccumulator

An accumulator for single real values, computing basic statistics.

ValueStatistics

Collected statitsics from ValueAccumulator.

Package Contents#

class lenskit.data.accum.Accumulator[X, R]#

Bases: Protocol

Protocol implemented by data accumulators.

add(value)#

Add a single value to this accumulator.

Parameters:

value (X)

Return type:

None

accumulate()#

Compute the accumulated value from this accumulator.

Return type:

R

class lenskit.data.accum.AccumulatorFactory[X, R]#

Bases: Protocol

Base class for protocol classes.

Protocol classes are defined as:

class Proto(Protocol):
    def meth(self) -> int:
        ...

Such classes are primarily used with static type checkers that recognize structural subtyping (static duck-typing).

For example:

class C:
    def meth(self) -> int:
        return 0

def func(x: Proto) -> int:
    return x.meth()

func(C())  # Passes static type check

See PEP 544 for details. Protocol classes decorated with @typing.runtime_checkable act as simple-minded runtime protocols that check only the presence of given attributes, ignoring their type signatures. Protocol classes can be generic, they are defined as:

class GenProto[T](Protocol):
    def meth(self) -> T:
        ...
create_accumulator()#

Create an accumulator for the results of this object.

Returns:

An accumulator.

Return type:

Accumulator[X, R]

class lenskit.data.accum.ValueStatAccumulator#

Bases: lenskit.data.accum._proto.Accumulator[float | None, ValueStatistics]

An accumulator for single real values, computing basic statistics.

property values: numpy.ndarray[tuple[int], numpy.dtype[numpy.float64]]#
Return type:

numpy.ndarray[tuple[int], numpy.dtype[numpy.float64]]

__len__()#
Return type:

int

add(value)#

Add a single value to this accumulator.

Parameters:

value (float | None)

accumulate()#

Compute the accumulated value from this accumulator.

Return type:

ValueStatistics

class lenskit.data.accum.ValueStatistics#

Bases: TypedDict

Collected statitsics from ValueAccumulator.

n: int#
mean: float#
median: float#
std: float#