tfc.distributions.quantization_offset  |  TensorFlow v2.16.1 (original) (raw)

tfc.distributions.quantization_offset

Stay organized with collections Save and categorize content based on your preferences.

Computes distribution-dependent quantization offset.

View aliases

Main aliases

tfc.quantization_offset

tfc.distributions.quantization_offset(
    distribution
)

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 methodself._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.

Args
distribution A tfp.distributions.Distribution object.
Returns
A tf.Tensor broadcastable to shape self.batch_shape, containing the determined quantization offsets. No gradients are allowed to flow through the return value.