Advertisement
Guest User

Untitled

a guest
Jan 19th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. g1 = tf.Graph()
  2. with g1.as_default():
  3.  
  4. X1 = tf.placeholder("float", [None, 784])
  5. w1 = weights([Nv, Nh])
  6. vb1 = bias([Nv])
  7. hb1 = bias([Nh])
  8.  
  9. print ("w1:", w1.shape)
  10. print("X1:", X1.shape)
  11. print("vb1:", vb1.shape)
  12. print("hb1:",hb1.shape)
  13.  
  14. h0_prob = tf.nn.sigmoid(tf.matmul(X1, w1) + hb1)
  15. h0 = sample_prob(h0_prob)
  16. h1 = h0
  17.  
  18. print ("h1:", h1.shape)
  19.  
  20. for step in range(gibbs_sampling_steps):
  21. v1_prob = tf.nn.sigmoid(tf.matmul(h1, tf.transpose(w1)) + vb1)
  22. v1 = sample_prob(v1_prob)
  23. print("v1:", v1.shape)
  24. h1_prob = tf.nn.sigmoid(tf.matmul(v1, w1) + hb1)
  25. h1 = sample_prob(h1_prob)
  26.  
  27.  
  28. w1_positive_grad = tf.matmul(v1, h0)
  29. w1_negative_grad = tf.matmul(v1, h1)
  30.  
  31. print ("w1_positive: ", w1_positive_grad.shape)
  32. print ("w1_negative: ", w1_negative_grad.shape)
  33.  
  34. dw1 = (w1_positive_grad - w1_negative_grad) / tf.to_float(tf.shape(X1)[0])
  35.  
  36. update_w1 = tf.assign_add(w1, alpha * dw1)
  37. update_vb1 = tf.assign_add(vb1, alpha * tf.reduce_mean(X1 - v1, 0))
  38. update_hb1 = tf.assign_add(hb1, alpha * tf.reduce_mean(h0 - h1, 0))
  39.  
  40. out1 = (update_w1, update_vb1, update_hb1)
  41.  
  42. print ("update_w1: ", update_w1.shape)
  43.  
  44. v1_prob = tf.nn.sigmoid(tf.matmul(h1, tf.transpose(update_w1)) + update_vb1)
  45. v1 = sample_prob(v1_prob)
  46.  
  47. print ("v1 last:", v1.shape)
  48.  
  49. err1 = X1 - v1
  50. print("error: ", err1.shape)
  51. err_sum1 = tf.reduce_mean(err1 * err1)
  52.  
  53. initialize1 = tf.global_variables_initializer()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement