Ejemplo n.º 1
0
def responsibility(x, k, pi, mu, lam):
    K = len(pi)
    num = pi[k] * norm.pdf(x, mu[k], inv(lam[k]))
    den = 0
    for j in range(K):
        den = den + pi[j] * norm.pdf(x, mu[j], inv(lam[j]))
    return num / den
Ejemplo n.º 2
0
    def callback(params, t, g):
        print("Iteration {} lower bound {}".format(t, -objective(params, t)))

        plt.cla()
        target_distribution = lambda x : np.exp(log_posterior(x, t))
        plot_isocontours(ax, target_distribution)

        mean, log_std = unpack_params(params)
        variational_contour = lambda x: mvn.pdf(x, mean, np.diag(np.exp(2*log_std)))
        plot_isocontours(ax, variational_contour)
        plt.draw()
        plt.pause(1.0/30.0)
Ejemplo n.º 3
0
    def callback(params, t, g):
        print("Iteration {} lower bound {}".format(t, -objective(params, t)))

        plt.cla()
        target_distribution = lambda x: np.exp(log_density(x, t))
        plot_isocontours(ax, target_distribution)

        mean, std = unpack_params(params)
        variational_contour = lambda x: mvn.pdf(x, mean, std @ std.T)
        plot_isocontours(ax, variational_contour)
        plt.draw()
        plt.pause(1.0 / 30.0)
Ejemplo n.º 4
0
 def variational_contour(x): return mvn.pdf(
     x, mean, np.diag(np.exp(2 * log_std)))
 plot_isocontours(ax, variational_contour)
Ejemplo n.º 5
0
def variational_density(x, params, D):
	std = params[D:].reshape([D,D])
	cov_mat = np.matmul(std, std.T)
	return mvn.pdf(x, mean=params[:D], cov=cov_mat)
Ejemplo n.º 6
0
 def _logprob(z):
     return np.log(mvn.pdf(z, mean=mus[0], cov=sigmas[0]) +\
             mvn.pdf(z, mean=mus[1], cov=sigmas[1]) +\
             mvn.pdf(z, mean=mus[2], cov=sigmas[2]))