class_docstr: Restricted  Boltzmann Machine
class_docstr_tok: ["Restricted","Boltzmann","Machine"]
docstr: Sample the visible units given the hiddens. This can be thought of as a Backward pass in a FFN
  (negative phase). Each visible unit can take values in [1,rating], while the zero is reserved
  for missing data; as such the value of the hidden unit is sampled from a multinomial distribution.
  
  Basic mechanics:
  
  1) For every training example we first sample Nv Multinomial distributions. The result is of the
  form [0,1,0,0,0,...,0] where the index of the 1 element corresponds to the rth rating. The index
  is extracted using the argmax function and we need to add 1 at the end since array indeces starts
  from 0.
  
  2) Selects only those units that have been sampled. During the training phase it is important to not
  use the reconstructed inputs, so we beed to enforce a zero value in the reconstructed ratings in
  the same position as the original input.
  
  Args:
      h (tf.Tensor, float32): visible units.
  
  Returns:
      tf.Tensor, tf.Tensor:
      - `pvh`: The activation probability of the visible unit given the hidden.
      - `v_`: The sampled value of the visible unit from a Multinomial distributions having success probability `pvh`.
docstr_tok: ["Sample","the","visible","units","given","the","hiddens",".","This","can","be","thought","of","as","a","Backward","pass","in","a","FFN","(","negative","phase",")",".","Each","visible","unit","can","take","values","in","[","1",",","rating","]",",","while","the","zero","is","reserved","for","missing","data",";","as","such","the","value","of","the","hidden","unit","is","sampled","from","a","multinomial","distribution",".","Basic","mechanics",":","1",")","For","every","training","example","we","first","sample","Nv","Multinomial","distributions",".","The","result","is","of","the","form","[","0,1,0,0,0",",","...",",0","]","where","the","index","of","the","1","element","corresponds","to","the","rth","rating",".","The","index","is","extracted","using","the","argmax","function","and","we","need","to","add","1","at","the","end","since","array","indeces","starts","from","0",".","2",")","Selects","only","those","units","that","have","been","sampled",".","During","the","training","phase","it","is","important","to","not","use","the","reconstructed","inputs",",","so","we","beed","to","enforce","a","zero","value","in","the","reconstructed","ratings","in","the","same","position","as","the","original","input",".","Args",":","h","(","tf.Tensor",",","float32",")",":","visible","units",".","Returns",":","tf.Tensor",",","tf.Tensor",":","-","`","pvh","`",":","The","activation","probability","of","the","visible","unit","given","the","hidden",".","-","`","v_","`",":","The","sampled","value","of","the","visible","unit","from","a","Multinomial","distributions","having","success","probability","`","pvh","`","."]
code: def sample_visible_units(self, h):
      """Sample the visible units given the hiddens. This can be thought of as a Backward pass in a FFN
      (negative phase). Each visible unit can take values in [1,rating], while the zero is reserved
      for missing data; as such the value of the hidden unit is sampled from a multinomial distribution.
  
      Basic mechanics:
  
      1) For every training example we first sample Nv Multinomial distributions. The result is of the
      form [0,1,0,0,0,...,0] where the index of the 1 element corresponds to the rth rating. The index
      is extracted using the argmax function and we need to add 1 at the end since array indeces starts
      from 0.
  
      2) Selects only those units that have been sampled. During the training phase it is important to not
      use the reconstructed inputs, so we beed to enforce a zero value in the reconstructed ratings in
      the same position as the original input.
  
      Args:
          h (tf.Tensor, float32): visible units.
  
      Returns:
          tf.Tensor, tf.Tensor:
          - `pvh`: The activation probability of the visible unit given the hidden.
          - `v_`: The sampled value of the visible unit from a Multinomial distributions having success probability `pvh`.
      """
  
      with tf.compat.v1.name_scope("sample_visible_units"):
          phi_h = (
              tf.matmul(h, tf.transpose(a=self.w)) + self.bv
          )  # linear combination
          pvh = self.multinomial_distribution(
              phi_h
          )  # conditional probability of v given h
  
          # Sampling (modify here )
          v_tmp = self.multinomial_sampling(
              pvh
          )  # sample the value of the visible units
  
          mask = tf.equal(
              self.v, 0
          )  # selects the inactive units in the input vector
  
          v_ = tf.compat.v1.where(
              mask, x=self.v, y=v_tmp
          )  # enforce inactive units in the reconstructed vector
  
      return pvh, v_
  
imports: import numpy
  import tensorflow
  import logging
  import os
  from pathlib import Path
label_desc: Use image node_id 9 for calling the RBM obj's underlying member method code with example usage: obj.sample_visible_units(h) and returns: pvh,  v_