def run_cluster():
import GPy
# create dataset
print "creating dataset..."
N = 50
k1 = GPy.kern.RBF(5, variance=1, lengthscale=1. /
np.random.dirichlet(np.r_[10, 10, 10, 0.1, 0.1]), ARD=True)
k2 = GPy.kern.RBF(5, variance=1, lengthscale=1. /
np.random.dirichlet(np.r_[10, 0.1, 10, 0.1, 10]), ARD=True)
k3 = GPy.kern.RBF(5, variance=1, lengthscale=1. /
np.random.dirichlet(np.r_[0.1, 0.1, 10, 10, 10]), ARD=True)
X = np.random.normal(0, 1, (N, 5))
A = np.random.multivariate_normal(np.zeros(N), k1.K(X), 10).T
B = np.random.multivariate_normal(np.zeros(N), k2.K(X), 10).T
C = np.random.multivariate_normal(np.zeros(N), k3.K(X), 10).T
Y = np.vstack((A, B, C))
labels = np.hstack((np.zeros(A.shape[0]), np.ones(
B.shape[0]), np.ones(C.shape[0]) * 2))
# inference
print "inference ..."
M = 20
D = 5
lvm_aep = aep.SGPLVM(Y, D, M, lik='Gaussian')
lvm_aep.optimise(method='L-BFGS-B', alpha=0.1, maxiter=2000)
lvm = ep.SGPLVM(Y, D, M, lik='Gaussian')
lvm.update_hypers(lvm_aep.get_hypers())
# # a quick hack to initialise the factors
# lvm.sgp_layer.t1 = np.tile(lvm_aep.sgp_layer.theta_2[np.newaxis, :, :] / lvm.N, [lvm.N, 1, 1])
# lvm.sgp_layer.t2 = np.tile(lvm_aep.sgp_layer.theta_1[np.newaxis, :, :, :] / lvm.N, [lvm.N, 1, 1, 1])
# lvm.sgp_layer.update_posterior()
# lvm.tx1 = lvm_aep.factor_x1
# lvm.tx2 = lvm_aep.factor_x2
lvm.inference(alpha=0.1, no_epochs=10, parallel=True, decay=0.5)
ls = np.exp(lvm.sgp_layer.ls)
print ls
inds = np.argsort(ls)
plt.figure()
mx, vx = lvm.get_posterior_x()
plt.scatter(mx[:, inds[0]], mx[:, inds[1]], c=labels)
zu = lvm.sgp_layer.zu
plt.plot(zu[:, inds[0]], zu[:, inds[1]], 'ko')
plt.show()
评论列表
文章目录