def Py_z2(data, i, clustering, cluster_assn, prior, ti=0): Y = data[1, 0] T = data[1, 1] if type(i) == int: new_y = Y[i] new_t = T[:, i] else: new_y = i new_t = ti ## NOTE: Should change var1, l and var2 v1 = prior["var1"] # 0.1 v2 = prior["var2"] # 0.2 l = prior["length_scale"] # 0.05 GPs = [ GPCluster(rbf_kern, Y=Y[list(cluster)], T=T[:, list(cluster)], var1=v1, l=l, var2=v2) for cluster in clustering ] likelihoods = [GPs[j].likelihood(new_y, new_t) for j in range(len(GPs))] empty_gp = GPCluster(rbf_kern, Y=np.array([0]), T=np.array([0]), var1=v1, l=l, var2=v2) likelihoods.append(empty_gp.likelihood_empty(new_y, new_t)) return np.array(likelihoods)
dp = DCRP(alpha1, alpha2, Px_z1, Py_z2, prior1, prior2) dp._initialize_assn(train_data) print "Number of clusters for X = ", len(dp.c1) print "Number of clusters for Y = ", len(dp.c2) # Run gibbs sampling dp._gibbs_sampling_crp(train_data) print "Number of clusters for X = ", len(dp.c1) print "Number of clusters for Y = ", len(dp.c2) # Final clustering dp_c2 = len(dp.c2) dp_gp = [] for k in range(dp_c2): dp_gp.append(GPCluster(rbf_kern,Y=train_data[1,0][list(dp.c2[k]),:],\ T=train_data[1,1][:,list(dp.c2[k])],var1=prior2["var1"], \ l=prior2["length_scale"],var2=prior2["var2"])) dp_gp.append(GPCluster(rbf_kern,Y=np.array([[0,0,0,0,0]]),\ T=np.array([[0,1,2,3,4]]).T,var1=prior2["var1"],\ l=prior2["length_scale"],var2=prior2["var2"])) ms = 0 for m in range(size_test): y = test_data[1, 0][m].reshape((-1, 1)) y = y[:4] t = np.array([[0, 1, 2, 3]]) x = test_data[0, 0][m] prob = dp.predict(x, y, t, train_data) t = np.array([[0, 1, 2, 3, 4]]) sum = 0 for i in range(prob.shape[0]):