/** * A {@code VectorTruncator} that does not actually perform any truncation. * Any input vector is returned unchanged. */ @Shareable public class NoOpTruncator implements VectorTruncator, Serializable { private static final long serialVersionUID = 1L; @Override public Long2DoubleMap truncate(Long2DoubleMap v) { return LongUtils.frozenMap(v); } }
/** * Item scorer that scores every item with the global mean rating. It is not useful to use this scorer for * ranking items. */ @Shareable public class GlobalMeanRatingItemScorer extends ConstantItemScorer { private static final long serialVersionUID = 1L; @Inject public GlobalMeanRatingItemScorer(@Transient RatingSummary summary) { super(summary.getGlobalMean()); } }
/** * Represents the absence of a threshold function, choosing * to retain all similarity values passed to it. */ @Shareable public class NoThreshold implements Threshold, Serializable { private static final long serialVersionUID = 1; @Override public boolean retain(double sim) { return true; } }
/** * Identity clamping function. * * @author <a href="http://www.grouplens.org">GroupLens Research</a> * @since 0.11 */ @Shareable public final class IdentityClampingFunction implements ClampingFunction, Serializable { private static final long serialVersionUID = 1L; @Override public double apply(long user, long item, double value) { return value; } }
/** * Clamp values to the range of valid ratings. This clamping function uses * the {@link PreferenceDomain} to clamp values to fall within the minimum * and maximum allowable ratings. * * @author <a href="http://www.grouplens.org">GroupLens Research</a> * @since 0.11 */ @Shareable public class RatingRangeClampingFunction implements ClampingFunction, Serializable { private static final long serialVersionUID = 1L; private final PreferenceDomain domain; @Inject public RatingRangeClampingFunction(PreferenceDomain dom) { domain = dom; } public double apply(long user, long item, double value) { return domain.clampValue(value); } }
/** * Neighborhood scorer that computes the sum of neighborhood similarities. * * @author <a href="http://www.grouplens.org">GroupLens Research</a> */ @Shareable public class SimilaritySumNeighborhoodScorer implements NeighborhoodScorer, Serializable { private static final long serialVersionUID = 1L; @Override public void score(long item, Long2DoubleMap neighbors, Long2DoubleMap scores, ItemItemScoreAccumulator accum) { if (neighbors.size() > 0) { double sum = Vectors.sum(neighbors); accum.add(item, sum, neighbors.size(), sum); } } @Override public String toString() { return "[NeighborhoodScorer: SimilaritySum]"; } }
/** * Neighborhood scorer that computes the weighted average of neighbor scores. * * @author <a href="http://www.grouplens.org">GroupLens Research</a> */ @Shareable public class WeightedAverageNeighborhoodScorer implements NeighborhoodScorer, Serializable { private static final long serialVersionUID = 1L; @Override public void score(long item, Long2DoubleMap neighbors, Long2DoubleMap scores, ItemItemScoreAccumulator accum) { double weight = Vectors.sumAbs(neighbors); if (weight > 0) { double weightedSum = Vectors.dotProduct(neighbors, scores); accum.add(item, weightedSum / weight, neighbors.size(), weight); } } @Override public String toString() { return "[NeighborhoodScorer: WeightedAverage]"; } }
/** * Checks similarity values to ensure their absolute values are * over the {@link ThresholdValue}. */ @Shareable public class AbsoluteThreshold implements Threshold, Serializable { private static final long serialVersionUID = 1L; private final double value; /** * Construct a new absolute-value threshold. * * @param threshold The threshold valud. */ @Inject public AbsoluteThreshold(@ThresholdValue double threshold) { this.value = threshold; } @Override public boolean retain(double sim) { return Math.abs(sim) > value; } }
/** * A {@code VectorTruncator} that will retain entries with values * that are accepted by some {@code Threshold}. */ @Shareable public class ThresholdTruncator implements VectorTruncator, Serializable { private static final long serialVersionUID = 1L; private final Threshold threshold; @Inject public ThresholdTruncator(Threshold threshold) { this.threshold = threshold; } @Override public Long2DoubleMap truncate(Long2DoubleMap v) { Long2DoubleMap res = new Long2DoubleOpenHashMap(v.size()); for (Long2DoubleMap.Entry e: Vectors.fastEntries(v)) { if (threshold.retain(e.getDoubleValue())) { res.put(e.getLongKey(), e.getDoubleValue()); } } return res; } }
/** * Checks similarity values to ensure their real values are * over the {@link ThresholdValue}. */ @Shareable public class RealThreshold implements Threshold, Serializable { private static final long serialVersionUID = 1L; private final double thresholdValue; @Inject public RealThreshold(@ThresholdValue double thresholdValue) { this.thresholdValue = thresholdValue; } /** * Get the threshold value. * * @return The threshold value. */ public double getValue() { return thresholdValue; } @Override public boolean retain(double sim) { return sim > thresholdValue; } }
@Shareable public final class IdentityVectorNormalizer extends AbstractVectorNormalizer implements Serializable { private static final long serialVersionUID = -6708410675383598691L;
@Shareable public class UserVectorSimilarity implements UserSimilarity, Serializable { private static final long serialVersionUID = 1L;
@Shareable public class TopNTruncator implements VectorTruncator, Serializable {
@Shareable public class MeanCenteringVectorNormalizer extends AbstractVectorNormalizer implements Serializable { private static final long serialVersionUID = 1L;
@Shareable public class ItemVectorSimilarity implements ItemSimilarity, Serializable, MaybeThreadSafe { private static final long serialVersionUID = 1L;
@Shareable public class DefaultItemVectorNormalizer implements ItemVectorNormalizer, Serializable { private static final long serialVersionUID = 1L;
@Shareable public class DefaultUserVectorNormalizer implements UserVectorNormalizer, Serializable { private static final long serialVersionUID = 1L;
@Shareable public class PopularityRankItemScorer extends AbstractItemScorer implements Serializable { private static final long serialVersionUID = 2L;
@Shareable public class ItemMeanRatingItemScorer extends AbstractItemScorer implements Serializable { private static final long serialVersionUID = 1L;
@Shareable public class UnitVectorNormalizer extends AbstractVectorNormalizer implements Serializable { private final static long serialVersionUID = 1L;