C# Class MyMediaLite.ItemRecommendation.BPRMF

Matrix factorization model for item prediction (ranking) optimized for BPR

BPR reduces ranking to pairwise classification. The different variants (settings) of this recommender roughly optimize the area under the ROC curve (AUC).

\f[ \max_\Theta \sum_{(u,i,j) \in D_S} \ln g(\hat{s}_{u,i,j}(\Theta)) - \lambda ||\Theta||^2 , \f] where \f$\hat{s}_{u,i,j}(\Theta) := \hat{s}_{u,i}(\Theta) - \hat{s}_{u,j}(\Theta)\f$ and \f$D_S = \{ (u, i, j) | i \in \mathcal{I}^+_u \wedge j \in \mathcal{I}^-_u \}\f$. \f$\Theta\f$ represents the parameters of the model and \f$\lambda\f$ is a regularization constant. \f$g\f$ is the logistic function.

In this implementation, we distinguish different regularization updates for users and positive and negative items, which means we do not have only one regularization constant. The optimization problem specified above thus is only an approximation.

Literature: Steffen Rendle, Christoph Freudenthaler, Zeno Gantner, Lars Schmidt-Thieme: BPR: Bayesian Personalized Ranking from Implicit Feedback. UAI 2009. http://www.ismll.uni-hildesheim.de/pub/pdfs/Rendle_et_al2009-Bayesian_Personalized_Ranking.pdf

Different sampling strategies are configurable by setting the UniformUserSampling and WithReplacement accordingly. To get the strategy from the original paper, set UniformUserSampling=false and WithReplacement=false. WithReplacement=true (default) gives you usually a slightly faster convergence, and UniformUserSampling=true (default) (approximately) optimizes the average AUC over all users.

This recommender supports incremental updates.

Inheritance: MF, IFoldInItemRecommender
Exibir arquivo Open project: zenogantner/MML-KDD Class Usage Examples

Protected Properties

Property Type Description
fast_sampling bool
fast_sampling_memory_limit int
item_bias IList
learn_rate double
random System.Random
reg_i double
reg_j double
reg_u double
user_neg_items IList>
user_pos_items IList>

Public Methods

Method Description
AddFeedback ( int user_id, int item_id ) : void
ComputeFit ( ) : double

Compute the fit (AUC on training data)

ComputeLoss ( ) : double

Compute approximate loss

Iterate ( ) : void

Perform one iteration of stochastic gradient ascent over the training data

One iteration is samples number of positive entries in the training matrix times

LoadModel ( string file ) : void
Predict ( int user_id, int item_id ) : double
RemoveFeedback ( int user_id, int item_id ) : void
RemoveItem ( int item_id ) : void
RemoveUser ( int user_id ) : void
SaveModel ( string file ) : void
ToString ( ) : string
Train ( ) : void

Protected Methods

Method Description
AddItem ( int item_id ) : void
AddUser ( int user_id ) : void
CheckSampling ( ) : void
InitModel ( ) : void
RetrainItem ( int item_id ) : void

Retrain the latent factors of a given item

RetrainUser ( int user_id ) : void

Retrain the latent factors of a given user

SampleItemPair ( int u, int &i, int &j ) : void

Sample a pair of items, given a user

SampleOtherItem ( int u, int i, int &j ) : bool

Sample another item, given the first one and the user

SampleTriple ( int &u, int &i, int &j ) : void

Sample a triple for BPR learning

SampleUser ( ) : int

Sample a user that has viewed at least one and not all items

UpdateFactors ( int u, int i, int j, bool update_u, bool update_i, bool update_j ) : void

Update latent factors according to the stochastic gradient descent update rule

Private Methods

Method Description
CreateFastSamplingData ( int u ) : void

Method Details

AddFeedback() public method

public AddFeedback ( int user_id, int item_id ) : void
user_id int
item_id int
return void

AddItem() protected method

protected AddItem ( int item_id ) : void
item_id int
return void

AddUser() protected method

protected AddUser ( int user_id ) : void
user_id int
return void

CheckSampling() protected method

protected CheckSampling ( ) : void
return void

ComputeFit() public method

Compute the fit (AUC on training data)
public ComputeFit ( ) : double
return double

ComputeLoss() public method

Compute approximate loss
public ComputeLoss ( ) : double
return double

InitModel() protected method

protected InitModel ( ) : void
return void

Iterate() public method

Perform one iteration of stochastic gradient ascent over the training data
One iteration is samples number of positive entries in the training matrix times
public Iterate ( ) : void
return void

LoadModel() public method

public LoadModel ( string file ) : void
file string
return void

Predict() public method

public Predict ( int user_id, int item_id ) : double
user_id int
item_id int
return double

RemoveFeedback() public method

public RemoveFeedback ( int user_id, int item_id ) : void
user_id int
item_id int
return void

RemoveItem() public method

public RemoveItem ( int item_id ) : void
item_id int
return void

RemoveUser() public method

public RemoveUser ( int user_id ) : void
user_id int
return void

RetrainItem() protected method

Retrain the latent factors of a given item
protected RetrainItem ( int item_id ) : void
item_id int the item ID
return void

RetrainUser() protected method

Retrain the latent factors of a given user
protected RetrainUser ( int user_id ) : void
user_id int the user ID
return void

SampleItemPair() protected method

Sample a pair of items, given a user
protected SampleItemPair ( int u, int &i, int &j ) : void
u int the user ID
i int the ID of the first item
j int the ID of the second item
return void

SampleOtherItem() protected method

Sample another item, given the first one and the user
protected SampleOtherItem ( int u, int i, int &j ) : bool
u int the user ID
i int the ID of the given item
j int the ID of the other item
return bool

SampleTriple() protected method

Sample a triple for BPR learning
protected SampleTriple ( int &u, int &i, int &j ) : void
u int the user ID
i int the ID of the first item
j int the ID of the second item
return void

SampleUser() protected method

Sample a user that has viewed at least one and not all items
protected SampleUser ( ) : int
return int

SaveModel() public method

public SaveModel ( string file ) : void
file string
return void

ToString() public method

public ToString ( ) : string
return string

Train() public method

public Train ( ) : void
return void

UpdateFactors() protected method

Update latent factors according to the stochastic gradient descent update rule
protected UpdateFactors ( int u, int i, int j, bool update_u, bool update_i, bool update_j ) : void
u int the user ID
i int the ID of the first item
j int the ID of the second item
update_u bool if true, update the user latent factors
update_i bool if true, update the latent factors of the first item
update_j bool if true, update the latent factors of the second item
return void

Property Details

fast_sampling protected_oe property

Fast, but memory-intensive sampling
protected bool fast_sampling
return bool

fast_sampling_memory_limit protected_oe property

Fast sampling memory limit, in MiB
protected int fast_sampling_memory_limit
return int

item_bias protected_oe property

Item bias terms
protected IList item_bias
return IList

learn_rate protected_oe property

Learning rate alpha
protected double learn_rate
return double

random protected_oe property

Random number generator
protected Random,System random
return System.Random

reg_i protected_oe property

Regularization parameter for positive item factors
protected double reg_i
return double

reg_j protected_oe property

Regularization parameter for negative item factors
protected double reg_j
return double

reg_u protected_oe property

Regularization parameter for user factors
protected double reg_u
return double

user_neg_items protected_oe property

support data structure for fast sampling
protected IList> user_neg_items
return IList>

user_pos_items protected_oe property

support data structure for fast sampling
protected IList> user_pos_items
return IList>