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
Afficher le fichier Open project: zenogantner/MML-KDD Class Usage Examples

Protected Properties

Свойство 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>

Méthodes publiques

Méthode 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

Méthodes protégées

Méthode 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

Méthode Description
CreateFastSamplingData ( int u ) : void

Method Details

AddFeedback() public méthode

public AddFeedback ( int user_id, int item_id ) : void
user_id int
item_id int
Résultat void

AddItem() protected méthode

protected AddItem ( int item_id ) : void
item_id int
Résultat void

AddUser() protected méthode

protected AddUser ( int user_id ) : void
user_id int
Résultat void

CheckSampling() protected méthode

protected CheckSampling ( ) : void
Résultat void

ComputeFit() public méthode

Compute the fit (AUC on training data)
public ComputeFit ( ) : double
Résultat double

ComputeLoss() public méthode

Compute approximate loss
public ComputeLoss ( ) : double
Résultat double

InitModel() protected méthode

protected InitModel ( ) : void
Résultat void

Iterate() public méthode

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
Résultat void

LoadModel() public méthode

public LoadModel ( string file ) : void
file string
Résultat void

Predict() public méthode

public Predict ( int user_id, int item_id ) : double
user_id int
item_id int
Résultat double

RemoveFeedback() public méthode

public RemoveFeedback ( int user_id, int item_id ) : void
user_id int
item_id int
Résultat void

RemoveItem() public méthode

public RemoveItem ( int item_id ) : void
item_id int
Résultat void

RemoveUser() public méthode

public RemoveUser ( int user_id ) : void
user_id int
Résultat void

RetrainItem() protected méthode

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

RetrainUser() protected méthode

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

SampleItemPair() protected méthode

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
Résultat void

SampleOtherItem() protected méthode

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
Résultat bool

SampleTriple() protected méthode

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
Résultat void

SampleUser() protected méthode

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

SaveModel() public méthode

public SaveModel ( string file ) : void
file string
Résultat void

ToString() public méthode

public ToString ( ) : string
Résultat string

Train() public méthode

public Train ( ) : void
Résultat void

UpdateFactors() protected méthode

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
Résultat void

Property Details

fast_sampling protected_oe property

Fast, but memory-intensive sampling
protected bool fast_sampling
Résultat bool

fast_sampling_memory_limit protected_oe property

Fast sampling memory limit, in MiB
protected int fast_sampling_memory_limit
Résultat int

item_bias protected_oe property

Item bias terms
protected IList item_bias
Résultat IList

learn_rate protected_oe property

Learning rate alpha
protected double learn_rate
Résultat double

random protected_oe property

Random number generator
protected Random,System random
Résultat System.Random

reg_i protected_oe property

Regularization parameter for positive item factors
protected double reg_i
Résultat double

reg_j protected_oe property

Regularization parameter for negative item factors
protected double reg_j
Résultat double

reg_u protected_oe property

Regularization parameter for user factors
protected double reg_u
Résultat double

user_neg_items protected_oe property

support data structure for fast sampling
protected IList> user_neg_items
Résultat IList>

user_pos_items protected_oe property

support data structure for fast sampling
protected IList> user_pos_items
Résultat IList>