# Computing Gradients for a [-1, 1]-valued RBM

The gradient derivation for a binary-valued RBM with values $$\in\{0,1\}$$ is well-documented, for example in Goodfellow, et al and here on Cross Validated. However, in some works (e.g., associative GANs and their quantum variants), it is popular to use binary RBM variables in the range $$\{-1, 1\}$$ instead.

How would this change in variable range affect the gradient derivation? I know we can still exploit the bipartite structure of the RBM but am not sure how the rest of the simplifications and subsequent equations would fare.

As an example, the gradients of a popular TensorFlow implementation are

h0_props = self.propup(visibles)
hb_grad = tf.reduce_mean(h0_props - h_samples, 0)
vb_grad = tf.reduce_mean(visibles - v_samples, 0)


where propup computes $$P(h|v)$$.

Changing the input range (and removing ReLU activations when updating either $$\bf{v}$$ or $$\bf{h}$$) makes the RBM fluctuate wildly, leading me to assume the gradients are no longer valid. I was hoping someone more familiar with the math could elucidate.

In Section 6.1 of the paper on Associative Adversial Networks you mention they give a detail about training with $$\{-1, 1\}$$ labels:

We chose binary variable states as $$(-1)$$ and $$(+1)$$ similar to spin states in an Ising model [24]. The expected value of a unit in the RBM is $$p∗1 + (1−p)∗−1 = 2p−1$$ where $$p$$ is the conditional probability of a variable to be (1), which is a sigmoid.

Why does it matter ? The derivations of the RBM equations for labels in $$\{0, 1\}$$ are well detailed in this article. Equation 2.27 details one of the equation for the gradient:

For a $$\{0, 1\}$$ RBM, the conditional expectation is, with $$p\triangleq p(H_i=1|\pmb{v})$$ (as in the AAN article), $$p∗1 + (1-p)∗0=p$$. We see the that the conditional expectation is indeed used in the gradient expression with $$\sum_{\pmb{h}}p(\pmb{h}|\pmb{v})h_i$$, which equal to $$p$$ in the $$\{0, 1\}$$ case.

In a $$\{-1, 1\}$$ RBM, we do not have that the conditional expectation is equal to $$p(H_i=1|\pmb{v})$$. In the code, h0_props and h_samples approximates $$p(H_i=1|\pmb{v})$$ but what you want according to 2.26 is $$2p(H_i=1|\pmb{v})-1$$. Thus you should adapt the code with

h0_props = self.propup(visibles)