y_train = y[index_train, :] x_test = x[index_test, :] y_test = y[index_test, :] # gp model.optimize(x_train, y_train) model.predict(x_test) # evaluation predictive_class_rbf = np.sign(model.ym) ACC_rbf = valid.ACC(predictive_class_rbf, y_test) ## DIFFUSION Kernel # compute kernel matrix and initalize GP with precomputed kernel model = pyGPs.GPC() M1, M2 = graphUtil.formKernelMatrix(Matrix, index_train, index_test) k = pyGPs.cov.Pre(M1, M2) model.setPrior(kernel=k) # if you only use precomputed kernel matrix, there is no training data needed, # but you still need to specify x_train (due to general structure of pyGPs) # e.g. you can use the following: n = len(index_train) x_train = np.zeros((n, 1)) # gp model.optimize(x_train, y_train) model.predict(x_test) # evaluation predictive_class_diff = np.sign(model.ym)
print('number of kernel iterations =', t) Matrix = K[:,:,t] # normalize kernel matrix (not useful for MUTAG) # Matrix = graphUtil.normalizeKernel(Matrix) # start cross-validation for this t for index_train, index_test in valid.k_fold_index(N, K=10): y_train = graph_label[index_train,:] y_test = graph_label[index_test,:] n1 = len(index_train) n2 = len(index_test) model = pyGPs.GPC() M1,M2 = graphUtil.formKernelMatrix(Matrix, index_train, index_test) k = pyGPs.cov.Pre(M1,M2) model.setPrior(kernel=k) # gp x_train = np.zeros((n1,1)) x_test = np.zeros((n2,1)) model.getPosterior(x_train, y_train) model.predict(x_test) predictive_class = np.sign(model.ym) # evaluation acc = valid.ACC(predictive_class, y_test) ACC.append(acc)