

def short_hdi(sample, cred=0.95):
    'Calculate the shortest Highest Density Interval from\n    the posterior distribution sampled via MCMC.\n\n    :Arguments:\n        sample: A list with the values of the posterior distribution.\n        cred: The mass of the posterior for which the interval is computed.\n                Default is 95%, should be a float from 0.0 to 1.0.\n\n    Returns a tuple with the limits of the HDI.\n\n    PyMC has a 95% HDI algorithm, but it uses quantiles.\n\n    '
    sorted_sample = sorted(sample)
    ci_index = int((cred * len(sorted_sample)))
    num_ci = (len(sorted_sample) - ci_index)
    ci_width = []
    for i in range(num_ci):
        width = (sorted_sample[(i + ci_index)] - sorted_sample[i])
        ci_width.append(width)
    hdi_min = sorted_sample[ci_width.index(min(ci_width))]
    hdi_max = sorted_sample[(ci_width.index(min(ci_width)) + ci_index)]
    hdi_lim = (hdi_min, hdi_max)
    return hdi_lim

dataset/ETHPy150Open erikson84/BayesDataAnalysisWithPyMC/BayesDataAnalysisWithPymc/short_hdi.py short_hdi/original