def calc_min_interval(x, alpha):
 n = len(x)
 cred_mass = (1.0 - alpha)
 interval_idx_inc = int(np.floor((cred_mass * n)))
 n_intervals = (n - interval_idx_inc)
 interval_width = (x[interval_idx_inc:] - x[:n_intervals])
 if (len(interval_width) == 0):
  raise ValueError('Too few elements for interval calculation')
 min_idx = np.argmin(interval_width)
 hdi_min = x[min_idx]
 hdi_max = x[(min_idx + interval_idx_inc)]
 return (hdi_min, hdi_max)

def calc_min_interval ( x , alpha ) : n = len ( x ) cred_mass = ( 1.0 - alpha ) interval_idx_inc = int ( np . floor ( ( cred_mass * n ) ) ) n_intervals = ( n - interval_idx_inc ) interval_width = ( x [ interval_idx_inc : ] - x [ : n_intervals ] ) if ( len ( interval_width ) == 0 ) : raise ValueError ( 'Too few elements for interval calculation' ) min_idx = np . argmin ( interval_width ) hdi_min = x [ min_idx ] hdi_max = x [ ( min_idx + interval_idx_inc ) ] return ( hdi_min , hdi_max )
internal method to determine the minimum interval of a given width assumes that x is sorted numpy array .