gplvm_vfe_examples.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:geepee 作者: thangbui 项目源码 文件源码
def run_frey():
    # import dataset
    data = pods.datasets.brendan_faces()
    # Y = data['Y'][:50, :]
    Y = data['Y']
    Yn = Y - np.mean(Y, axis=0)
    Yn /= np.std(Y, axis=0)
    Y = Yn

    # inference
    print "inference ..."
    M = 30
    D = 20
    lvm = vfe.SGPLVM(Y, D, M, lik='Gaussian')
    lvm.optimise(method='L-BFGS-B', maxiter=10)
    plt.figure()
    mx, vx = lvm.get_posterior_x()
    zu = lvm.sgp_layer.zu
    plt.scatter(mx[:, 0], mx[:, 1])
    plt.plot(zu[:, 0], zu[:, 1], 'ko')

    nx = ny = 30
    x_values = np.linspace(-5, 5, nx)
    y_values = np.linspace(-5, 5, ny)
    sx = 28
    sy = 20
    canvas = np.empty((sx * ny, sy * nx))
    for i, yi in enumerate(x_values):
        for j, xi in enumerate(y_values):
            z_mu = np.array([[xi, yi]])
            x_mean, x_var = lvm.predict_f(z_mu)
            canvas[(nx - i - 1) * sx:(nx - i) * sx, j *
                   sy:(j + 1) * sy] = x_mean.reshape(sx, sy)

    plt.figure(figsize=(8, 10))
    Xi, Yi = np.meshgrid(x_values, y_values)
    plt.imshow(canvas, origin="upper", cmap="gray")
    plt.tight_layout()

    plt.show()
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号