code: def density_goodness_of_fit(samples, probs, plot=False):
      """
      Transform arbitrary continuous samples to Uniform(0,1) distribution and
      assess goodness of fit via binned Pearson's chi^2 test.
  
      :param torch.Tensor samples: A vector list of real-valued samples from a
          distribution.
      :param torch.Tensor probs: A vector of probability densities evaluated at
          those samples.
      :param bool plot: Whether to print a histogram. Defaults to False.
      :returns: Goodness of fit, as a p-value.
      :rtype: float
      """
      assert samples.shape == probs.shape
      if len(samples) <= 100:
          raise InvalidTest("imprecision; use more samples")
  
      samples, index = samples.sort(0)
      probs = probs[index]
      gaps = samples[1:] - samples[:-1]
  
      sparsity = 1 / probs
      sparsity = 0.5 * (sparsity[1:] + sparsity[:-1])
      density = len(samples) / sparsity
  
      exp_samples = density * gaps
      return exp_goodness_of_fit(exp_samples, plot=plot)
  
file_path: pyro/pyro/distributions/testing/gof.py
imports: import math
  import warnings
  import torch
  from .special import chi2sf
label_desc: Use image node_id 5 for calling a global function with example usage: density_goodness_of_fit(samples, probs, plot) and returns: exp_goodness_of_fit