code: def binomial_dist(total_count, probs, *, overdispersion=0.0):
      """
      Returns a Beta-Binomial distribution that is an overdispersed version of a
      Binomial distribution, according to a parameter ``overdispersion``,
      typically set in the range 0.1 to 0.5.
  
      This is useful for (1) fitting real data that is overdispersed relative to
      a Binomial distribution, and (2) relaxing models of large populations to
      improve inference. In particular the ``overdispersion`` parameter lower
      bounds the relative uncertainty in stochastic models such that increasing
      population leads to a limiting scale-free dynamical system with bounded
      stochasticity, in contrast to Binomial-based SDEs that converge to
      deterministic ODEs in the large population limit.
  
      This parameterization satisfies the following properties:
  
      1.  Variance increases monotonically in ``overdispersion``.
      2.  ``overdispersion = 0`` results in a Binomial distribution.
      3.  ``overdispersion`` lower bounds the relative uncertainty ``std_dev /
          (total_count * p * q)``, where ``probs = p = 1 - q``, and serves as an
          asymptote for relative uncertainty as ``total_count → ∞``. This
          contrasts the Binomial whose relative uncertainty tends to zero.
      4.  If ``X ~ binomial_dist(n, p, overdispersion=σ)`` then in the large
          population limit ``n → ∞``, the scaled random variable ``X / n``
          converges in distribution to ``LogitNormal(log(p/(1-p)), σ)``.
  
      To achieve these properties we set ``p = probs``, ``q = 1 - p``, and::
  
          concentration = 1 / (p * q * overdispersion**2) - 1
  
      :param total_count: Number of Bernoulli trials.
      :type total_count: int or torch.Tensor
      :param probs: Event probabilities.
      :type probs: float or torch.Tensor
      :param overdispersion: Amount of overdispersion, in the half open interval
          [0,2). Defaults to zero.
      :type overdispersion: float or torch.tensor
      """
      _validate_overdispersion(overdispersion)
      if _is_zero(overdispersion):
          if _RELAX:
              return _relaxed_binomial(total_count, probs)
          return dist.ExtendedBinomial(total_count, probs)
  
      p = probs
      q = 1 - p
      od2 = (overdispersion + 1e-8) ** 2
      concentration1 = 1 / (q * od2 + 1e-8) - p
      concentration0 = 1 / (p * od2 + 1e-8) - q
      # At this point we have
      #   concentration1 + concentration0 == 1 / (p + q + od2 + 1e-8) - 1
  
      if _RELAX:
          return _relaxed_beta_binomial(
              concentration1, concentration0, total_count
          )
      return dist.ExtendedBetaBinomial(
          concentration1, concentration0, total_count
      )
  
file_path: pyro/pyro/contrib/epidemiology/distributions.py
imports: import math
  from contextlib import contextmanager
  import torch
  from torch.distributions.utils import broadcast_all
  import pyro.distributions
  from pyro.distributions.util import is_validation_enabled
label_desc: Use image node_id 9 for calling a global function with example usage: binomial_dist(total_count, probs) and returns: dist, dist, _relaxed_beta_binomial, _relaxed_binomial