public class FunkSVDModelProvider extends Object implements javax.inject.Provider<FunkSVDModel>
SVD recommender builder using gradient descent (Funk SVD).
This recommender builder constructs an SVD-based recommender using gradient descent, as pioneered by Simon Funk. It also incorporates the regularizations Funk did. These are documented in Netflix Update: Try This at Home. This implementation is based in part on Timely Development's sample code.
Modifier and Type | Field and Description |
---|---|
protected int |
featureCount |
protected double |
initialValue |
protected FunkSVDUpdateRule |
rule |
protected RatingMatrix |
snapshot |
Constructor and Description |
---|
FunkSVDModelProvider(RatingMatrix snapshot,
FunkSVDUpdateRule rule,
int featureCount,
double initVal) |
Modifier and Type | Method and Description |
---|---|
protected double |
doFeatureIteration(TrainingEstimator estimates,
List<RatingMatrixEntry> ratings,
org.apache.commons.math3.linear.RealVector userFeatureVector,
org.apache.commons.math3.linear.RealVector itemFeatureVector,
double trail)
Do a single feature iteration.
|
FunkSVDModel |
get() |
protected void |
summarizeFeature(org.apache.commons.math3.linear.RealVector ufv,
org.apache.commons.math3.linear.RealVector ifv,
FeatureInfo.Builder fib)
Add a feature’s summary to the feature info builder.
|
protected void |
trainFeature(int feature,
TrainingEstimator estimates,
org.apache.commons.math3.linear.RealVector userFeatureVector,
org.apache.commons.math3.linear.RealVector itemFeatureVector,
FeatureInfo.Builder fib)
Train a feature using a collection of ratings.
|
protected final int featureCount
protected final RatingMatrix snapshot
protected final double initialValue
protected final FunkSVDUpdateRule rule
@Inject public FunkSVDModelProvider(@Nonnull RatingMatrix snapshot, @Nonnull FunkSVDUpdateRule rule, @FeatureCount int featureCount, @InitialFeatureValue double initVal)
public FunkSVDModel get()
get
in interface javax.inject.Provider<FunkSVDModel>
protected void trainFeature(int feature, TrainingEstimator estimates, org.apache.commons.math3.linear.RealVector userFeatureVector, org.apache.commons.math3.linear.RealVector itemFeatureVector, FeatureInfo.Builder fib)
Train a feature using a collection of ratings. This method iteratively calls doFeatureIteration(TrainingEstimator, List, RealVector, RealVector, double)
to train the feature. It can be overridden to customize the feature training strategy.
We use the estimator to maintain the estimate up through a particular feature value, rather than recomputing the entire kernel value every time. This hopefully speeds up training. It means that we always tell the updater we are training feature 0, but use a subvector that starts with the current feature.
feature
- The number of the current feature.estimates
- The current estimator. This method is not expected to update the estimator.userFeatureVector
- The user feature values. This has been initialized to the initial value, and may be reused between features.itemFeatureVector
- The item feature values. This has been initialized to the initial value, and may be reused between features.fib
- The feature info builder. This method is only expected to add information about its training rounds to the builder; the caller takes care of feature number and summary data.doFeatureIteration(TrainingEstimator, List, RealVector, RealVector, double)
,
summarizeFeature(RealVector, RealVector, FeatureInfo.Builder)
protected double doFeatureIteration(TrainingEstimator estimates, List<RatingMatrixEntry> ratings, org.apache.commons.math3.linear.RealVector userFeatureVector, org.apache.commons.math3.linear.RealVector itemFeatureVector, double trail)
Do a single feature iteration.
estimates
- The estimates.ratings
- The ratings to train on.userFeatureVector
- The user column vector for the current feature.itemFeatureVector
- The item column vector for the current feature.trail
- The sum of the remaining user-item-feature values.protected void summarizeFeature(org.apache.commons.math3.linear.RealVector ufv, org.apache.commons.math3.linear.RealVector ifv, FeatureInfo.Builder fib)
Add a feature’s summary to the feature info builder.
ufv
- The user values.ifv
- The item values.fib
- The feature info builder.