@statfunc
def hpd(x, alpha=0.05, transform=(lambda x: x)):
 x = transform(x.copy())
 if (x.ndim > 1):
  tx = np.transpose(x, (list(range(x.ndim))[1:] + [0]))
  dims = np.shape(tx)
  intervals = np.resize(0.0, (dims[:(-1)] + (2,)))
  for index in make_indices(dims[:(-1)]):
   try:
    index = tuple(index)
   except TypeError:
    pass
   sx = np.sort(tx[index])
   intervals[index] = calc_min_interval(sx, alpha)
  return np.array(intervals)
 else:
  sx = np.sort(x)
  return np.array(calc_min_interval(sx, alpha))

@ statfunc def hpd ( x , alpha = 0.05 , transform = ( lambda x : x ) ) : x = transform ( x . copy ( ) ) if ( x . ndim > 1 ) : tx = np . transpose ( x , ( list ( range ( x . ndim ) ) [ 1 : ] + [ 0 ] ) ) dims = np . shape ( tx ) intervals = np . resize ( 0.0 , ( dims [ : ( - 1 ) ] + ( 2 , ) ) ) for index in make_indices ( dims [ : ( - 1 ) ] ) : try : index = tuple ( index ) except TypeError : pass sx = np . sort ( tx [ index ] ) intervals [ index ] = calc_min_interval ( sx , alpha ) return np . array ( intervals ) else : sx = np . sort ( x ) return np . array ( calc_min_interval ( sx , alpha ) )
calculate highest posterior density of array for given alpha .