class_docstr: Restricted  Boltzmann Machine
class_docstr_tok: ["Restricted","Boltzmann","Machine"]
docstr: Fit method
  
  Training in generative models takes place in two steps:
  
  1) Gibbs sampling
  2) Gradient evaluation and parameters update
  
  This estimate is later used in the weight update step by minimizing the distance between the
  model and the empirical free energy. Note that while the unit's configuration space is sampled,
  the weights are determined via maximum likelihood (saddle point).
  
  Main component of the algo; once instantiated, it generates the computational graph and performs
  model training
  
  Args:
      xtr (numpy.ndarray, integers): the user/affinity matrix for the train set
      xtst (numpy.ndarray, integers): the user/affinity matrix for the test set
docstr_tok: ["Fit","method","Training","in","generative","models","takes","place","in","two","steps",":","1",")","Gibbs","sampling","2",")","Gradient","evaluation","and","parameters","update","This","estimate","is","later","used","in","the","weight","update","step","by","minimizing","the","distance","between","the","model","and","the","empirical","free","energy",".","Note","that","while","the","unit","'s","configuration","space","is","sampled",",","the","weights","are","determined","via","maximum","likelihood","(","saddle","point",")",".","Main","component","of","the","algo",";","once","instantiated",",","it","generates","the","computational","graph","and","performs","model","training","Args",":","xtr","(","numpy.ndarray",",","integers",")",":","the","user\/affinity","matrix","for","the","train","set","xtst","(","numpy.ndarray",",","integers",")",":","the","user\/affinity","matrix","for","the","test","set"]
code: def fit(self, xtr):
      """Fit method
  
      Training in generative models takes place in two steps:
  
      1) Gibbs sampling
      2) Gradient evaluation and parameters update
  
      This estimate is later used in the weight update step by minimizing the distance between the
      model and the empirical free energy. Note that while the unit's configuration space is sampled,
      the weights are determined via maximum likelihood (saddle point).
  
      Main component of the algo; once instantiated, it generates the computational graph and performs
      model training
  
      Args:
          xtr (numpy.ndarray, integers): the user/affinity matrix for the train set
          xtst (numpy.ndarray, integers): the user/affinity matrix for the test set
      """
  
      # keep the position of the items in the train set so that they can be optionally exluded from recommendation
      self.seen_mask = np.not_equal(xtr, 0)
  
      n_users = xtr.shape[0]
      num_minibatches = int(
          n_users / self.minibatch
      )  # number of minibatches
  
      self.init_training_session(xtr)
  
      rmse_train = []  # List to collect the metrics across epochs
  
      # start loop over training epochs
      for i in range(self.epochs):
          self.gibbs_protocol(i)  # Gibbs sampling update
          epoch_tr_err = self.batch_training(
              num_minibatches
          )  # model train
  
          if self.with_metrics and i % self.display_epoch == 0:
              log.info("training epoch %i rmse %f" % (i, epoch_tr_err))
  
          rmse_train.append(
              epoch_tr_err
          )  # mse training error per training epoch
  
      self.rmse_train = rmse_train
  
imports: import numpy
  import tensorflow
  import logging
  import os
  from pathlib import Path
label_desc: Use image node_id 19 for calling the RBM obj's underlying member method code with example usage: obj.fit(xtr) without return types