def dda_expected_entropy(qs): """return d/da[E[H|a*qs]], a function of alpha""" # Agrees with test_diff! sum_qs = float(sum(qs)) h_inf = h(normalize(qs), units='nats') h_0 = 0 #expected_entropy_from_alphas([0 for q in qs]) Z = h_inf #*log(2) # in nats return lambda alpha: ((sum_qs * polygamma(1, alpha * sum_qs + 1) - sum( qj**2 / sum_qs * polygamma(1, alpha * qj + 1) for qj in qs)) / (Z))
def dda_expected_entropy(qs): """return d/da[E[H|a*qs]], a function of alpha""" # Agrees with test_diff! sum_qs = float(sum(qs)) h_inf = h(normalize(qs),units='nats') h_0 = 0 #expected_entropy_from_alphas([0 for q in qs]) Z = h_inf#*log(2) # in nats return lambda alpha: ((sum_qs*polygamma(1,alpha*sum_qs+1) - sum(qj**2/sum_qs*polygamma(1,alpha*qj+1) for qj in qs))/ (Z))
def h_mle(xs,units='bits'): """Compute MLE estimator of entropy""" p_hats = frequencies(xs) return h(p_hats,units=units)