rebar
rebar copied to clipboard
Explain truncated gumbel sampling
I didn't know why truncated gumbel can sampled in this way
return -tf.log(EPSILON + tf.exp(-gumbel) + tf.exp(-truncation))
can u describe it?
Yeah, it's not super obvious. I borrowed the trick from here, but they don't demonstrate it either. But it's actually not too hard to show. Remember that an easy way to sample is to use an inverse transform sampler, where you map uniform noise through the inverse CDF of the desired distribution. So if we can find the CDF and invert it, we have a sampler. All you then need to do is to grab the CDF of a truncated distribution from Wikipedia, plug in the Gumbel CDF and invert it.
Since the sampler above assumes gumbel noise, you will also need to map the gumbel noise through its CDF to get uniform noise (running the original Gumbel inverse transform sampler in reverse), which means that the final expression has the form
InverseTruncatedCDF(CDF(gumbel))
.