Lately I have been making use of a continuous relaxation of discrete random variables proposed in two recent papers: The Concrete Distribution: A Continuous Relaxation of Discrete Random Variables and Categorical Reparameterization with Gumbel-Softmax. I decided to write a blog post with some motivation of the method, as well as providing some minor clarification on this method’s properties.

Consider a bernoulli variable where the distribution of conditioned on model inputs and weights has the following form: , where . For notational clarity, I will suppress the dependence of on and . Additionally, I am specifically excluding the case because deterministic variables are not very interesting. We can also view a bernoulli variable with parameter as having the following density on :

Where is the dirac delta function. The cumulative distribution function (CDF) of a bernoulli variable parameterized with has a simple piecewise constant form (disregarding some technical details about delta functions and measure theory):

We note that is continuous everywhere except .

Imagine that we had a function of , , and we wanted to estimate in terms of a finite number of samples drawn from . This might seem frivolous to do for a single bernoulli variable since we could just write out the full formula for the expectation exactly but it is easier to see how intractable this process gets if we are considering high dimensional vectors of such variables. One previous method for computing this estimate is the REINFORCE estimator, but this estimator suffers from high variance and does not easily integrate well with automatic differentiation methods like those found in Tensorflow or Theano.

If were a continuous valued random variable then we could probably use some form of the reparameterisation trick, where is represented as a function of the parameters and a noise term , such that . Importantly must be differentiable in both of its inputs. Gradients with respect to can be expressed in terms of where . is generally an easy to sample from distribution with a smooth density (such as a standard gaussian) and explicitly does not depend on . See this blog post for a great overview of the reparameterisation trick.

Unfortunately no such function exists for discrete variables like bernoulli or categorical random variables. The solution proposed (simultaneously it seems) by Maddison, Et al and Jang, Et al is to come up with continuous random variables that can be expressed using a reparameterisation trick, share certain statistical properties with the discrete variables they are approximating, and become close (in a sense) to these variables when a “temperature” parameter tends to zero. I will focus on the application of this method to a bernoulli variable (henceforth referred to as the relaxed bernoulli variable) but I note that the method generalizes to categorical variables of any number of states. Additionally, I will mostly follow the convention of Maddison, Et al, where this variable is referred to as a Binary Concrete variable. A sample of a relaxed bernoulli variable with parameter can be defined in terms of a new temperature parameter and a variable distributed according to a standard logistic distribution:

In (other) words a relaxed bernoulli variable is obtained by a) sampling a standard logistic variable b) offsetting that variable by c) scaling the result by and finally d) passing the whole thing through a logistic sigmoid. For notational expediency I will henceforth let stand for a logistic sigmoid applied to the variable z. A relaxed bernoulli variate with parameter and temperature has the following density:

In the appendix of Maddison, Et al, the authors state several properties of the relaxed bernoulli variable, two of which are of particular interest to me:

- (
*Rounding*) . Intuitively, if we were rounding a relaxed bernoulli variable to the nearest integer, then it would have the same distribution as a normal bernoulli variable with the same parameter . This is easy to see by noting that if and only if $z > 0$. Thus . Since the CDF of is the logistic sigmoid (by definition) then we have, . - (
*Zero Temperature*) . This statement was not immediately clear to me but I took it to mean that if one sampled many relaxed bernoulli variables but kept as an adjustable parameter, then took the limit of then approximately would converge to 1 and the rest to 0. This statement follows directly from the previous one by noting that if and if .

The zero temperature property is probably good enough to convince most users that a relaxed bernoulli variable becomes a good approximation to a standard bernoulli variable with the same as . However, I was left wondering if the stronger property of convergence in distribution also held. Convergence in distribution guarantees some other useful properties through the portmanteau lemma, such as for all bounded and continuous functions .

The relaxed bernoulli variate with CDF converges in distribution to a bernoulli variable if as for every where is continuous.

For the relaxed bernoulli variable, obtaining an expression for takes a little bit of trickery. Normally one could just define the CDF in terms of an integral of the probability density function:

However, is not defined, and even diverges for small enough , at . This makes even numerical evaluation of difficult. However, we can take advantage of the *rounding *property above to make the following claim (once again suspending some technical details about measure theory):

We can use this expression and standard properties of integrals to get a more tractable formulation of . First we define the following notation for :

Finally, we have an expression for that can be evaluated with standard numerical integration techniques.

By inspection it is clear that for or . Additionally, since is discontinuous at all that remains to show is that as for . is plotted below for several values of (translated into different values of ), and for different values of . does appear to converge to , although not uniformly.

To make the statement of convergence a little more concrete, I note that it suffices to show that and as for all . Furthermore, these limits can be established by showing that as for all . It is clear that both the numerator and denominator of are continuous functions of as long as and . The denominator converges to and the numerator to as . Thus as for all .