code: def hpd_coverage(mu, pdf, thresh):
      '''
      Integrates a pdf over mu taking only bins where
      the mean over the bin is above a given threshold
      This gives the coverage of the HPD interval for
      the given threshold.
      '''
      dp = integral_element(mu, pdf)
      bin_mean = (pdf[1:] + pdf[:-1]) / 2.
  
      return dp[bin_mean > thresh].sum(f hpd_coverage(mu, pdf, thresh):
      '''
      Integrates a pdf over mu taking only bins where
      the mean over the bin is above a given threshold
      This gives the coverage of the HPD interval for
      the given threshold.
      '''
      dp = integral_element(mu, pdf)
      bin_mean = (pdf[1:] + pdf[:-1]) / 2.
  
      return dp[bin_mean > thresh].sum()
docs: Integrates a pdf over mu taking only bins where
      the mean over the bin is above a given threshold
      This gives the coverage of the HPD interval for
      the given threshold.