Esempio n. 1
0
def plot_some_zipf(f_counts, N, dom):
  plt.loglog(range(1,N+1), f_counts, 'r+')
  lgnd = ['play frequencies']+['s='+str(s) for s in dom]
  for s in dom:
    t = su.zipf_t(s, N)
    zipf_vals = [su.zipf(k,s,t) for k in range(1,N+1)]
    plt.loglog(range(1,N+1), zipf_vals)
    plt.xlim([0.0, float(N)])
    plt.xlabel('rank k')
    plt.ylabel('frequency f')
    plt.legend(lgnd,'upper right')
Esempio n. 2
0
def plot_fit_zipf(f_counts, N, dom):
  res = opt.minimize(su.kl_optimize, [0], args=([f_counts]))
  kls = []
  for s in dom:
    t = su.zipf_t(s, N)
    zipf_vals = [su.zipf(k,s,t) for k in range(1,N+1)]
    kls.append(float(su.kl_divergence(f_counts, zipf_vals)))
  plt.plot(dom, kls)
  plt.xlabel('s')
  #plt.annotate('global min at ~'+str(0.48) , xy=(res.x, res.fun), xytext=(res.x+res.x/30.0, res.fun+7*res.fun),
  #            arrowprops=dict(facecolor='black', shrink=0.05),
  #         )
  plt.legend(['KL divergence'], 'upper right')
  plt.xlim([dom[0], dom[-1]])
  plt.show()