prea.recommender.etc
Class NonlinearPMF

java.lang.Object
  extended by prea.recommender.etc.NonlinearPMF
All Implemented Interfaces:
Recommender

public class NonlinearPMF
extends java.lang.Object
implements Recommender

This is a class implementing Non-linear Probabilistic Matrix Factorization. Technical detail of the algorithm can be found in Neil D. Lawrence and Raquel Urtasun, Non-linear Matrix Factorization with Gaussian Processes, Proceedings of the 26th International Conference on Machine Learning, 2009.

Since:
2012. 4. 20
Version:
1.1
Author:
Mingxuan Sun

Field Summary
static int ATOX
           
 int featureCount
          The number of features.
static int GRADFACT
           
(package private)  int[] index1toAll
          list of number from 1 to n
 int itemCount
          The number of items.
 SparseMatrix itemFeatures
          Item profile in low-rank matrix form.
 SparseMatrix itemFeaturesChange
          Change of Item profile in low-rank matrix form.
 DenseVector kernParam
          kernel parameter value
 int kernParamNum
          kernel parameter number
 double learningRate
          Learning rate parameter.
 int maxIter
          Maximum number of iteration.
 double maxValue
          Maximum value of rating, existing in the dataset.
 double minValue
          Minimum value of rating, existing in the dataset.
 double momentum
          Momentum parameter.
 SparseMatrix rateMatrix
          Rating matrix for each user (row) and item (column)
 boolean showProgress
          Indicator whether to show progress of iteration.
 int userCount
          The number of users.
static int XTOA
           
 
Constructor Summary
NonlinearPMF(int uc, int ic, double max, double min, int fc, double l, double m, int iter, double kernInverseWidth, double kernVarianceRbf, double kernVarianceBias, double kernVarianceWhite)
          Construct a matrix-factorization model with the given data.
 
Method Summary
 void buildModel(SparseMatrix rm)
          Build a model with the given data and algorithm.
private  DenseVector collabLogLikeGradients(int user, DenseVector kernParam, double momentum, double learningRate)
          Compute the gradients of the model (latent factors and kernel parameters) given one users ratings.
private  DenseMatrix distancePairWise(DenseMatrix X1, DenseMatrix X2)
          Compute the squared Euclidean distance between the row vectors of one matrix and the row vectors of another matrix.
private  DenseVector distancePairWise(DenseMatrix X1, DenseVector x)
          Compute the squared euclidean distance between the row vectors of one matrix and a vector.
 EvaluationMetrics evaluate(SparseMatrix testMatrix)
          Evaluate the designated algorithm with the given test data.
private  DenseVector expTransform(DenseVector x, int transformType)
          Transform a vector by log function, exponential function or linear function.
private  DenseVector getEstimation(int u, int[] testItemsRaw)
          Estimate of ratings for a given user and a set of test items.
private  DenseMatrix kernCompute(DenseMatrix X1, DenseMatrix X2, boolean whiteNoiseFlag)
          Compute kernel parameters for vectors in matrix X1 and vectors in matrix X2.
private  DenseMatrix rbfKernCompute(DenseMatrix distance, double kernInverseWidth, double kernVarianceRbf)
          Compute RBF(radial basis function) kernel parameters for given distances.
private  DenseMatrix rbfKernGradXpoint(DenseVector x, DenseMatrix X2, double kernInverseWidth, double kernVarianceRbf)
          Compute the gradient of RBF kernel with respect to input locations.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ATOX

public static final int ATOX
See Also:
Constant Field Values

XTOA

public static final int XTOA
See Also:
Constant Field Values

GRADFACT

public static final int GRADFACT
See Also:
Constant Field Values

rateMatrix

public SparseMatrix rateMatrix
Rating matrix for each user (row) and item (column)


userCount

public int userCount
The number of users.


itemCount

public int itemCount
The number of items.


featureCount

public int featureCount
The number of features.


maxValue

public double maxValue
Maximum value of rating, existing in the dataset.


minValue

public double minValue
Minimum value of rating, existing in the dataset.


learningRate

public double learningRate
Learning rate parameter.


momentum

public double momentum
Momentum parameter.


maxIter

public int maxIter
Maximum number of iteration.


itemFeatures

public SparseMatrix itemFeatures
Item profile in low-rank matrix form.


itemFeaturesChange

public SparseMatrix itemFeaturesChange
Change of Item profile in low-rank matrix form.


showProgress

public boolean showProgress
Indicator whether to show progress of iteration.


kernParamNum

public int kernParamNum
kernel parameter number


kernParam

public DenseVector kernParam
kernel parameter value


index1toAll

int[] index1toAll
list of number from 1 to n

Constructor Detail

NonlinearPMF

public NonlinearPMF(int uc,
                    int ic,
                    double max,
                    double min,
                    int fc,
                    double l,
                    double m,
                    int iter,
                    double kernInverseWidth,
                    double kernVarianceRbf,
                    double kernVarianceBias,
                    double kernVarianceWhite)
Construct a matrix-factorization model with the given data.

Parameters:
uc - The number of users in the dataset.
ic - The number of items in the dataset.
max - The maximum rating value in the dataset.
min - The minimum rating value in the dataset.
fc - The number of features in low-rank factorized matrix.
iter - The maximum number of iteration.
kernInverseWidth - the kernel inverse width for the RBF kernel.
kernVarianceRbf - the variance for the RBF kernel.
kernVarianceBias - the variance for the bias.
kernVarianceWhite - the variance for the white noise.
Method Detail

buildModel

public void buildModel(SparseMatrix rm)
Build a model with the given data and algorithm.

Specified by:
buildModel in interface Recommender
Parameters:
rm - The rating matrix with train data.

evaluate

public EvaluationMetrics evaluate(SparseMatrix testMatrix)
Evaluate the designated algorithm with the given test data.

Specified by:
evaluate in interface Recommender
Parameters:
testMatrix - The rating matrix with test data.
Returns:
The result of evaluation, such as MAE, RMSE, and rank-score.

getEstimation

private DenseVector getEstimation(int u,
                                  int[] testItemsRaw)
Estimate of ratings for a given user and a set of test items.

Parameters:
u - The user number.
testItemsRaw - The list of items to be predicted.
Returns:
A list containing predicted rating scores.

expTransform

private DenseVector expTransform(DenseVector x,
                                 int transformType)
Transform a vector by log function, exponential function or linear function.

Parameters:
x - The input vector.
transformType - the type of function.
Returns:
The vector after transformation.

distancePairWise

private DenseMatrix distancePairWise(DenseMatrix X1,
                                     DenseMatrix X2)
Compute the squared Euclidean distance between the row vectors of one matrix and the row vectors of another matrix. Vectors in the two matrix have the same dimension.

Parameters:
X1 - matrix1.
X2 - matrix2.
Returns:
The pairwise squared Euclidean distances.

distancePairWise

private DenseVector distancePairWise(DenseMatrix X1,
                                     DenseVector x)
Compute the squared euclidean distance between the row vectors of one matrix and a vector. Vectors in the two matrix have the same dimension.

Parameters:
X1 - matrix1.
x - vector.
Returns:
The pairwise squared euclidean distances.

rbfKernCompute

private DenseMatrix rbfKernCompute(DenseMatrix distance,
                                   double kernInverseWidth,
                                   double kernVarianceRbf)
Compute RBF(radial basis function) kernel parameters for given distances.

Parameters:
distance - The distance matrix.
kernInverseWidth - The kernal inverse bandwidth.
kernVarianceRbf - The kern variance.
Returns:
The kernel matrix.

rbfKernGradXpoint

private DenseMatrix rbfKernGradXpoint(DenseVector x,
                                      DenseMatrix X2,
                                      double kernInverseWidth,
                                      double kernVarianceRbf)
Compute the gradient of RBF kernel with respect to input locations.

Parameters:
x - row locations against which gradients are being computed.
X2 - column locations against which gradients are being computed.
kernInverseWidth - The kernal inverse bandwidth.
kernVarianceRbf - The kern variance.
Returns:
the gradients.

kernCompute

private DenseMatrix kernCompute(DenseMatrix X1,
                                DenseMatrix X2,
                                boolean whiteNoiseFlag)
Compute kernel parameters for vectors in matrix X1 and vectors in matrix X2.

Parameters:
X1 - the matrix1.
X2 - the matrix2.
whiteNoiseFlag - the flag for combining whiteNoise.
Returns:
The kernel matrix.

collabLogLikeGradients

private DenseVector collabLogLikeGradients(int user,
                                           DenseVector kernParam,
                                           double momentum,
                                           double learningRate)
Compute the gradients of the model (latent factors and kernel parameters) given one users ratings.

Parameters:
user - the userId.
kernParam - the kernel parameters.
momentum - the momentum.
learningRate - the learningRate.
Returns:
The kernel matrix.