Ejemplo n.º 1
0
    def __init__(self, data, T, alpha_beta):
        mu, sigma = compute_uniform_mean_psi(T)
        self.theta_prior = Gaussian(
            mu=mu, sigma=sigma, mu_0=mu, sigma_0=T*sigma/10.,
            nu_0=T/10., kappa_0=1./10)

        self.ppgs = initialize_polya_gamma_samplers()
        self.omega = np.zeros((data.shape[0], T-1))

        super(StickbreakingCorrelatedLDA, self).__init__(data, T, alpha_beta)
Ejemplo n.º 2
0
        betas.append(model.beta.copy())

    # Check that the PG-Multinomial samples are distributed like the prior
    thetas = np.array(thetas)
    theta_mean = thetas.mean(0)
    theta_std  = thetas.std(0)

    betas = np.array(betas)
    beta_mean = betas.mean(0)
    beta_std  = betas.std(0)

    # Now sample from the prior for comparison
    print("Sampling from prior")
    from pybasicbayes.distributions import GaussianFixedMean
    from pgmult.internals.utils import compute_uniform_mean_psi, psi_to_pi
    mu, sigma0 = compute_uniform_mean_psi(T)
    psis_prior = np.array(
        [GaussianFixedMean(mu=mu, lmbda_0=T * sigma0, nu_0=T).rvs(1)
         for _ in xrange(N_iter)])
    thetas_prior = psi_to_pi(psis_prior[:,0,:])
    betas_prior = np.random.dirichlet(alpha_beta*np.ones(V), size=(N_iter,))

    # print "Mean psi: ", psi_mean, " +- ", psi_std

    import pybasicbayes.util.general as general
    percentilecutoff = 5
    def plot_1d_scaled_quantiles(p1,p2,plot_midline=True):
        # scaled quantiles so that multiple calls line up
        p1.sort(), p2.sort() # NOTE: destructive! but that's cool
        xmin,xmax = general.scoreatpercentile(p1,percentilecutoff), \
                    general.scoreatpercentile(p1,100-percentilecutoff)