@DefaultProvider(value=MeanVarianceNormalizer.Builder.class) @Shareable public class MeanVarianceNormalizer extends AbstractVectorNormalizer implements Serializable
Normalizes against the variance of the vector with optional smoothing as described in Hofmann ’04.
For user rating vectors, this normalization assumes that a user’s mean rating and variance are independent of actual preferences, and attempts to describe the preference of a rating by the distance of the rating from the mean, relative to the user’s normal rating variance.
The smoothing factor helps to smooth out results for users with fewer ratings by re-weighting the user’s rating variance. The ‘smoothing number’ is a number of ‘default’ ratings to give the user, weighting the user’s variance towards the average community variance. Accordingly, set smoothing = 0 (or use default constructor) for no smoothing. The ‘global variance’ parameter only pertains to smoothing, and is unnecessary otherwise.
If the reference vector has a standard deviation of 0 (as determined by Scalars.isZero(double)
), and there is no smoothing, then no scaling is done (it is treated as if the standard deviation is 1). This is to keep the behavior well-defined in all cases.
Modifier and Type | Class and Description |
---|---|
static class |
MeanVarianceNormalizer.Builder
A Builder for UserVarianceNormalizers that computes the variance from a RatingBuildContext.
|
Constructor and Description |
---|
MeanVarianceNormalizer()
Initializes basic normalizer with no damping.
|
MeanVarianceNormalizer(double damping,
double globalVariance)
Construct a new mean variance normalizer.
|
Modifier and Type | Method and Description |
---|---|
double |
getDamping()
Get the damping term.
|
double |
getGlobalVariance()
Get the global variance.
|
VectorTransformation |
makeTransformation(Long2DoubleMap reference)
Create a vector transformation that normalizes and denormalizes vectors with respect to a reference vector.
|
VectorTransformation |
makeTransformation(SparseVector reference)
Create a vector transformation that normalizes and denormalizes vectors with respect to the specified entity.
|
normalize
public MeanVarianceNormalizer()
Initializes basic normalizer with no damping.
public MeanVarianceNormalizer(double damping, double globalVariance)
Construct a new mean variance normalizer.
damping
- damping factor to use. 0 for no damping, 5 for Hofmann’s implementation.globalVariance
- global variance to use in the damping calculations.public double getDamping()
Get the damping term.
public double getGlobalVariance()
Get the global variance.
public VectorTransformation makeTransformation(SparseVector reference)
VectorNormalizer
Create a vector transformation that normalizes and denormalizes vectors with respect to the specified entity. This allows transformations to be applied multiple times to different vectors and also unapplied.
If the reference vector is empty, the returned transformation should be the identity transform. Results are undefined if the reference vector is not complete or contains NaN values.
If the normalization needs to retain a copy of the sparse vector, it will take an immutable copy.
makeTransformation
in interface VectorNormalizer
reference
- The reference vector.public VectorTransformation makeTransformation(Long2DoubleMap reference)
VectorNormalizer
Create a vector transformation that normalizes and denormalizes vectors with respect to a reference vector. The reference vector is used to compute any data needed for the normalization. For example, a mean-centering normalization will subtract the mean of the reference vector from any vector to which it is applied, and add back the reference mean when it is unapplied.
This allows transformations to be applied multiple times to different vectors and also unapplied.
If the reference vector is empty, the returned transformation should be the identity transform. Results are undefined if the reference vector is not complete or contains NaN values.
If the normalization needs to retain a copy of the sparse vector, it will take an immutable copy.
makeTransformation
in interface VectorNormalizer
reference
- The reference vector.