code: def test_sampling_funct(init_rbm, affinity_matrix):
      # obtain the train/test set matrices
      Xtr, _ = affinity_matrix
  
      # initialize the model
      model = RBM(
          possible_ratings=np.setdiff1d(np.unique(Xtr), np.array([0])),
          visible_units=Xtr.shape[1],
          hidden_units=init_rbm["n_hidden"],
          training_epoch=init_rbm["epochs"],
          minibatch_size=init_rbm["minibatch"],
      )
  
      def check_sampled_values(sampled, s):
          """
          Check if the elements of the sampled units are in {0,s}
          """
          a = []
  
          for i in range(0, s + 1):
              l_bool = sampled == i
              a.append(l_bool)
  
          return sum(a)
  
      r = Xtr.max()  # obtain the rating scale
  
      # fit the model to the data
      model.fit(Xtr)
  
      # evaluate the activation probabilities of the hidden units and their sampled values
      phv, h = model.sess.run(model.sample_hidden_units(model.v))
  
      # check the dimensions of the two matrices
      assert phv.shape == (Xtr.shape[0], 100)
      assert h.shape == (Xtr.shape[0], 100)
  
      # check that the activation probabilities are in [0,1]
      assert (phv <= 1).all() & (phv >= 0).all()
  
      # check that the sampled value of the hidden units is either 1 or 0
      assert check_sampled_values(h, 1).all()
  
      # evaluate the activation probabilities of the visible units and their sampled values
      pvh, v_sampled = model.sess.run(model.sample_visible_units(h))
  
      assert pvh.shape == (Xtr.shape[0], Xtr.shape[1], r)
      assert v_sampled.shape == Xtr.shape
  
      # check that the multinomial distribution is normalized over the r classes for all users/items
      assert np.sum(pvh, axis=2) == pytest.approx(np.ones(Xtr.shape))
  
      # check that the sampled values of the visible units is in [0,r]
      assert check_sampled_values(v_sampled, r).all()
  
imports: import pytest
  import numpy
label_desc: Use image node_id 4 for calling a global function with example usage: test_sampling_funct(init_rbm, affinity_matrix) and returns: sum