Base class for BPR-MF plus attribute-to-factor mapping. More...
Public Member Functions | |
override void | AddFeedback (int user_id, int item_id) |
Add a positive feedback event 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. | |
abstract void | IterateMapping () |
Perform one iteration of the mapping training. | |
abstract 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 the weight for a given user-item combination. | |
override void | RemoveFeedback (int user_id, int item_id) |
Remove all feedback events by the given user-item combination. | |
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. | |
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) |
void | CheckSampling () |
override void | InitModel () |
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. | |
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 > | attribute_to_factor |
The matrix representing the attribute-to-factor mapping. | |
bool | fast_sampling = false |
Fast, but memory-intensive sampling. | |
int | fast_sampling_memory_limit = 1024 |
Fast sampling memory limit, in MiB. | |
float[] | item_bias |
Item bias terms. | |
Matrix< float > | item_factors |
Latent item factor matrix. | |
double | last_loss = double.NegativeInfinity |
Loss for the last iteration, used by bold driver heuristics. | |
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 | |
System.Random | random |
Random number generator. | |
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. | |
IList< IList< int > > | user_neg_items |
support data structure for fast sampling | |
IList< IList< int > > | user_pos_items |
support data structure for fast sampling | |
Properties | |
float | BiasReg [get, set] |
Regularization parameter for the bias term. | |
bool | BoldDriver [get, set] |
Use bold driver heuristics for learning rate adaption. | |
int | FastSamplingMemoryLimit [get, set] |
Fast sampling memory limit, in MiB. | |
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. | |
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) | |
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 | UpdateJ [get, set] |
If set (default), update factors for negative sampled items during learning. | |
bool | WithReplacement [get, set] |
Sample positive observations with (true) or without (false) replacement. |
Base class for BPR-MF plus attribute-to-factor mapping.
Literature:
override void AddFeedback | ( | int | user_id, | |
int | item_id | |||
) | [inline, virtual, inherited] |
Add a positive feedback event and perform incremental training.
user_id | the user ID | |
item_id | the item ID |
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.
user_id | the user ID | |
item_id | the item ID |
Implements IRecommender.
Object Clone | ( | ) | [inline, inherited] |
create a shallow copy of the object
override float ComputeObjective | ( | ) | [inline, virtual, inherited] |
Compute the current optimization objective (usually loss plus regularization term) of the model.
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 MultiCoreBPRMF.
abstract void IterateMapping | ( | ) | [pure virtual] |
Perform one iteration of the mapping training.
Implemented in BPRMF_ItemMapping, BPRMF_ItemMapping_Optimal, BPRMF_UserMapping, and BPRMF_UserMapping_Optimal.
abstract void LearnAttributeToFactorMapping | ( | ) | [pure virtual] |
Learn the mapping.
Implemented in BPRMF_ItemMapping, BPRMF_ItemMapping_Optimal, BPRMF_ItemMappingKNN, BPRMF_ItemMappingSVR, BPRMF_UserMapping, and BPRMF_UserMapping_Optimal.
override void LoadModel | ( | string | filename | ) | [inline, virtual, inherited] |
Get the model parameters from a file.
filename | the name of the file to read from |
Reimplemented from MF.
override float Predict | ( | int | user_id, | |
int | item_id | |||
) | [inline, virtual, inherited] |
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.
user_id | the user ID | |
item_id | the item ID |
Reimplemented from MF.
Reimplemented in BPRMF_ItemMapping, and BPRMF_UserMapping.
override void RemoveFeedback | ( | int | user_id, | |
int | item_id | |||
) | [inline, virtual, inherited] |
Remove all feedback events by the given user-item combination.
user_id | the user ID | |
item_id | the item ID |
Reimplemented from IncrementalItemRecommender.
override void RemoveItem | ( | int | item_id | ) | [inline, virtual, inherited] |
Remove all feedback by one item.
item_id | the item ID |
Reimplemented from IncrementalItemRecommender.
override void RemoveUser | ( | int | user_id | ) | [inline, virtual, inherited] |
Remove all feedback by one user.
user_id | the user ID |
Reimplemented from IncrementalItemRecommender.
virtual void RetrainItem | ( | int | item_id | ) | [inline, protected, virtual, inherited] |
Retrain the latent factors of a given item.
item_id | the item ID |
virtual void RetrainUser | ( | int | user_id | ) | [inline, protected, virtual, inherited] |
Retrain the latent factors of a given user.
user_id | the user ID |
virtual void SampleItemPair | ( | int | u, | |
out int | i, | |||
out int | j | |||
) | [inline, protected, virtual, inherited] |
Sample a pair of items, given a user.
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 | |||
) | [inline, protected, virtual, inherited] |
Sample another item, given the first one and the user.
u | the user ID | |
i | the ID of the given item | |
j | the ID of the other item |
virtual void SampleTriple | ( | out int | u, | |
out int | i, | |||
out int | j | |||
) | [inline, protected, virtual, inherited] |
Sample a triple for BPR learning.
u | the user ID | |
i | the ID of the first item | |
j | the ID of the second item |
Reimplemented in WeightedBPRMF.
virtual int SampleUser | ( | ) | [inline, protected, virtual, inherited] |
Sample a user that has viewed at least one and not all items.
override void SaveModel | ( | string | filename | ) | [inline, virtual, inherited] |
Save the model parameters to a file.
filename | the name of the file to write to |
Reimplemented from MF.
override string ToString | ( | ) | [inline, inherited] |
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 ItemRecommender.
Reimplemented in BPRMF_ItemMapping, BPRMF_ItemMapping_Optimal, BPRMF_ItemMappingKNN, BPRMF_ItemMappingSVR, BPRMF_UserMapping, BPRMF_UserMapping_Optimal, MultiCoreBPRMF, SoftMarginRankingMF, and WeightedBPRMF.
virtual void UpdateFactors | ( | int | u, | |
int | i, | |||
int | j, | |||
bool | update_u, | |||
bool | update_i, | |||
bool | update_j | |||
) | [inline, protected, virtual, inherited] |
Update latent factors according to the stochastic gradient descent update rule.
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 in SoftMarginRankingMF.
Matrix<float> attribute_to_factor [protected] |
The matrix representing the attribute-to-factor mapping.
includes bias
bool fast_sampling = false [protected, inherited] |
Fast, but memory-intensive sampling.
int fast_sampling_memory_limit = 1024 [protected, inherited] |
Fast sampling memory limit, in MiB.
float [] item_bias [protected, inherited] |
Item bias terms.
Matrix<float> item_factors [protected, inherited] |
Latent item factor matrix.
double last_loss = double.NegativeInfinity [protected, inherited] |
Loss for the last iteration, used by bold driver heuristics.
float learn_rate = 0.05f [protected, inherited] |
Learning rate alpha.
double learn_rate_mapping = 0.01 [protected] |
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] |
number of times the regression is computed (to avoid local minima)
may be ignored by the recommender
int num_iter_mapping = 10 [protected] |
number of iterations of the mapping training procedure
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] |
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.
IList<IList<int> > user_neg_items [protected, inherited] |
support data structure for fast sampling
IList<IList<int> > user_pos_items [protected, inherited] |
support data structure for fast sampling
float BiasReg [get, set, inherited] |
Regularization parameter for the bias term.
bool BoldDriver [get, set, inherited] |
Use bold driver heuristics for learning rate adaption.
Does not work too well for BPR-MF.
Literature:
int FastSamplingMemoryLimit [get, set, inherited] |
Fast sampling memory limit, in MiB.
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.
float LearnRate [get, set, inherited] |
Learning rate alpha.
double LearnRateMapping [get, set] |
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] |
number of times the regression is computed (to avoid local minima)
may be ignored by the recommender
uint NumIter [get, set, inherited] |
Number of iterations over the training data.
Implements IIterativeModel.
int NumIterMapping [get, set] |
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] |
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 UpdateJ [get, set, inherited] |
If set (default), update factors for negative sampled items during learning.
bool WithReplacement [get, set, inherited] |
Sample positive observations with (true) or without (false) replacement.