class_docstr: Base class for parameterized probability distributions.
  
  Distributions in Pyro are stochastic function objects with :meth:`sample` and
  :meth:`log_prob` methods. Distribution are stochastic functions with fixed
  parameters::
  
    d = dist.Bernoulli(param)
    x = d()                                # Draws a random sample.
    p = d.log_prob(x)                      # Evaluates log probability of x.
  
  **Implementing New Distributions**:
  
  Derived classes must implement the methods: :meth:`sample`,
  :meth:`log_prob`.
  
  **Examples**:
  
  Take a look at the `examples <http://pyro.ai/examples>`_ to see how they interact
  with inference algorithms.
class_docstr_tok: ["Base","class","for","parameterized","probability","distributions",".","Distributions","in","Pyro","are","stochastic","function","objects","with",":","meth",":","`","sample","`","and",":","meth",":","`","log_prob","`","methods",".","Distribution","are","stochastic","functions","with","fixed","parameters",":",":","d","=","dist.Bernoulli","(","param",")","x","=","d","(",")","#","Draws","a","random","sample",".","p","=","d.log_prob","(","x",")","#","Evaluates","log","probability","of","x",".","*","*","Implementing","New","Distributions","*","*",":","Derived","classes","must","implement","the","methods",":",":","meth",":","`","sample","`",",",":","meth",":","`","log_prob","`",".","*","*","Examples","*","*",":","Take","a","look","at","the","`","examples","<","http",":","\/\/pyro.ai\/examples",">","`","_","to","see","how","they","interact","with","inference","algorithms","."]
docstr: Computes ingredients for stochastic gradient estimators of ELBO.
  
  The default implementation is correct both for non-reparameterized and
  for fully reparameterized distributions. Partially reparameterized
  distributions should override this method to compute correct
  `.score_function` and `.entropy_term` parts.
  
  Setting ``.has_rsample`` on a distribution instance will determine
  whether inference engines like :class:`~pyro.infer.svi.SVI` use
  reparameterized samplers or the score function estimator.
  
  :param torch.Tensor x: A single value or batch of values.
  :return: A `ScoreParts` object containing parts of the ELBO estimator.
  :rtype: ScoreParts
docstr_tok: ["Computes","ingredients","for","stochastic","gradient","estimators","of","ELBO",".","The","default","implementation","is","correct","both","for","non-reparameterized","and","for","fully","reparameterized","distributions",".","Partially","reparameterized","distributions","should","override","this","method","to","compute","correct","`",".score_function","`","and","`",".entropy_term","`","parts",".","Setting","``",".has_rsample","``","on","a","distribution","instance","will","determine","whether","inference","engines","like",":","class",":","`","~pyro.infer.svi.SVI","`","use","reparameterized","samplers","or","the","score","function","estimator",".",":","param","torch.Tensor","x",":","A","single","value","or","batch","of","values",".",":","return",":","A","`","ScoreParts","`","object","containing","parts","of","the","ELBO","estimator",".",":","rtype",":","ScoreParts"]
code: def score_parts(self, x, *args, **kwargs):
      """
      Computes ingredients for stochastic gradient estimators of ELBO.
  
      The default implementation is correct both for non-reparameterized and
      for fully reparameterized distributions. Partially reparameterized
      distributions should override this method to compute correct
      `.score_function` and `.entropy_term` parts.
  
      Setting ``.has_rsample`` on a distribution instance will determine
      whether inference engines like :class:`~pyro.infer.svi.SVI` use
      reparameterized samplers or the score function estimator.
  
      :param torch.Tensor x: A single value or batch of values.
      :return: A `ScoreParts` object containing parts of the ELBO estimator.
      :rtype: ScoreParts
      """
      log_prob = self.log_prob(x, *args, **kwargs)
      if self.has_rsample:
          return ScoreParts(
              log_prob=log_prob, score_function=0, entropy_term=log_prob
          )
      else:
          # XXX should the user be able to control inclusion of the entropy term?
          # See Roeder, Wu, Duvenaud (2017) "Sticking the Landing" https://arxiv.org/abs/1703.09194
          return ScoreParts(
              log_prob=log_prob, score_function=log_prob, entropy_term=0
          )
  
file_path: pyro/pyro/distributions/distribution.py
imports: import functools
  import inspect
  from abc import ABCMeta, abstractmethod
  import torch
  from pyro.distributions.score_parts import ScoreParts
label_desc: Use image node_id 4 for calling the Distribution obj's underlying member method code with example usage: obj.score_parts(x) and returns: ScoreParts, ScoreParts