Matrix factorization model for item prediction optimized for a soft margin (hinge) ranking loss, using stochastic gradient descent (as in BPR-MF).
More...
Public Member Functions |
override void | AddFeedback (ICollection< Tuple< int, int >> feedback) |
| Add positive feedback events and perform incremental training
|
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
|
Object | Clone () |
| create a shallow copy of the object
|
override float | ComputeObjective () |
| Compute approximate loss
|
override void | Iterate () |
| Perform one iteration of stochastic gradient ascent over the training data
|
override void | LoadModel (string file) |
| Get the model parameters from a file
|
override float | Predict (int user_id, int item_id) |
| Predict the weight for a given user-item combination
|
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
|
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
|
override void | RemoveItem (int item_id) |
| Remove all feedback by one item
|
override void | RemoveUser (int user_id) |
| Remove all feedback by one user
|
override void | SaveModel (string file) |
| Save the model parameters to a file
|
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
|
override string | ToString () |
| Return a string representation of the recommender
|
override void | Train () |
| Learn the model parameters of the recommender from the training data
|
Protected Member Functions |
override void | AddItem (int item_id) |
override void | AddUser (int user_id) |
override void | InitModel () |
virtual void | IterateWithoutReplacementUniformPair () |
| Iterate over the training data, uniformly sample from user-item pairs without replacement.
|
virtual void | IterateWithoutReplacementUniformPair (IList< int > indices) |
| Iterate over the training data, uniformly sample from user-item pairs without replacement.
|
virtual void | IterateWithoutReplacementUniformUser () |
| Iterate over the training data, uniformly sample from users without replacement.
|
virtual void | IterateWithReplacementUniformPair () |
| Iterate over the training data, uniformly sample from user-item pairs with replacement.
|
virtual void | IterateWithReplacementUniformUser () |
| Iterate over the training data, uniformly sample from users with replacement.
|
override void | RetrainItem (int item_id) |
| Retrain the latent factors of a given item
|
override void | RetrainUser (int user_id) |
| Retrain the latent factors of a given user
|
virtual void | SampleItemPair (ICollection< int > user_items, out int item_id, out int other_item_id) |
| Sample a pair of items, given a user
|
virtual bool | SampleOtherItem (int user_id, int item_id, out int other_item_id) |
| Sample another item, given the first one and the user
|
virtual void | SampleTriple (out int user_id, out int item_id, out int other_item_id) |
| Sample a triple for BPR learning
|
virtual int | SampleUser () |
| Uniformly sample a user that has viewed at least one and not all items
|
override void | UpdateFactors (int u, int i, int j, bool update_u, bool update_i, bool update_j) |
| Update latent factors according to the stochastic gradient descent update rule
|
Protected Attributes |
float[] | item_bias |
| Item bias terms
|
Matrix< float > | item_factors |
| Latent item factor matrix
|
float | learn_rate = 0.05f |
| Learning rate alpha
|
int | num_factors = 10 |
| Number of latent factors per user/item
|
float | reg_i = 0.0025f |
| Regularization parameter for positive item factors
|
float | reg_j = 0.00025f |
| Regularization parameter for negative item factors
|
float | reg_u = 0.0025f |
| Regularization parameter for user factors
|
bool | update_j = true |
| If set (default), update factors for negative sampled items during learning
|
Matrix< float > | user_factors |
| Latent user factor matrix
|
Static Protected Attributes |
static System.Random | random |
| Reference to (per-thread) singleton random number generator
|
Properties |
float | BiasReg [get, set] |
| Regularization parameter for the bias term
|
virtual IPosOnlyFeedback | Feedback [get, set] |
| the feedback data to be used for training
|
double | InitMean [get, set] |
| Mean of the normal distribution used to initialize the latent factors
|
double | InitStdDev [get, set] |
| Standard deviation of the normal distribution used to initialize the latent factors
|
float | LearnRate [get, set] |
| Learning rate alpha
|
int | MaxItemID [get, set] |
| Maximum item ID
|
int | MaxUserID [get, set] |
| Maximum user ID
|
uint | NumFactors [get, set] |
| Number of latent factors per user/item
|
uint | NumIter [get, set] |
| Number of iterations over the training data
|
float | RegI [get, set] |
| Regularization parameter for positive item factors
|
float | RegJ [get, set] |
| Regularization parameter for negative item factors
|
float | RegU [get, set] |
| Regularization parameter for user factors
|
bool | UniformUserSampling [get, set] |
| Sample uniformly from users
|
bool | UpdateItems [get, set] |
bool | UpdateJ [get, set] |
| If set (default), update factors for negative sampled items during learning
|
bool | UpdateUsers [get, set] |
bool | WithReplacement [get, set] |
| Sample positive observations with (true) or without (false) replacement
|
Detailed Description
Matrix factorization model for item prediction optimized for a soft margin (hinge) ranking loss, using stochastic gradient descent (as in BPR-MF).
Literature:
This recommender supports incremental updates.
Member Function Documentation
override void AddFeedback |
( |
ICollection< Tuple< int, int >> |
feedback | ) |
|
|
inlinevirtualinherited |
Add positive feedback events and perform incremental training
- Parameters
-
feedback | collection 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_id | the user ID |
item_id | the 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.
create a shallow copy of the object
override float ComputeObjective |
( |
| ) |
|
|
inlinevirtual |
Compute approximate loss
- Returns
- the approximate loss
Reimplemented from BPRMF.
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.
virtual void IterateWithoutReplacementUniformPair |
( |
| ) |
|
|
inlineprotectedvirtualinherited |
Iterate over the training data, uniformly sample from user-item pairs without replacement.
Reimplemented in MultiCoreBPRMF.
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 | ) |
|
|
inlinevirtualinherited |
Get the model parameters from a file
- Parameters
-
filename | the name of the file to read from |
Reimplemented from MF.
override float Predict |
( |
int |
user_id, |
|
|
int |
item_id |
|
) |
| |
|
inlinevirtualinherited |
Predict the weight for a given user-item combination
If the user or the item are not known to the recommender, zero is returned. To avoid this behavior for unknown entities, use CanPredict() to check before.
- Parameters
-
user_id | the user ID |
item_id | the item ID |
- Returns
- the predicted weight
Reimplemented from MF.
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_id | the user ID |
n | the number of items to recommend, -1 for as many as possible |
ignore_items | collection if items that should not be returned; if null, use empty collection |
candidate_items | the 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
-
feedback | collection of user id - item id tuples |
Reimplemented from IncrementalItemRecommender.
override void RemoveItem |
( |
int |
item_id | ) |
|
|
inlinevirtualinherited |
Remove all feedback by one item
- Parameters
-
Reimplemented from MF.
override void RemoveUser |
( |
int |
user_id | ) |
|
|
inlinevirtualinherited |
override void RetrainItem |
( |
int |
item_id | ) |
|
|
inlineprotectedvirtualinherited |
Retrain the latent factors of a given item
- Parameters
-
Implements MF.
override void RetrainUser |
( |
int |
user_id | ) |
|
|
inlineprotectedvirtualinherited |
Retrain the latent factors of a given user
- Parameters
-
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_items | the items accessed by the given user |
item_id | the ID of the first item |
other_item_id | the 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_id | the user ID |
item_id | the ID of the given item |
other_item_id | the 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_id | the user ID |
item_id | the ID of the first item |
other_item_id | the 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 | ) |
|
|
inlinevirtualinherited |
Save the model parameters to a file
- Parameters
-
filename | the name of the file to write to |
Reimplemented from MF.
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_items | the ratings (item IDs and rating values) representing the new user |
candidate_items | the 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.
Reimplemented from BPRMF.
override void UpdateFactors |
( |
int |
u, |
|
|
int |
i, |
|
|
int |
j, |
|
|
bool |
update_u, |
|
|
bool |
update_i, |
|
|
bool |
update_j |
|
) |
| |
|
inlineprotectedvirtual |
Update latent factors according to the stochastic gradient descent update rule
- Parameters
-
u | the user ID |
i | the ID of the first item |
j | the ID of the second item |
update_u | if true, update the user latent factors |
update_i | if true, update the latent factors of the first item |
update_j | if true, update the latent factors of the second item |
Reimplemented from BPRMF.
Member Data Documentation
Matrix<float> item_factors |
|
protectedinherited |
Latent item factor matrix
Number of latent factors per user/item
Reference to (per-thread) singleton random number generator
Regularization parameter for positive item factors
Regularization parameter for negative item factors
Regularization parameter for user factors
If set (default), update factors for negative sampled items during learning
Matrix<float> user_factors |
|
protectedinherited |
Latent user factor matrix
Property Documentation
Regularization parameter for the bias term
the feedback data to be used for training
Mean of the normal distribution used to initialize the latent factors
Standard deviation of the normal distribution used to initialize the latent factors
Number of latent factors per user/item
Number of iterations over the training data
Regularization parameter for positive item factors
Regularization parameter for negative item factors
Regularization parameter for user factors
Sample uniformly from users
If set (default), update factors for negative sampled items during learning
Sample positive observations with (true) or without (false) replacement
The documentation for this class was generated from the following file: