Sparse Linear Methods (SLIM) for item prediction (ranking) optimized for BPR-Opt optimization criterion
More...
Public Member Functions |
virtual void | AddFeedback (ICollection< Tuple< int, int >> feedback) |
| Add positive feedback events and perform incremental training
|
| BPRSLIM () |
| Default constructor
|
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 the fit (AUC on training data)
|
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 rating or score for a given user-item combination
|
double | PredictWithDifference (int user_id, int pos_item_id, int neg_item_id) |
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) |
virtual 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
|
virtual void | RemoveUser (int user_id) |
| Remove all feedback by one user
|
override void | SaveModel (string file) |
| Save the model parameters to a file
|
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 | RetrainItem (int item_id) |
| Retrain the latent factors of a given item
|
virtual void | SampleItemPair (int u, out int i, out int j) |
| Sample a pair of items, given a user
|
virtual bool | SampleOtherItem (int u, int i, out int j) |
| Sample another item, given the first one and the user
|
virtual void | SampleTriple (out int u, out int i, out int j) |
| Sample a triple for BPR learning
|
virtual int | SampleUser () |
| Sample a user that has viewed at least one and not all items
|
virtual 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 |
Matrix< float > | item_weights |
| Item weight matrix (the W matrix in the original paper)
|
ItemKNN | itemKNN |
| The item KNN used in the feature selection step
|
double | learn_rate = 0.05 |
| Learning rate alpha
|
System.Random | random |
| Random number generator
|
double | reg_i = 0.0025 |
| Regularization parameter for positive item weights
|
double | reg_j = 0.00025 |
| Regularization parameter for negative item weights
|
bool | update_j = true |
| If set (default), update factors for negative sampled items during learning
|
Properties |
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
|
double | LearnRate [get, set] |
| Learning rate alpha
|
int | MaxItemID [get, set] |
| Maximum item ID
|
int | MaxUserID [get, set] |
| Maximum user ID
|
uint | NumIter [get, set] |
| Number of iterations over the training data
|
double | RegI [get, set] |
| Regularization parameter for positive item weights
|
double | RegJ [get, set] |
| Regularization parameter for negative item weights
|
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
Sparse Linear Methods (SLIM) for item prediction (ranking) optimized for BPR-Opt optimization criterion
This implementation differs from the algorithm in the original SLIM paper since the model here is optimized for BPR-Opt instead of the elastic net loss. The optmization algorithm used is the Sotchastic Gradient Ascent.
Literature:
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.
Constructor & Destructor Documentation
Member Function Documentation
virtual void AddFeedback |
( |
ICollection< Tuple< int, int >> |
feedback | ) |
|
|
inlinevirtualinherited |
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 the fit (AUC on training data)
- Returns
- the fit
Implements SLIM.
override void Iterate |
( |
| ) |
|
|
inlinevirtual |
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 SLIM.
override void LoadModel |
( |
string |
filename | ) |
|
|
inlinevirtual |
Get the model parameters from a file
- Parameters
-
filename | the name of the file to read from |
Reimplemented from SLIM.
override float Predict |
( |
int |
user_id, |
|
|
int |
item_id |
|
) |
| |
|
inlinevirtualinherited |
Predict rating or score for a given user-item combination
- Parameters
-
user_id | the user ID |
item_id | the item ID |
- Returns
- the predicted score/rating for the given user-item combination
Implements Recommender.
Reimplemented in LeastSquareSLIM.
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.
virtual void RemoveFeedback |
( |
ICollection< Tuple< int, int >> |
feedback | ) |
|
|
inlinevirtualinherited |
override void RemoveItem |
( |
int |
item_id | ) |
|
|
inlinevirtual |
virtual void RemoveUser |
( |
int |
user_id | ) |
|
|
inlinevirtualinherited |
virtual void RetrainItem |
( |
int |
item_id | ) |
|
|
inlineprotectedvirtual |
Retrain the latent factors of a given item
- Parameters
-
virtual void SampleItemPair |
( |
int |
u, |
|
|
out int |
i, |
|
|
out int |
j |
|
) |
| |
|
inlineprotectedvirtual |
Sample a pair of items, given a user
- Parameters
-
u | the user ID |
i | the ID of the first item |
j | the ID of the second item |
virtual bool SampleOtherItem |
( |
int |
u, |
|
|
int |
i, |
|
|
out int |
j |
|
) |
| |
|
inlineprotectedvirtual |
Sample another item, given the first one and the user
- Parameters
-
u | the user ID |
i | the ID of the given item |
j | the ID of the other item |
- Returns
- true if the given item was already seen by user u
virtual void SampleTriple |
( |
out int |
u, |
|
|
out int |
i, |
|
|
out int |
j |
|
) |
| |
|
inlineprotectedvirtual |
Sample a triple for BPR learning
- Parameters
-
u | the user ID |
i | the ID of the first item |
j | the ID of the second item |
virtual int SampleUser |
( |
| ) |
|
|
inlineprotectedvirtual |
Sample a user that has viewed at least one and not all items
- Returns
- the user ID
override void SaveModel |
( |
string |
filename | ) |
|
|
inlinevirtual |
Save the model parameters to a file
- Parameters
-
filename | the name of the file to write to |
Reimplemented from SLIM.
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 Recommender.
Learn the model parameters of the recommender from the training data
Reimplemented from SLIM.
virtual 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 |
Member Data Documentation
Matrix<float> item_weights |
|
protectedinherited |
Item weight matrix (the W matrix in the original paper)
The item KNN used in the feature selection step
Regularization parameter for positive item weights
Regularization parameter for negative item weights
If set (default), update factors for negative sampled items during learning
Property Documentation
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 iterations over the training data
Regularization parameter for positive item weights
Regularization parameter for negative item weights
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: