MyMediaLite  3.07
Public Member Functions | Protected Member Functions | Protected Attributes | Static Protected Attributes | Properties
BPRMF_ItemMapping_Optimal Class Reference

item attribute to latent factor mapping, optimized for BPR loss More...

Inheritance diagram for BPRMF_ItemMapping_Optimal:
BPRMF_ItemMapping BPRMF_Mapping IItemAttributeAwareRecommender BPRMF IRecommender MF IFoldInItemRecommender IncrementalItemRecommender IIterativeModel IRecommender ItemRecommender IIncrementalItemRecommender Recommender IIncrementalRecommender IRecommender

List of all members.

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 the current optimization objective (usually loss plus regularization term) of the model.
override void Iterate ()
 Perform one iteration of stochastic gradient ascent over the training data.
override void IterateMapping ()
 Perform one iteration of the mapping learning process.
override void LearnAttributeToFactorMapping ()
 Learn the mapping.
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.
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 float[] __MapToLatentFactorSpace (int item_id)
 map to latent factor space (actual function)
override void AddItem (int item_id)
override void AddUser (int user_id)
double[] ComputeMappingFit ()
 Compute the fit of the mapping.
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 float[] MapToLatentFactorSpace (int item_id)
 map to latent factor space (method to be called)
virtual void RetrainItem (int item_id)
 Retrain the latent factors of a given item.
virtual void RetrainUser (int user_id)
 Retrain the latent factors of a given user.
int SampleItem ()
 Samples an item for the mapping training. Only items that are associated with at least one user are taken into account.
virtual void SampleItemPair (int user_id, 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.
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.
virtual void UpdateMappingFactors (int u, int i, int j)
 update the mapping factors for a given user and an item pair

Protected Attributes

Func< int, float[]> _MapToLatentFactorSpace
 map to latent factor space (field)
Matrix< float > attribute_to_factor
 The matrix representing the attribute-to-factor mapping.
float[] factor_bias
 array to store the bias for each mapping
IBooleanMatrix item_attributes
 The matrix storing the item attributes.
float[] item_bias
 Item bias terms.
Matrix< float > item_factors
 Latent item factor matrix.
float learn_rate = 0.05f
 Learning rate alpha.
double learn_rate_mapping = 0.01
 The learn rate for training the mapping functions.
int num_factors = 10
 Number of latent factors per user/item.
int num_init_mapping = 5
 number of times the regression is computed (to avoid local minima)
int num_iter_mapping = 10
 number of iterations of the mapping training procedure
float reg_i = 0.0025f
 Regularization parameter for positive item factors.
float reg_j = 0.00025f
 Regularization parameter for negative item factors.
double reg_mapping = 0.1
 regularization constant for the mapping
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.
IBooleanMatrix ItemAttributes [get, set]
float LearnRate [get, set]
 Learning rate alpha.
double LearnRateMapping [get, set]
 The learn rate for training the mapping functions.
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.
int NumInitMapping [get, set]
 number of times the regression is computed (to avoid local minima)
int NumItemAttributes [get, set]
uint NumIter [get, set]
 Number of iterations over the training data.
int NumIterMapping [get, set]
 number of iterations of the mapping training procedure
float RegI [get, set]
 Regularization parameter for positive item factors.
float RegJ [get, set]
 Regularization parameter for negative item factors.
double RegMapping [get, set]
 regularization constant for the mapping
float RegU [get, set]
 Regularization parameter for user factors.
bool UniformUserSampling [get, set]
 Sample uniformly from users.
bool UpdateItems [get, set]
 true if items shall be updated when doing incremental updates
bool UpdateJ [get, set]
 If set (default), update factors for negative sampled items during learning.
bool UpdateUsers [get, set]
 true if users shall be updated when doing incremental updates
bool WithReplacement [get, set]
 Sample positive observations with (true) or without (false) replacement.

Detailed Description

item attribute to latent factor mapping, optimized for BPR loss

Literature:

This recommender does NOT support incremental updates.


Member Function Documentation

override float [] __MapToLatentFactorSpace ( int  item_id) [inline, protected, virtual]

map to latent factor space (actual function)

Reimplemented from BPRMF_ItemMapping.

override void AddFeedback ( ICollection< Tuple< int, int >>  feedback) [inline, virtual, inherited]

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 
) [inline, virtual, inherited]

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 ( ) [inline, inherited]

create a shallow copy of the object

double [] ComputeMappingFit ( ) [inline, protected, inherited]

Compute the fit of the mapping.

Returns:
an array of doubles containing the RMSE on the training data for each latent factor
override float ComputeObjective ( ) [inline, virtual, inherited]

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 ( ) [inline, virtual, inherited]

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.

Reimplemented in BPRMF_Mapping.

override void IterateMapping ( ) [inline, virtual]

Perform one iteration of the mapping learning process.

Reimplemented from BPRMF_ItemMapping.

virtual void IterateWithoutReplacementUniformPair ( ) [inline, protected, virtual, inherited]

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

Reimplemented in MultiCoreBPRMF.

virtual void IterateWithoutReplacementUniformPair ( IList< int >  indices) [inline, protected, virtual, inherited]

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

virtual void IterateWithoutReplacementUniformUser ( ) [inline, protected, virtual, inherited]

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

virtual void IterateWithReplacementUniformPair ( ) [inline, protected, virtual, inherited]

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

virtual void IterateWithReplacementUniformUser ( ) [inline, protected, virtual, inherited]

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

override void LearnAttributeToFactorMapping ( ) [inline, virtual]

Learn the mapping.

Reimplemented from BPRMF_ItemMapping.

override void LoadModel ( string  filename) [inline, virtual, inherited]

Get the model parameters from a file.

Parameters:
filenamethe name of the file to read from

Reimplemented from MF.

override float [] MapToLatentFactorSpace ( int  item_id) [inline, protected, virtual]

map to latent factor space (method to be called)

Reimplemented from BPRMF_ItemMapping.

override float Predict ( int  user_id,
int  item_id 
) [inline, inherited]

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) [inline, virtual, inherited]

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) [inline, virtual, inherited]

Remove all feedback by one item.

Parameters:
item_idthe item ID

Reimplemented from IncrementalItemRecommender.

override void RemoveUser ( int  user_id) [inline, virtual, inherited]

Remove all feedback by one user.

Parameters:
user_idthe user ID

Reimplemented from IncrementalItemRecommender.

virtual void RetrainItem ( int  item_id) [inline, protected, virtual, inherited]

Retrain the latent factors of a given item.

Parameters:
item_idthe item ID
virtual void RetrainUser ( int  user_id) [inline, protected, virtual, inherited]

Retrain the latent factors of a given user.

Parameters:
user_idthe user ID
int SampleItem ( ) [inline, protected, inherited]

Samples an item for the mapping training. Only items that are associated with at least one user are taken into account.

Returns:
the item ID
virtual void SampleItemPair ( int  user_id,
out int  item_id,
out int  other_item_id 
) [inline, protected, virtual, inherited]

Sample a pair of items, given a user.

Parameters:
user_idthe user ID
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 
) [inline, protected, virtual, inherited]

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 
) [inline, protected, virtual, inherited]

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 ( ) [inline, protected, virtual, inherited]

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

Returns:
the user ID
override void SaveModel ( string  filename) [inline, virtual, inherited]

Save the model parameters to a file.

Parameters:
filenamethe name of the file to write to

Reimplemented from MF.

IList<Tuple<int, float> > ScoreItems ( IList< int >  accessed_items,
IList< int >  candidate_items 
) [inline, inherited]

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.

Reimplemented from BPRMF_ItemMapping.

virtual void UpdateFactors ( int  user_id,
int  item_id,
int  other_item_id,
bool  update_u,
bool  update_i,
bool  update_j 
) [inline, protected, virtual, inherited]

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.

virtual void UpdateMappingFactors ( int  u,
int  i,
int  j 
) [inline, protected, virtual]

update the mapping factors for a given user and an item pair

Parameters:
uthe user ID
ithe first item ID
jthe second item ID

Member Data Documentation

Func<int, float[]> _MapToLatentFactorSpace [protected, inherited]

map to latent factor space (field)

Matrix<float> attribute_to_factor [protected, inherited]

The matrix representing the attribute-to-factor mapping.

includes bias

float [] factor_bias [protected, inherited]

array to store the bias for each mapping

IBooleanMatrix item_attributes [protected, inherited]

The matrix storing the item attributes.

float [] item_bias [protected, inherited]

Item bias terms.

Matrix<float> item_factors [protected, inherited]

Latent item factor matrix.

float learn_rate = 0.05f [protected, inherited]

Learning rate alpha.

double learn_rate_mapping = 0.01 [protected, inherited]

The learn rate for training the mapping functions.

int num_factors = 10 [protected, inherited]

Number of latent factors per user/item.

int num_init_mapping = 5 [protected, inherited]

number of times the regression is computed (to avoid local minima)

may be ignored by the recommender

int num_iter_mapping = 10 [protected, inherited]

number of iterations of the mapping training procedure

System.Random random [static, protected, inherited]

Reference to (per-thread) singleton random number generator.

float reg_i = 0.0025f [protected, inherited]

Regularization parameter for positive item factors.

float reg_j = 0.00025f [protected, inherited]

Regularization parameter for negative item factors.

double reg_mapping = 0.1 [protected, inherited]

regularization constant for the mapping

float reg_u = 0.0025f [protected, inherited]

Regularization parameter for user factors.

bool update_j = true [protected, inherited]

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

Matrix<float> user_factors [protected, inherited]

Latent user factor matrix.


Property Documentation

float BiasReg [get, set, inherited]

Regularization parameter for the bias term.

virtual IPosOnlyFeedback Feedback [get, set, inherited]

the feedback data to be used for training

double InitMean [get, set, inherited]

Mean of the normal distribution used to initialize the latent factors.

double InitStdDev [get, set, inherited]

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

IBooleanMatrix ItemAttributes [get, set, inherited]

the binary item attributes

Implements IItemAttributeAwareRecommender.

float LearnRate [get, set, inherited]

Learning rate alpha.

double LearnRateMapping [get, set, inherited]

The learn rate for training the mapping functions.

int MaxItemID [get, set, inherited]

Maximum item ID.

int MaxUserID [get, set, inherited]

Maximum user ID.

uint NumFactors [get, set, inherited]

Number of latent factors per user/item.

int NumInitMapping [get, set, inherited]

number of times the regression is computed (to avoid local minima)

may be ignored by the recommender

int NumItemAttributes [get, set, inherited]

an integer stating the number of attributes

Implements IItemAttributeAwareRecommender.

uint NumIter [get, set, inherited]

Number of iterations over the training data.

Implements IIterativeModel.

int NumIterMapping [get, set, inherited]

number of iterations of the mapping training procedure

float RegI [get, set, inherited]

Regularization parameter for positive item factors.

float RegJ [get, set, inherited]

Regularization parameter for negative item factors.

double RegMapping [get, set, inherited]

regularization constant for the mapping

float RegU [get, set, inherited]

Regularization parameter for user factors.

bool UniformUserSampling [get, set, inherited]

Sample uniformly from users.

bool UpdateItems [get, set, inherited]

true if items shall be updated when doing incremental updates

Set to false if you do not want any updates to the item model parameters when doing incremental updates.

Implements IIncrementalRecommender.

bool UpdateJ [get, set, inherited]

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

bool UpdateUsers [get, set, inherited]

true if users shall be updated when doing incremental updates

Default should be true. Set to false if you do not want any updates to the user model parameters when doing incremental updates.

Implements IIncrementalRecommender.

bool WithReplacement [get, set, inherited]

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


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