Esempio n. 1
0
def post_direct(a, d, cw1, tw0):
  out = np.zeros(cw1)
  for i in range(cw1):
    out[i] = (  libplump.logKramp(a + d, d, i)
              - libplump.logKramp(a + 1, 1, i)
              + log_stirling_cached(d, cw1, i + 1)
              + log_stirling_cached(d, i + 1, tw0))
  out -= np.max(out)
  out = np.exp(out)
  out /= np.sum(out)
  return out
Esempio n. 2
0
def post_direct(a, d, cw1, tw0):
    out = np.zeros(cw1)
    for i in range(cw1):
        out[i] = (libplump.logKramp(a + d, d, i) -
                  libplump.logKramp(a + 1, 1, i) +
                  log_stirling_cached(d, cw1, i + 1) +
                  log_stirling_cached(d, i + 1, tw0))
    out -= np.max(out)
    out = np.exp(out)
    out /= np.sum(out)
    return out
Esempio n. 3
0
def plot_posterior_components(a,
                              N,
                              ds=np.arange(0.1, 1, 0.2),
                              ps=np.arange(0.1, 1, 0.2)):
    fig = plt.figure()
    ax = fig.add_subplot(111)
    # plot stirling numbers
    ps = []
    for d in ds:
        p1, = ax.plot(range(1, N + 1),
                      [log_stirling_cached(d, N, i) for i in range(1, N + 1)],
                      ':')

    # plot Kramp's symbol
    ax.set_color_cycle(mpl.rcParams['axes.color_cycle'])
    for d in ds:
        p2, = ax.plot(
            range(1, N + 1),
            [libplump.logKramp(a + d, d, i - 1)
             for i in range(1, N + 1)], '--')

    # plot sum of the two
    ax.set_color_cycle(mpl.rcParams['axes.color_cycle'])
    for d in ds:
        p3, = ax.plot(range(1, N + 1), [
            libplump.logKramp(a + d, d, i - 1) + log_stirling_cached(d, N, i)
            for i in range(1, N + 1)
        ])
        ps.append(p3)

    #plt.gca().set_color_cycle(mpl.rcParams['axes.color_cycle'])
    #for p in ps:
    #  plt.plot(range(1,N+1), [np.log(p)*i for i in range(1,N+1)],'.')

    #plt.gca().set_color_cycle(mpl.rcParams['axes.color_cycle'])
    # for p in ps:
    #   plt.plot(range(1,N+1), [np.log(p)*i for i in range(1,N+1)],'.')
    ax.set_xlabel("Number of tables")
    ax.set_title("Log-Posterior Parts, $\\alpha = %.1f$" % (a, ))
    l1 = ax.legend([p1, p2, p3], [
        "$\log  S_d(c, t)$", "$\log [\\alpha + d]_d^{t-1}$",
        "$\log  S_d(c, t) + \log  [\\alpha + d]_d^{t-1}$"
    ],
                   loc=6)
    ax.legend(ps, ["$d = %.1f$" % (d, ) for d in ds],
              loc=8,
              ncol=len(ds),
              borderaxespad=0.)
    ax.add_artist(l1)
    ax.grid(True)
    return fig, ax
Esempio n. 4
0
def log_post_ts(a, d, cws, tws, p0s):
    # see eq. 10 in "Improvements ..." paper
    return (libplump.logKramp(a + d, d,
                              float(np.sum(tws)) - 1) +
            np.sum([
                log_stirling_cached(d, cws[i], tws[i]) for i in range(len(cws))
            ]) + np.sum([tws[i] * math.log(p0s[i]) for i in range(len(cws))]))
Esempio n. 5
0
def plot_posterior_components(a,N, ds=np.arange(0.1,1,0.2), ps=np.arange(0.1,1,0.2)):
  fig = plt.figure()
  ax = fig.add_subplot(111)
  # plot stirling numbers
  ps = []
  for d in ds:
    p1, = ax.plot(range(1,N+1), [log_stirling_cached(d,N,i) for i in range(1,N+1)], ':')

  # plot Kramp's symbol
  ax.set_color_cycle(mpl.rcParams['axes.color_cycle'])
  for d in ds:
    p2, = ax.plot(range(1,N+1), [libplump.logKramp(a + d, d, i - 1) for i in range(1,N+1)],'--')
  
  # plot sum of the two
  ax.set_color_cycle(mpl.rcParams['axes.color_cycle'])
  for d in ds:
    p3, = ax.plot(range(1,N+1), [libplump.logKramp(a + d, d, i - 1) + log_stirling_cached(d,N,i) for i in range(1,N+1)])
    ps.append(p3)
  
  #plt.gca().set_color_cycle(mpl.rcParams['axes.color_cycle'])
  #for p in ps:
  #  plt.plot(range(1,N+1), [np.log(p)*i for i in range(1,N+1)],'.')
  
  
  #plt.gca().set_color_cycle(mpl.rcParams['axes.color_cycle'])
  # for p in ps:
  #   plt.plot(range(1,N+1), [np.log(p)*i for i in range(1,N+1)],'.')
  ax.set_xlabel("Number of tables")
  ax.set_title("Log-Posterior Parts, $\\alpha = %.1f$"%(a,))
  l1 = ax.legend([p1, p2, p3], 
      [ "$\log  S_d(c, t)$",
        "$\log [\\alpha + d]_d^{t-1}$",
        "$\log  S_d(c, t) + \log  [\\alpha + d]_d^{t-1}$"
      ], loc = 6)
  ax.legend(ps, ["$d = %.1f$"%(d,) for d in ds], loc = 8, 
      ncol=len(ds) , borderaxespad=0.)
  ax.add_artist(l1)
  ax.grid(True)
  return fig, ax
Esempio n. 6
0
def prior_et(a, d, c):
    return (np.exp(
        libplump.logKramp(a + d, 1, c) - np.log(d) -
        libplump.logKramp(a + 1, 1, c - 1)) - a / d)
Esempio n. 7
0
def logcrp(a, d, c, t):
    return (libplump.logKramp(a + d, d, float(t - 1)) -
            libplump.logKramp(a + 1, 1, float(c - 1)) +
            log_stirling_cached(d, c, t))
Esempio n. 8
0
def log_post_t(a, d, cw, tw, T, p0):
    # see eq. 10 in "Improvements ..." paper
    return (libplump.logKramp(a + d, d, float(T - 1)) +
            log_stirling_cached(d, cw, tw) + tw * math.log(p0))
Esempio n. 9
0
def prior_et(a,d,c):
   return (np.exp( libplump.logKramp(a + d, 1, c)
                 - np.log(d) 
                 - libplump.logKramp(a + 1, 1, c - 1))
         - a/d)
Esempio n. 10
0
def logcrp(a,d,c,t):
 return (libplump.logKramp(a + d, d, float(t -1)) -
         libplump.logKramp(a + 1, 1, float(c-1)) +
         log_stirling_cached(d, c, t))
Esempio n. 11
0
def log_post_ts(a,d,cws,tws,p0s):
  # see eq. 10 in "Improvements ..." paper
 return (libplump.logKramp(a + d, d, float(np.sum(tws)) - 1) + 
         np.sum([log_stirling_cached(d,cws[i],tws[i]) for i in range(len(cws))]) + 
         np.sum([tws[i]*math.log(p0s[i]) for i in range(len(cws))])
         )
Esempio n. 12
0
def log_post_t(a,d,cw,tw,T,p0):
  # see eq. 10 in "Improvements ..." paper
 return (libplump.logKramp(a + d, d, float(T -1)) + 
         log_stirling_cached(d, cw, tw) + 
         tw*math.log(p0))