C# Класс 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.

Наследование: MF, IFoldInItemRecommender
Показать файл Открыть проект Примеры использования класса

Защищенные свойства (Protected)

Свойство Тип Описание
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>

Открытые методы

Метод Описание
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

Защищенные методы

Метод Описание
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

Приватные методы

Метод Описание
CreateFastSamplingData ( int u ) : void

Описание методов

AddFeedback() публичный Метод

public AddFeedback ( int user_id, int item_id ) : void
user_id int
item_id int
Результат void

AddItem() защищенный Метод

protected AddItem ( int item_id ) : void
item_id int
Результат void

AddUser() защищенный Метод

protected AddUser ( int user_id ) : void
user_id int
Результат void

CheckSampling() защищенный Метод

protected CheckSampling ( ) : void
Результат void

ComputeFit() публичный Метод

Compute the fit (AUC on training data)
public ComputeFit ( ) : double
Результат double

ComputeLoss() публичный Метод

Compute approximate loss
public ComputeLoss ( ) : double
Результат double

InitModel() защищенный Метод

protected InitModel ( ) : void
Результат void

Iterate() публичный Метод

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
Результат void

LoadModel() публичный Метод

public LoadModel ( string file ) : void
file string
Результат void

Predict() публичный Метод

public Predict ( int user_id, int item_id ) : double
user_id int
item_id int
Результат double

RemoveFeedback() публичный Метод

public RemoveFeedback ( int user_id, int item_id ) : void
user_id int
item_id int
Результат void

RemoveItem() публичный Метод

public RemoveItem ( int item_id ) : void
item_id int
Результат void

RemoveUser() публичный Метод

public RemoveUser ( int user_id ) : void
user_id int
Результат void

RetrainItem() защищенный Метод

Retrain the latent factors of a given item
protected RetrainItem ( int item_id ) : void
item_id int the item ID
Результат void

RetrainUser() защищенный Метод

Retrain the latent factors of a given user
protected RetrainUser ( int user_id ) : void
user_id int the user ID
Результат void

SampleItemPair() защищенный Метод

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
Результат void

SampleOtherItem() защищенный Метод

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
Результат bool

SampleTriple() защищенный Метод

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
Результат void

SampleUser() защищенный Метод

Sample a user that has viewed at least one and not all items
protected SampleUser ( ) : int
Результат int

SaveModel() публичный Метод

public SaveModel ( string file ) : void
file string
Результат void

ToString() публичный Метод

public ToString ( ) : string
Результат string

Train() публичный Метод

public Train ( ) : void
Результат void

UpdateFactors() защищенный Метод

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
Результат void

Описание свойств

fast_sampling защищенное свойство

Fast, but memory-intensive sampling
protected bool fast_sampling
Результат bool

fast_sampling_memory_limit защищенное свойство

Fast sampling memory limit, in MiB
protected int fast_sampling_memory_limit
Результат int

item_bias защищенное свойство

Item bias terms
protected IList item_bias
Результат IList

learn_rate защищенное свойство

Learning rate alpha
protected double learn_rate
Результат double

random защищенное свойство

Random number generator
protected Random,System random
Результат System.Random

reg_i защищенное свойство

Regularization parameter for positive item factors
protected double reg_i
Результат double

reg_j защищенное свойство

Regularization parameter for negative item factors
protected double reg_j
Результат double

reg_u защищенное свойство

Regularization parameter for user factors
protected double reg_u
Результат double

user_neg_items защищенное свойство

support data structure for fast sampling
protected IList> user_neg_items
Результат IList>

user_pos_items защищенное свойство

support data structure for fast sampling
protected IList> user_pos_items
Результат IList>