Class PMF
- java.lang.Object
-
- es.upm.etsisi.cf4j.recommender.Recommender
-
- es.upm.etsisi.cf4j.recommender.matrixFactorization.PMF
-
public class PMF extends Recommender
Implements Mnih, A., & Salakhutdinov, R. R. (2008). Probabilistic matrix factorization. In Advances in neural information processing systems (pp. 1257-1264).
-
-
Field Summary
Fields Modifier and Type Field Description protected static double
DEFAULT_GAMMA
protected static double
DEFAULT_LAMBDA
protected double
gamma
Learning rateprotected double
lambda
Regularization parameterprotected int
numFactors
Number of latent factorsprotected int
numIters
Number of iterationsprotected double[][]
p
User factorsprotected double[][]
q
Item factors-
Fields inherited from class es.upm.etsisi.cf4j.recommender.Recommender
datamodel
-
-
Constructor Summary
Constructors Constructor Description PMF(DataModel datamodel, int numFactors, int numIters)
Model constructorPMF(DataModel datamodel, int numFactors, int numIters, double lambda)
Model constructorPMF(DataModel datamodel, int numFactors, int numIters, double lambda, double gamma, long seed)
Model constructorPMF(DataModel datamodel, int numFactors, int numIters, double lambda, long seed)
Model constructorPMF(DataModel datamodel, int numFactors, int numIters, long seed)
Model constructorPMF(DataModel datamodel, Map<String,Object> params)
Model constructor from a Map containing the model's hyper-parameters values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fit()
Estimates model parameters given the hyper-parametersdouble
getGamma()
Get the learning rate parameter of the modeldouble[]
getItemFactors(int itemIndex)
Get the latent factors vector of an item (qi)double
getLambda()
Get the regularization parameter of the modelint
getNumFactors()
Get the number of factors of the modelint
getNumIters()
Get the number of iterationsdouble[]
getUserFactors(int userIndex)
Get the latent factors vector of a user (pu)double
predict(int userIndex, int itemIndex)
Computes a rating predictionString
toString()
-
Methods inherited from class es.upm.etsisi.cf4j.recommender.Recommender
getDataModel, predict
-
-
-
-
Field Detail
-
DEFAULT_GAMMA
protected static final double DEFAULT_GAMMA
- See Also:
- Constant Field Values
-
DEFAULT_LAMBDA
protected static final double DEFAULT_LAMBDA
- See Also:
- Constant Field Values
-
p
protected final double[][] p
User factors
-
q
protected final double[][] q
Item factors
-
gamma
protected final double gamma
Learning rate
-
lambda
protected final double lambda
Regularization parameter
-
numFactors
protected final int numFactors
Number of latent factors
-
numIters
protected final int numIters
Number of iterations
-
-
Constructor Detail
-
PMF
public PMF(DataModel datamodel, Map<String,Object> params)
Model constructor from a Map containing the model's hyper-parameters values. Map object must contains the following keys:- numFactors: int value with the number of latent factors.
- numIters:: int value with the number of iterations.
- gamma (optional): double value with the learning rate hyper-parameter. If missing, it is set to 0.01.
- lambda (optional): double value with the regularization hyper-parameter. If missing, it is set to 0.05.
- seed (optional): random seed for random numbers generation. If missing, random value is used.
- Parameters:
datamodel
- DataModel instanceparams
- Model's hyper-parameters values
-
PMF
public PMF(DataModel datamodel, int numFactors, int numIters)
Model constructor- Parameters:
datamodel
- DataModel instancenumFactors
- Number of factorsnumIters
- Number of iterations
-
PMF
public PMF(DataModel datamodel, int numFactors, int numIters, long seed)
Model constructor- Parameters:
datamodel
- DataModel instancenumFactors
- Number of factorsnumIters
- Number of iterationsseed
- Seed for random numbers generation
-
PMF
public PMF(DataModel datamodel, int numFactors, int numIters, double lambda)
Model constructor- Parameters:
datamodel
- DataModel instancenumFactors
- Number of factorsnumIters
- Number of iterationslambda
- Regularization parameter
-
PMF
public PMF(DataModel datamodel, int numFactors, int numIters, double lambda, long seed)
Model constructor- Parameters:
datamodel
- DataModel instancenumFactors
- Number of factorsnumIters
- Number of iterationslambda
- Regularization parameterseed
- Seed for random numbers generation
-
PMF
public PMF(DataModel datamodel, int numFactors, int numIters, double lambda, double gamma, long seed)
Model constructor- Parameters:
datamodel
- DataModel instancenumFactors
- Number of factorsnumIters
- Number of iterationslambda
- Regularization parametergamma
- Learning rate parameterseed
- Seed for random numbers generation
-
-
Method Detail
-
getNumFactors
public int getNumFactors()
Get the number of factors of the model- Returns:
- Number of factors
-
getNumIters
public int getNumIters()
Get the number of iterations- Returns:
- Number of iterations
-
getLambda
public double getLambda()
Get the regularization parameter of the model- Returns:
- Lambda
-
getGamma
public double getGamma()
Get the learning rate parameter of the model- Returns:
- Gamma
-
getUserFactors
public double[] getUserFactors(int userIndex)
Get the latent factors vector of a user (pu)- Parameters:
userIndex
- User index- Returns:
- Latent factors vector
-
getItemFactors
public double[] getItemFactors(int itemIndex)
Get the latent factors vector of an item (qi)- Parameters:
itemIndex
- Item index- Returns:
- Latent factors vector
-
fit
public void fit()
Description copied from class:Recommender
Estimates model parameters given the hyper-parameters- Specified by:
fit
in classRecommender
-
predict
public double predict(int userIndex, int itemIndex)
Description copied from class:Recommender
Computes a rating prediction- Specified by:
predict
in classRecommender
- Parameters:
userIndex
- Index of the user in the array of Users of the DataModel instanceitemIndex
- Index of the item in the array of Items of the DataModel instance- Returns:
- Prediction
-
-