Computes distribution-dependent quantization offset.

For range coding of continuous random variables, the values need to be quantized first. Typically, it is beneficial for compression performance to align the centers of the quantization bins such that one of them coincides with the mode of the distribution. With offset being the mode of the distribution, for instance, this can be achieved simply by computing:

x_hat = tf.round(x - offset) + offset

This method tries to determine the offset in a best-effort fashion, based on which statistics the Distribution implements. First, a method self._quantization_offset() is tried. If that isn't defined, it tries in turn: self.mode(), self.quantile(.5), then self.mean(). If none of these are implemented, it falls back on quantizing to integer values (i.e., an offset of zero).

Note the offset is always in the range [-.5, .5] as it is assumed to be combined with a round quantizer.

distribution A tfp.distributions.Distribution object.

A tf.Tensor broadcastable to shape self.batch_shape, containing the determined quantization offsets. No gradients are allowed to flow through the return value.