class_docstr: Lossless compression for Herarchical latent variable models.
  
  Based on the Craystack (https://github.com/j-towns/craystack)
  implementation of Bits-Back coding.
  
  Args:
      model: The hierarchical latent variable model.
      data_shape: The shape [batch-size, channels, height, width]
          of the data and each latent.
      latent_prec: Coding precision.
      prior_prec: Precision for the discretization.
      obs_prec: Precision for the observation codec.
      data_prec: Precision of the discrete data.
      initial_len: Length of the random initial bitstring.
      data_min: Minimum value of the data to be fed into the model.
      data_max: Maximum value of the data to be fed into the model.
      clip_stdd: Minimum value for the stdd of the observation codec.
      track: Whether to track the message sizes at each step.
class_docstr_tok: ["Lossless","compression","for","Herarchical","latent","variable","models",".","Based","on","the","Craystack","(","https",":","\/\/github.com\/j-towns\/craystack",")","implementation","of","Bits-Back","coding",".","Args",":","model",":","The","hierarchical","latent","variable","model",".","data_shape",":","The","shape","[","batch-size",",","channels",",","height",",","width","]","of","the","data","and","each","latent",".","latent_prec",":","Coding","precision",".","prior_prec",":","Precision","for","the","discretization",".","obs_prec",":","Precision","for","the","observation","codec",".","data_prec",":","Precision","of","the","discrete","data",".","initial_len",":","Length","of","the","random","initial","bitstring",".","data_min",":","Minimum","value","of","the","data","to","be","fed","into","the","model",".","data_max",":","Maximum","value","of","the","data","to","be","fed","into","the","model",".","clip_stdd",":","Minimum","value","for","the","stdd","of","the","observation","codec",".","track",":","Whether","to","track","the","message","sizes","at","each","step","."]
docstr: Likelihood codec for BB-ANS.
  
  Extracts indices idx_0 of z_0 and mean/standard deviation of
  the prior p(z_0|z_1). Indices correspond to bins with equal
  mass under the Gaussian prior p(z_0|z_1), allowing
  to obtain the (discretized) latent variable z_0.
  The codec then uses a uniform discretization under a Gaussian with
  mean/(clipped) standard deviation of p(x|z_0) to encode/decode
  the data in [0, 2 ** self.data_prec - 1].
  
  Args:
      discr_latents: The list of (discretized) latents.
  Returns:
      The craystack codec corresponding to the likelihood
      of the Bits-Back codec.
docstr_tok: ["Likelihood","codec","for","BB-ANS",".","Extracts","indices","idx_0","of","z_0","and","mean\/standard","deviation","of","the","prior","p","(","z_0|z_1",")",".","Indices","correspond","to","bins","with","equal","mass","under","the","Gaussian","prior","p","(","z_0|z_1",")",",","allowing","to","obtain","the","(","discretized",")","latent","variable","z_0",".","The","codec","then","uses","a","uniform","discretization","under","a","Gaussian","with","mean\/","(","clipped",")","standard","deviation","of","p","(","x|z_0",")","to","encode\/decode","the","data","in","[","0",",","2","*","*","self.data_prec","-","1","]",".","Args",":","discr_latents",":","The","list","of","(","discretized",")","latents",".","Returns",":","The","craystack","codec","corresponding","to","the","likelihood","of","the","Bits-Back","codec","."]
code: def likelihood(self, discr_latents: List[DiscrLatent]) -> cs.Codec:
      """
      Likelihood codec for BB-ANS.
  
      Extracts indices idx_0 of z_0 and mean/standard deviation of
      the prior p(z_0|z_1). Indices correspond to bins with equal
      mass under the Gaussian prior p(z_0|z_1), allowing
      to obtain the (discretized) latent variable z_0.
      The codec then uses a uniform discretization under a Gaussian with
      mean/(clipped) standard deviation of p(x|z_0) to encode/decode
      the data in [0, 2 ** self.data_prec - 1].
  
      Args:
          discr_latents: The list of (discretized) latents.
      Returns:
          The craystack codec corresponding to the likelihood
          of the Bits-Back codec.
      """
      assert len(discr_latents) == self.model.steps
      latent = self._to_latent(discr_latents[0])
      params = self.model.generate_fn(latent, step=0)
  
      codec = diag_gaussian_unif_bins(
          mean=params.mean,
          stdd=params.stdd.clip(min=self.clip_stdd),
          data_min=self.data_min,
          data_max=self.data_max,
          coding_prec=self.obs_prec,
          bin_prec=self.data_prec,
      )
      return self._track_codec(codec, step=0)
  
imports: from abc import ABC, abstractmethod
  from typing import List, NamedTuple, Optional, Tuple, Union, overload
  import craystack
  import numpy
  import torch
  from craystack import codecs
  from craystack.bb_ans import BBANS
  from improved_diffusion.gaussian_diffusion import GaussianDiffusion
label_desc: Use image node_id 13 for calling the BitsBackCodec obj's underlying member method code with example usage: obj.likelihood(discr_latents) and returns: self