docstr: BPRMF for Item Recommendation
  
   BPR reduces ranking to pairwise classification. The different variants (settings) of this recommender
   roughly optimize the area under the ROC curve (AUC).
  
  Usage::
  
      >> BprMF(train, test).compute()
      >> BprMF(train, test, batch_size=30).compute()
  
  :param train_file: File which contains the train set. This file needs to have at least 3 columns
  (user item feedback_value).
  :type train_file: str
  
  :param test_file: File which contains the test set. This file needs to have at least 3 columns
  (user item feedback_value).
  :type test_file: str, default None
  
  :param output_file: File with dir to write the final predictions
  :type output_file: str, default None
  
  :param factors: Number of latent factors per user/item
  :type factors: int, default 10
  
  :param learn_rate: Learning rate (alpha)
  :type learn_rate: float, default 0.05
  
  :param epochs: Number of epochs over the training data
  :type epochs: int, default 30
  
  :param batch_size: Reduce number of interactions in each epoch, if 0 usage the number of positive interactions
  in the train set
  :type batch_size: int, default 0
  
  :param rank_length: Size of the rank that must be generated by the predictions of the recommender algorithm
  :type rank_length: int, default 10
  
  :param init_mean: Mean of the normal distribution used to initialize the latent factors
  :type init_mean: float, default 0
  
  :param init_stdev: Standard deviation of the normal distribution used to initialize the latent factors
  :type init_stdev: float, default 0.1
  
  :param reg_u: Regularization parameter for user factors
  :type reg_u: float, default 0.0025
  
  :param reg_i: Regularization parameter for positive item factors
  :type reg_i: float, default 0.0025
  
  :param reg_j: Regularization parameter for negative item factors
  :type reg_j: float, default 0.00025
  
  :param reg_bias: Regularization parameter for the bias term
  :type reg_bias: default 0
  
  :param sep: Delimiter for input files
  :type sep: str, default '       '
  
  :param output_sep: Delimiter for output file
  :type output_sep: str, default '        '
  
  :param random_seed: Number of seed. Lock random numbers for reproducibility of experiments.
  :type random_seed: int, default None
  
  :param items_test: If True, update unobserved set of each user with samples in the test set
  :type items_test: bool, default False
docstr_tok: ["BPRMF","for","Item","Recommendation","BPR","reduces","ranking","to","pairwise","classification",".","The","different","variants","(","settings",")","of","this","recommender","roughly","optimize","the","area","under","the","ROC","curve","(","AUC",")",".","Usage",":",":",">",">","BprMF","(","train",",","test",")",".compute","(",")",">",">","BprMF","(","train",",","test",",","batch_size=30",")",".compute","(",")",":","param","train_file",":","File","which","contains","the","train","set",".","This","file","needs","to","have","at","least","3","columns","(","user","item","feedback_value",")",".",":","type","train_file",":","str",":","param","test_file",":","File","which","contains","the","test","set",".","This","file","needs","to","have","at","least","3","columns","(","user","item","feedback_value",")",".",":","type","test_file",":","str",",","default","None",":","param","output_file",":","File","with","dir","to","write","the","final","predictions",":","type","output_file",":","str",",","default","None",":","param","factors",":","Number","of","latent","factors","per","user\/item",":","type","factors",":","int",",","default","10",":","param","learn_rate",":","Learning","rate","(","alpha",")",":","type","learn_rate",":","float",",","default","0.05",":","param","epochs",":","Number","of","epochs","over","the","training","data",":","type","epochs",":","int",",","default","30",":","param","batch_size",":","Reduce","number","of","interactions","in","each","epoch",",","if","0","usage","the","number","of","positive","interactions","in","the","train","set",":","type","batch_size",":","int",",","default","0",":","param","rank_length",":","Size","of","the","rank","that","must","be","generated","by","the","predictions","of","the","recommender","algorithm",":","type","rank_length",":","int",",","default","10",":","param","init_mean",":","Mean","of","the","normal","distribution","used","to","initialize","the","latent","factors",":","type","init_mean",":","float",",","default","0",":","param","init_stdev",":","Standard","deviation","of","the","normal","distribution","used","to","initialize","the","latent","factors",":","type","init_stdev",":","float",",","default","0.1",":","param","reg_u",":","Regularization","parameter","for","user","factors",":","type","reg_u",":","float",",","default","0.0025",":","param","reg_i",":","Regularization","parameter","for","positive","item","factors",":","type","reg_i",":","float",",","default","0.0025",":","param","reg_j",":","Regularization","parameter","for","negative","item","factors",":","type","reg_j",":","float",",","default","0.00025",":","param","reg_bias",":","Regularization","parameter","for","the","bias","term",":","type","reg_bias",":","default","0",":","param","sep",":","Delimiter","for","input","files",":","type","sep",":","str",",","default","'","'",":","param","output_sep",":","Delimiter","for","output","file",":","type","output_sep",":","str",",","default","'","'",":","param","random_seed",":","Number","of","seed",".","Lock","random","numbers","for","reproducibility","of","experiments",".",":","type","random_seed",":","int",",","default","None",":","param","items_test",":","If","True",",","update","unobserved","set","of","each","user","with","samples","in","the","test","set",":","type","items_test",":","bool",",","default","False"]
code: def __init__(
      self,
      train_file=None,
      test_file=None,
      output_file=None,
      factors=10,
      learn_rate=0.05,
      epochs=30,
      batch_size=0,
      rank_length=10,
      init_mean=0,
      init_stdev=0.1,
      reg_u=0.0025,
      reg_i=0.0025,
      reg_j=0.00025,
      reg_bias=0,
      sep="\t",
      output_sep="\t",
      random_seed=None,
      items_test=False,
  ):
      """
      BPRMF for Item Recommendation
  
       BPR reduces ranking to pairwise classification. The different variants (settings) of this recommender
       roughly optimize the area under the ROC curve (AUC).
  
      Usage::
  
          >> BprMF(train, test).compute()
          >> BprMF(train, test, batch_size=30).compute()
  
      :param train_file: File which contains the train set. This file needs to have at least 3 columns
      (user item feedback_value).
      :type train_file: str
  
      :param test_file: File which contains the test set. This file needs to have at least 3 columns
      (user item feedback_value).
      :type test_file: str, default None
  
      :param output_file: File with dir to write the final predictions
      :type output_file: str, default None
  
      :param factors: Number of latent factors per user/item
      :type factors: int, default 10
  
      :param learn_rate: Learning rate (alpha)
      :type learn_rate: float, default 0.05
  
      :param epochs: Number of epochs over the training data
      :type epochs: int, default 30
  
      :param batch_size: Reduce number of interactions in each epoch, if 0 usage the number of positive interactions
      in the train set
      :type batch_size: int, default 0
  
      :param rank_length: Size of the rank that must be generated by the predictions of the recommender algorithm
      :type rank_length: int, default 10
  
      :param init_mean: Mean of the normal distribution used to initialize the latent factors
      :type init_mean: float, default 0
  
      :param init_stdev: Standard deviation of the normal distribution used to initialize the latent factors
      :type init_stdev: float, default 0.1
  
      :param reg_u: Regularization parameter for user factors
      :type reg_u: float, default 0.0025
  
      :param reg_i: Regularization parameter for positive item factors
      :type reg_i: float, default 0.0025
  
      :param reg_j: Regularization parameter for negative item factors
      :type reg_j: float, default 0.00025
  
      :param reg_bias: Regularization parameter for the bias term
      :type reg_bias: default 0
  
      :param sep: Delimiter for input files
      :type sep: str, default '\t'
  
      :param output_sep: Delimiter for output file
      :type output_sep: str, default '\t'
  
      :param random_seed: Number of seed. Lock random numbers for reproducibility of experiments.
      :type random_seed: int, default None
  
      :param items_test: If True, update unobserved set of each user with samples in the test set
      :type items_test: bool, default False
  
      """
  
      super(BprMF, self).__init__(
          train_file=train_file,
          test_file=test_file,
          output_file=output_file,
          rank_length=rank_length,
          sep=sep,
          output_sep=output_sep,
      )
  
      self.recommender_name = "BPRMF"
  
      self.factors = factors
      self.learn_rate = learn_rate
      self.epochs = epochs
      self.batch_size = batch_size
      self.init_mean = init_mean
      self.init_stdev = init_stdev
      self.reg_bias = reg_bias
      self.reg_u = reg_u
      self.reg_i = reg_i
      self.reg_j = reg_j
      self.items_test = items_test
  
      if random_seed is not None:
          np.random.seed(random_seed)
          random.seed(random_seed)
  
      # internal vars
      self.p = None
      self.q = None
      self.bias = None
      self.num_interactions = None
  
file_path: CaseRecommender/caserec/recommenders/item_recommendation/bprmf.py
imports: import random
  import numpy
  from caserec.recommenders.item_recommendation.base_item_recommendation import BaseItemRecommendation
  from caserec.utils.extra_functions import timed
label_desc: Use image node_id 1 to create a new BprMF object from inherited base classes: BaseItemRecommendation with example: obj = BprMF(train_file, test_file, output_file, factors, learn_rate, epochs, batch_size, rank_length, init_mean, init_stdev, reg_u, reg_i, reg_j, reg_bias, sep, output_sep, random_seed, items_test)