org.grouplens.lenskit.util

## Class IdMeanAccumulator

• public final class IdMeanAccumulator
extends Object

An accumulator for means associated with IDs.

Since:
1.1
• ### Constructor Summary

Constructors
Constructor and Description
IdMeanAccumulator()
• ### Method Summary

All Methods
Modifier and Type Method and Description
ImmutableSparseVector computeIdMeans(double offset, double damping)
Compute the means for each ID.
double globalMean()
Get the global mean.
ImmutableSparseVector idMeanOffsets()
Compute offsets from the global mean for each ID.
ImmutableSparseVector idMeanOffsets(double damping)
Compute mean offsets for each item.
ImmutableSparseVector idMeans()
Get the per-ID means.
void put(long id, double val)
Accumulate a value with an ID.
• ### Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
• ### Constructor Detail

• #### IdMeanAccumulator

public IdMeanAccumulator()
• ### Method Detail

• #### put

public void put(long id,
double val)

Accumulate a value with an ID.

Parameters:
id - The ID.
val - The value.
• #### globalMean

public double globalMean()

Get the global mean.

Returns:
The global mean value.
• #### idMeans

public ImmutableSparseVector idMeans()

Get the per-ID means. Equivalent to computeIdMeans(0, 0).

Returns:
A vector of means for each ID that has been accumulated.
See Also:
computeIdMeans(double, double)
• #### computeIdMeans

public ImmutableSparseVector computeIdMeans(double offset,
double damping)

Compute the means for each ID. This is a generalized mean function, capable of offsetting the individual values and damping the overall mean. For an ID with (n) values (x_1,\dots,xn), offset (y) and damping (\gamma), it computes (\frac{\sum{i=1}^n x_i - ny}{n + \gamma}). If (y) is the global mean, this computes each ID’s average deviation from the global mean. If (\gamma) is additionally positive, then these average deviations are then damped towards 0, effectively pretending that each ID has an additional (\gamma) values at exactly the global mean. If (y=0) and (gamma > 0), it pretends each ID has additional values at 0.

The prior (assumed value for additional values) is always 0 in the output domain. If (y>0), then the values are offset first, and then damped towards 0. This method does not yet support damping towards some other value; if you need actual damped means, where each is damped towards the global mean, add the global mean to the resulting vector.

Parameters:
offset - An offset to subtract from each value prior to averaging.
damping - The damping term (see idMeanOffsets(double)).
Returns:
The vector of means.
• #### idMeanOffsets

public ImmutableSparseVector idMeanOffsets(double damping)

Compute mean offsets for each item. Equivalent to computeIdMeans(globalMean(), damping).

Parameters:
damping - The damping term.
Returns:
A vector of mean offsets.
See Also:
computeIdMeans(double, double)
• #### idMeanOffsets

public ImmutableSparseVector idMeanOffsets()

Compute offsets from the global mean for each ID. This is equivalent to calling idMeanOffsets(0).

Returns:
a vector of offsets.
Skip navigation links