class_docstr: A three-parameter generalization of the Negative Binomial distribution [1].
  It can be understood as a continuous mixture of Negative Binomial distributions
  in which we inject Normally-distributed noise into the logits of the Negative
  Binomial distribution:
  
  .. math::
  
      \begin{eqnarray}
      &\rm{LNNB}(y | \rm{total\_count}=\nu, \rm{logits}=\ell, \rm{multiplicative\_noise\_scale}=sigma) = \\
      &\int d\epsilon \mathcal{N}(\epsilon | 0, \sigma)
      \rm{NB}(y | \rm{total\_count}=\nu, \rm{logits}=\ell + \epsilon)
      \end{eqnarray}
  
  where :math:`y \ge 0` is a non-negative integer. Thus while a Negative Binomial distribution
  can be formulated as a Poisson distribution with a Gamma-distributed rate, this distribution
  adds an additional level of variability by also modulating the rate by Log Normally-distributed
  multiplicative noise.
  
  This distribution has a mean given by
  
  .. math::
      \mathbb{E}[y] = \nu e^{\ell} = e^{\ell + \log \nu + \tfrac{1}{2}\sigma^2}
  
  and a variance given by
  
  .. math::
      \rm{Var}[y] = \mathbb{E}[y] + \left( e^{\sigma^2} (1 + 1/\nu) - 1 \right) \left( \mathbb{E}[y] \right)^2
  
  Thus while a given mean and variance together uniquely characterize a Negative Binomial distribution, there is a
  one-dimensional family of Log Normal Negative Binomial distributions with a given mean and variance.
  
  Note that in some applications it may be useful to parameterize the logits as
  
  .. math::
      \ell = \ell^\prime - \log \nu - \tfrac{1}{2}\sigma^2
  
  so that the mean is given by :math:`\mathbb{E}[y] = e^{\ell^\prime}` and does not depend on :math:`\nu`
  and :math:`\sigma`, which serve to determine the higher moments.
  
  References:
  
  [1] "Lognormal and Gamma Mixed Negative Binomial Regression,"
  Mingyuan Zhou, Lingbo Li, David Dunson, and Lawrence Carin.
  
  :param total_count: non-negative number of negative Bernoulli trials. The variance decreases
      as `total_count` increases.
  :type total_count: float or torch.Tensor
  :param torch.Tensor logits: Event log-odds for probabilities of success for underlying
      Negative Binomial distribution.
  :param torch.Tensor multiplicative_noise_scale: Controls the level of the injected Normal logit noise.
  :param int num_quad_points: Number of quadrature points used to compute the (approximate) `log_prob`.
      Defaults to 8.
class_docstr_tok: ["A","three-parameter","generalization","of","the","Negative","Binomial","distribution","[","1","]",".","It","can","be","understood","as","a","continuous","mixture","of","Negative","Binomial","distributions","in","which","we","inject","Normally-distributed","noise","into","the","logits","of","the","Negative","Binomial","distribution",":","..","math",":",":","\\begin","{","eqnarray","}","&","\\rm","{","LNNB","}","(","y","|","\\rm","{","total\\_count","}","=\\nu",",","\\rm","{","logits","}","=\\ell",",","\\rm","{","multiplicative\\_noise\\_scale","}","=sigma",")","=","\\\\","&","\\int","d\\epsilon","\\mathcal","{","N","}","(","\\epsilon","|","0",",","\\sigma",")","\\rm","{","NB","}","(","y","|","\\rm","{","total\\_count","}","=\\nu",",","\\rm","{","logits","}","=\\ell","+","\\epsilon",")","\\end","{","eqnarray","}","where",":","math",":","`","y","\\ge","0","`","is","a","non-negative","integer",".","Thus","while","a","Negative","Binomial","distribution","can","be","formulated","as","a","Poisson","distribution","with","a","Gamma-distributed","rate",",","this","distribution","adds","an","additional","level","of","variability","by","also","modulating","the","rate","by","Log","Normally-distributed","multiplicative","noise",".","This","distribution","has","a","mean","given","by","..","math",":",":","\\mathbb","{","E","}","[","y","]","=","\\nu","e^","{","\\ell","}","=","e^","{","\\ell","+","\\log","\\nu","+","\\tfrac","{","1","}","{","2","}","\\sigma^2","}","and","a","variance","given","by","..","math",":",":","\\rm","{","Var","}","[","y","]","=","\\mathbb","{","E","}","[","y","]","+","\\left","(","e^","{","\\sigma^2","}","(","1","+","1\/\\nu",")","-","1","\\right",")","\\left","(","\\mathbb","{","E","}","[","y","]","\\right",")","^2","Thus","while","a","given","mean","and","variance","together","uniquely","characterize","a","Negative","Binomial","distribution",",","there","is","a","one-dimensional","family","of","Log","Normal","Negative","Binomial","distributions","with","a","given","mean","and","variance",".","Note","that","in","some","applications","it","may","be","useful","to","parameterize","the","logits","as","..","math",":",":","\\ell","=","\\ell^\\prime","-","\\log","\\nu","-","\\tfrac","{","1","}","{","2","}","\\sigma^2","so","that","the","mean","is","given","by",":","math",":","`","\\mathbb","{","E","}","[","y","]","=","e^","{","\\ell^\\prime","}","`","and","does","not","depend","on",":","math",":","`","\\nu","`","and",":","math",":","`","\\sigma","`",",","which","serve","to","determine","the","higher","moments",".","References",":","[","1","]","``","Lognormal","and","Gamma","Mixed","Negative","Binomial","Regression",",","''","Mingyuan","Zhou",",","Lingbo","Li",",","David","Dunson",",","and","Lawrence","Carin",".",":","param","total_count",":","non-negative","number","of","negative","Bernoulli","trials",".","The","variance","decreases","as","`","total_count","`","increases",".",":","type","total_count",":","float","or","torch.Tensor",":","param","torch.Tensor","logits",":","Event","log-odds","for","probabilities","of","success","for","underlying","Negative","Binomial","distribution",".",":","param","torch.Tensor","multiplicative_noise_scale",":","Controls","the","level","of","the","injected","Normal","logit","noise",".",":","param","int","num_quad_points",":","Number","of","quadrature","points","used","to","compute","the","(","approximate",")","`","log_prob","`",".","Defaults","to","8","."]
code: def mean(self):
      return torch.exp(
          self.logits
          + self.total_count.log()
          + 0.5 * self.multiplicative_noise_scale.pow(2.0)
      )
  
file_path: pyro/pyro/distributions/log_normal_negative_binomial.py
imports: import torch
  from torch.distributions import constraints
  from torch.distributions.utils import broadcast_all, lazy_property
  from pyro.distributions.torch import NegativeBinomial
  from pyro.distributions.torch_distribution import TorchDistribution
  from pyro.distributions.util import broadcast_shape
  from pyro.ops.special import get_quad_rule
label_desc: Use image node_id 5 for calling the LogNormalNegativeBinomial obj's underlying member method code with example usage: obj.mean() and returns: torch