code: def quantize(name, x_real, min, max, num_quant_bins=4):
      """Randomly quantize in a way that preserves probability mass."""
      assert _all(min < max)
      if num_quant_bins == 1:
          x = x_real.detach().round()
          return pyro.deterministic(name, x, event_dim=0)
  
      lb = x_real.detach().floor()
  
      probs = compute_bin_probs(
          x_real - lb, num_quant_bins=num_quant_bins
      )
  
      q = pyro.sample(
          "Q_" + name,
          dist.Categorical(probs),
          infer={"enumerate": "parallel"},
      )
      q = q.type_as(x_real) - (num_quant_bins // 2 - 1)
  
      x = lb + q
      x = torch.max(x, 2 * min - 1 - x)
      x = torch.min(x, 2 * max + 1 - x)
  
      return pyro.deterministic(name, x, event_dim=0)
  
file_path: pyro/pyro/contrib/epidemiology/util.py
imports: import numpy
  import torch
  import pyro
  import pyro.distributions
  import pyro.poutine
  from pyro.distributions.util import broadcast_shape
  from pyro.ops.special import safe_log
label_desc: Use image node_id 7 for calling a global function with example usage: quantize(name, x_real, min, max, num_quant_bins) and returns: pyro, pyro