MyMediaLite  3.11
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Properties | List of all members
MultiCoreBPRMF Class Reference

Matrix factorization for BPR on multiple cores More...

Inheritance diagram for MultiCoreBPRMF:
BPRMF MF IFoldInItemRecommender IncrementalItemRecommender IIterativeModel IRecommender ItemRecommender IIncrementalItemRecommender Recommender IIncrementalRecommender IRecommender

Public Member Functions

override void AddFeedback (ICollection< Tuple< int, int >> feedback)
 Add positive feedback events and perform incremental training More...
 
virtual bool CanPredict (int user_id, int item_id)
 Check whether a useful prediction (i.e. not using a fallback/default answer) can be made for a given user-item combination More...
 
Object Clone ()
 create a shallow copy of the object More...
 
override float ComputeObjective ()
 Compute the current optimization objective (usually loss plus regularization term) of the model More...
 
override void Iterate ()
 Perform one iteration of stochastic gradient ascent over the training data More...
 
override void LoadModel (string file)
 Get the model parameters from a file More...
 
 MultiCoreBPRMF ()
 default constructor More...
 
override float Predict (int user_id, int item_id)
 Predict rating or score for a given user-item combination More...
 
IList< Tuple< int, float > > Recommend (int user_id, int n=-1, ICollection< int > ignore_items=null, ICollection< int > candidate_items=null)
 Recommend items for a given user More...
 
virtual System.Collections.Generic.IList< Tuple< int, float > > Recommend (int user_id, int n=-1, System.Collections.Generic.ICollection< int > ignore_items=null, System.Collections.Generic.ICollection< int > candidate_items=null)
 
override void RemoveFeedback (ICollection< Tuple< int, int >> feedback)
 Remove all feedback events by the given user-item combinations More...
 
override void RemoveItem (int item_id)
 Remove all feedback by one item More...
 
override void RemoveUser (int user_id)
 Remove all feedback by one user More...
 
override void SaveModel (string file)
 Save the model parameters to a file More...
 
IList< Tuple< int, float > > ScoreItems (IList< int > accessed_items, IList< int > candidate_items)
 Score a list of items given a list of items that represent a new user More...
 
override string ToString ()
 Return a string representation of the recommender More...
 
override void Train ()
 Learn the model parameters of the recommender from the training data More...
 

Protected Member Functions

override void AddItem (int item_id)
 
override void AddUser (int user_id)
 
override void InitModel ()
 
override void IterateWithoutReplacementUniformPair ()
 Iterate over the training data, uniformly sample from user-item pairs without replacement. More...
 
virtual void IterateWithoutReplacementUniformPair (IList< int > indices)
 Iterate over the training data, uniformly sample from user-item pairs without replacement. More...
 
virtual void IterateWithoutReplacementUniformUser ()
 Iterate over the training data, uniformly sample from users without replacement. More...
 
virtual void IterateWithReplacementUniformPair ()
 Iterate over the training data, uniformly sample from user-item pairs with replacement. More...
 
virtual void IterateWithReplacementUniformUser ()
 Iterate over the training data, uniformly sample from users with replacement. More...
 
override void RetrainItem (int item_id)
 Retrain the latent factors of a given item More...
 
override void RetrainUser (int user_id)
 Retrain the latent factors of a given user More...
 
virtual void SampleItemPair (ICollection< int > user_items, out int item_id, out int other_item_id)
 Sample a pair of items, given a user More...
 
virtual bool SampleOtherItem (int user_id, int item_id, out int other_item_id)
 Sample another item, given the first one and the user More...
 
virtual void SampleTriple (out int user_id, out int item_id, out int other_item_id)
 Sample a triple for BPR learning More...
 
virtual int SampleUser ()
 Uniformly sample a user that has viewed at least one and not all items More...
 
virtual void UpdateFactors (int user_id, int item_id, int other_item_id, bool update_u, bool update_i, bool update_j)
 Update latent factors according to the stochastic gradient descent update rule More...
 

Protected Attributes

float[] item_bias
 Item bias terms More...
 
Matrix< float > item_factors
 Latent item factor matrix More...
 
float learn_rate = 0.05f
 Learning rate alpha More...
 
int num_factors = 10
 Number of latent factors per user/item More...
 
float reg_i = 0.0025f
 Regularization parameter for positive item factors More...
 
float reg_j = 0.00025f
 Regularization parameter for negative item factors More...
 
float reg_u = 0.0025f
 Regularization parameter for user factors More...
 
bool update_j = true
 If set (default), update factors for negative sampled items during learning More...
 
Matrix< float > user_factors
 Latent user factor matrix More...
 

Static Protected Attributes

static System.Random random
 Reference to (per-thread) singleton random number generator More...
 

Properties

float BiasReg [get, set]
 Regularization parameter for the bias term More...
 
virtual IPosOnlyFeedback Feedback [get, set]
 the feedback data to be used for training More...
 
double InitMean [get, set]
 Mean of the normal distribution used to initialize the latent factors More...
 
double InitStdDev [get, set]
 Standard deviation of the normal distribution used to initialize the latent factors More...
 
float LearnRate [get, set]
 Learning rate alpha More...
 
int MaxItemID [get, set]
 Maximum item ID More...
 
int MaxThreads [get, set]
 the maximum number of threads to use More...
 
int MaxUserID [get, set]
 Maximum user ID More...
 
uint NumFactors [get, set]
 Number of latent factors per user/item More...
 
uint NumIter [get, set]
 Number of iterations over the training data More...
 
float RegI [get, set]
 Regularization parameter for positive item factors More...
 
float RegJ [get, set]
 Regularization parameter for negative item factors More...
 
float RegU [get, set]
 Regularization parameter for user factors More...
 
bool UniformUserSampling [get, set]
 Sample uniformly from users More...
 
bool UpdateItems [get, set]
 
bool UpdateJ [get, set]
 If set (default), update factors for negative sampled items during learning More...
 
bool UpdateUsers [get, set]
 
bool WithReplacement [get, set]
 Sample positive observations with (true) or without (false) replacement More...
 

Detailed Description

Matrix factorization for BPR on multiple cores

This recommender supports incremental updates, however they are currently not performed on multiple cores.

Constructor & Destructor Documentation

MultiCoreBPRMF ( )
inline

default constructor

Member Function Documentation

override void AddFeedback ( ICollection< Tuple< int, int >>  feedback)
inlinevirtualinherited

Add positive feedback events and perform incremental training

Parameters
feedbackcollection of user id - item id tuples

Reimplemented from IncrementalItemRecommender.

virtual bool CanPredict ( int  user_id,
int  item_id 
)
inlinevirtualinherited

Check whether a useful prediction (i.e. not using a fallback/default answer) can be made for a given user-item combination

It is up to the recommender implementor to decide when a prediction is useful, and to document it accordingly.

Parameters
user_idthe user ID
item_idthe item ID
Returns
true if a useful prediction can be made, false otherwise

Implements IRecommender.

Reimplemented in ExternalItemRecommender, ExternalRatingPredictor, BiPolarSlopeOne, SlopeOne, Constant, GlobalAverage, UserAverage, ItemAverage, and Random.

Object Clone ( )
inlineinherited

create a shallow copy of the object

override float ComputeObjective ( )
inlinevirtualinherited

Compute the current optimization objective (usually loss plus regularization term) of the model

Returns
the current objective; -1 if not implemented

Implements MF.

Reimplemented in SoftMarginRankingMF.

override void Iterate ( )
inlinevirtualinherited

Perform one iteration of stochastic gradient ascent over the training data

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

Implements MF.

override void IterateWithoutReplacementUniformPair ( )
inlineprotectedvirtual

Iterate over the training data, uniformly sample from user-item pairs without replacement.

Reimplemented from BPRMF.

virtual void IterateWithoutReplacementUniformPair ( IList< int >  indices)
inlineprotectedvirtualinherited

Iterate over the training data, uniformly sample from user-item pairs without replacement.

virtual void IterateWithoutReplacementUniformUser ( )
inlineprotectedvirtualinherited

Iterate over the training data, uniformly sample from users without replacement.

virtual void IterateWithReplacementUniformPair ( )
inlineprotectedvirtualinherited

Iterate over the training data, uniformly sample from user-item pairs with replacement.

virtual void IterateWithReplacementUniformUser ( )
inlineprotectedvirtualinherited

Iterate over the training data, uniformly sample from users with replacement.

override void LoadModel ( string  filename)
inlineinherited

Get the model parameters from a file

Parameters
filenamethe name of the file to read from

Implements IRecommender.

override float Predict ( int  user_id,
int  item_id 
)
inlineinherited

Predict rating or score for a given user-item combination

Parameters
user_idthe user ID
item_idthe item ID
Returns
the predicted score/rating for the given user-item combination

Implements IRecommender.

IList<Tuple<int, float> > Recommend ( int  user_id,
int  n = -1,
ICollection< int >  ignore_items = null,
ICollection< int >  candidate_items = null 
)
inherited

Recommend items for a given user

Parameters
user_idthe user ID
nthe number of items to recommend, -1 for as many as possible
ignore_itemscollection if items that should not be returned; if null, use empty collection
candidate_itemsthe candidate items to choose from; if null, use all items
Returns
a sorted list of (item_id, score) tuples

Implemented in WeightedEnsemble, and Ensemble.

override void RemoveFeedback ( ICollection< Tuple< int, int >>  feedback)
inlinevirtualinherited

Remove all feedback events by the given user-item combinations

Parameters
feedbackcollection of user id - item id tuples

Reimplemented from IncrementalItemRecommender.

override void RemoveItem ( int  item_id)
inlinevirtualinherited

Remove all feedback by one item

Parameters
item_idthe item ID

Reimplemented from IncrementalItemRecommender.

override void RemoveUser ( int  user_id)
inlinevirtualinherited

Remove all feedback by one user

Parameters
user_idthe user ID

Reimplemented from IncrementalItemRecommender.

override void RetrainItem ( int  item_id)
inlineprotectedvirtualinherited

Retrain the latent factors of a given item

Parameters
item_idthe item ID

Implements MF.

override void RetrainUser ( int  user_id)
inlineprotectedvirtualinherited

Retrain the latent factors of a given user

Parameters
user_idthe user ID

Implements MF.

virtual void SampleItemPair ( ICollection< int >  user_items,
out int  item_id,
out int  other_item_id 
)
inlineprotectedvirtualinherited

Sample a pair of items, given a user

Parameters
user_itemsthe items accessed by the given user
item_idthe ID of the first item
other_item_idthe ID of the second item
virtual bool SampleOtherItem ( int  user_id,
int  item_id,
out int  other_item_id 
)
inlineprotectedvirtualinherited

Sample another item, given the first one and the user

Parameters
user_idthe user ID
item_idthe ID of the given item
other_item_idthe ID of the other item
Returns
true if the given item was already seen by user u
virtual void SampleTriple ( out int  user_id,
out int  item_id,
out int  other_item_id 
)
inlineprotectedvirtualinherited

Sample a triple for BPR learning

Parameters
user_idthe user ID
item_idthe ID of the first item
other_item_idthe ID of the second item

Reimplemented in WeightedBPRMF.

virtual int SampleUser ( )
inlineprotectedvirtualinherited

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

Returns
the user ID
override void SaveModel ( string  filename)
inlineinherited

Save the model parameters to a file

Parameters
filenamethe name of the file to write to

Implements IRecommender.

IList<Tuple<int, float> > ScoreItems ( IList< int >  accessed_items,
IList< int >  candidate_items 
)
inlineinherited

Score a list of items given a list of items that represent a new user

Returns
a list of int and float pairs, representing item IDs and predicted scores
Parameters
accessed_itemsthe ratings (item IDs and rating values) representing the new user
candidate_itemsthe items to be rated

Implements IFoldInItemRecommender.

override string ToString ( )
inline

Return a string representation of the recommender

The ToString() method of recommenders should list the class name and all hyperparameters, separated by space characters.

Implements IRecommender.

override void Train ( )
inlinevirtual

Learn the model parameters of the recommender from the training data

Reimplemented from MF.

virtual void UpdateFactors ( int  user_id,
int  item_id,
int  other_item_id,
bool  update_u,
bool  update_i,
bool  update_j 
)
inlineprotectedvirtualinherited

Update latent factors according to the stochastic gradient descent update rule

Parameters
user_idthe user ID
item_idthe ID of the first item
other_item_idthe ID of the second item
update_uif true, update the user latent factors
update_iif true, update the latent factors of the first item
update_jif true, update the latent factors of the second item

Reimplemented in SoftMarginRankingMF.

Member Data Documentation

float [] item_bias
protectedinherited

Item bias terms

Matrix<float> item_factors
protectedinherited

Latent item factor matrix

float learn_rate = 0.05f
protectedinherited

Learning rate alpha

int num_factors = 10
protectedinherited

Number of latent factors per user/item

System.Random random
staticprotectedinherited

Reference to (per-thread) singleton random number generator

float reg_i = 0.0025f
protectedinherited

Regularization parameter for positive item factors

float reg_j = 0.00025f
protectedinherited

Regularization parameter for negative item factors

float reg_u = 0.0025f
protectedinherited

Regularization parameter for user factors

bool update_j = true
protectedinherited

If set (default), update factors for negative sampled items during learning

Matrix<float> user_factors
protectedinherited

Latent user factor matrix

Property Documentation

float BiasReg
getsetinherited

Regularization parameter for the bias term

virtual IPosOnlyFeedback Feedback
getsetinherited

the feedback data to be used for training

double InitMean
getsetinherited

Mean of the normal distribution used to initialize the latent factors

double InitStdDev
getsetinherited

Standard deviation of the normal distribution used to initialize the latent factors

float LearnRate
getsetinherited

Learning rate alpha

int MaxItemID
getsetinherited

Maximum item ID

int MaxThreads
getset

the maximum number of threads to use

Determines the number of sections the users and items will be divided into.

int MaxUserID
getsetinherited

Maximum user ID

uint NumFactors
getsetinherited

Number of latent factors per user/item

uint NumIter
getsetinherited

Number of iterations over the training data

float RegI
getsetinherited

Regularization parameter for positive item factors

float RegJ
getsetinherited

Regularization parameter for negative item factors

float RegU
getsetinherited

Regularization parameter for user factors

bool UniformUserSampling
getsetinherited

Sample uniformly from users

bool UpdateJ
getsetinherited

If set (default), update factors for negative sampled items during learning

bool WithReplacement
getsetinherited

Sample positive observations with (true) or without (false) replacement


The documentation for this class was generated from the following file: