Exemplo n.º 1
0
def getCumDist(samps, cutOff = float("inf"), burnIn = 0):
  sampDic = {}
  for c, samp in sorted(samps.items()):
    if samp > cutOff or c < burnIn:
      continue
    c = c - burnIn
    try:
      sampDic[samp] += 1
    except:
      sampDic[samp] = 1.0

  return pu.norm(sampDic)
Exemplo n.º 2
0
def calcKLTest(post, samps, freq = float("inf"), show=True, col=None, plot=True, cutOff = float("inf"), burnIn = 0, alpha=0.5):
  sampDic = {}
  if isinstance(samps, list):
    samps = dict([(i+1,samps[i]) for i in range(len(samps))])

  xs = []
  ys = []
  prevC = 0
  sampList = []
  for c, samp in sorted(samps.items()):
    if samp > cutOff or c < burnIn:
      continue
    c = c - burnIn
    sampList.append(samp)
    try:
      sampDic[samp] += 1
    except:
      sampDic[samp] = 1.0

    kl = getKLDiv(pu.norm(sampDic), post)
    xs.append(c)
    ys.append(kl)
    if (c+1) / freq > prevC:
      prevC += 1
      plt.hist(sampList, 100)
      plt.title(str(c) + " " + str(kl))
      #plt.show()
  if not plot:
    return xs, ys
  else:
    if col:
      ax, = plt.plot(xs,ys, col, alpha=alpha)
    else:
      ax, = plt.plot(xs,ys)
    plt.yscale("log", basey=2)
    plt.xscale("log")
    if show:
      plt.show()

    return ax