def renyientropy(px, alpha=1, logbase=2, measure='R'):
 if (not _isproperdist(px)):
  raise ValueError('px is not a proper probability distribution')
 alpha = float(alpha)
 if (alpha == 1):
  genent = shannonentropy(px)
  if (logbase != 2):
   return (logbasechange(2, logbase) * genent)
  return genent
 elif (('inf' in string(alpha).lower()) or (alpha == np.inf)):
  return (- np.log(np.max(px)))
 px = (px ** alpha)
 genent = np.log(px.sum())
 if (logbase == 2):
  return ((1 / (1 - alpha)) * genent)
 else:
  return (((1 / (1 - alpha)) * logbasechange(2, logbase)) * genent)

def renyientropy ( px , alpha = 1 , logbase = 2 , measure = 'R' ) : if ( not _isproperdist ( px ) ) : raise ValueError ( 'px is not a proper probability distribution' ) alpha = float ( alpha ) if ( alpha == 1 ) : genent = shannonentropy ( px ) if ( logbase != 2 ) : return ( logbasechange ( 2 , logbase ) * genent ) return genent elif ( ( 'inf' in string ( alpha ) . lower ( ) ) or ( alpha == np . inf ) ) : return ( - np . log ( np . max ( px ) ) ) px = ( px ** alpha ) genent = np . log ( px . sum ( ) ) if ( logbase == 2 ) : return ( ( 1 / ( 1 - alpha ) ) * genent ) else : return ( ( ( 1 / ( 1 - alpha ) ) * logbasechange ( 2 , logbase ) ) * genent )
renyis generalized entropy parameters px : array-like discrete probability distribution of random variable x .