This current recipe present the steps for, a contrastive divergence (CD) technique used to speed up the sampling process:
- Compute a positive weight gradient by multiplying (outer product) the input vector X with a sample of the hidden vector h0 from the given probability distribution prob_h0:
w_pos_grad = tf$matmul(tf$transpose(X), h0)
- Compute a negative weight gradient by multiplying (outer product) the sample of the reconstructed input data v1 with the updated hidden activation vector h1:
w_neg_grad = tf$matmul(tf$transpose(v1), h1)
- Then, compute the CD matrix by subtracting the negative gradient from the positive gradient and dividing by the size of the input data:
CD = (w_pos_grad - w_neg_grad) / tf$to_float(tf$shape(X)[0]) ...