# Set up kernel function kern = nl.cmpndKern() kern1 = nl.rbfKern(X) kern2 = nl.biasKern(X) kern3 = nl.whiteKern(X) kern3.setVariance(1e-4) kern.addKern(kern1) kern.addKern(kern2) kern.addKern(kern3) noise = nl.gaussianNoise(y) # Create a GP model. model = nl.gp(1, 1, X, y, kern, noise, nl.gp.DTC, numActive, 3) model.setBetaVal(math.exp(2)) model.setDefaultOptimiser(nl.gp.CG) # Optimise the GP. model.optimise(1000) xtest = nl.matrix(np.linspace(-1.2, 1.2, 200).reshape(200, 1)) ytest = nl.matrix(200, 1) yvar = nl.matrix(200, 1) model.posteriorMeanVar(ytest, yvar, xtest) xt = xtest.toarray() yt = ytest.toarray() yv = yvar.toarray()
kern = nl.cmpndKern() kern1 = nl.rbfKern(X) kern2 = nl.biasKern(X) kern3 = nl.whiteKern(X) kern3.setVariance(1e-3) kern.addKern(kern1) kern.addKern(kern2) kern.addKern(kern3) noise = nl.gaussianNoise(Y) # Create a GP model. model = nl.gp(q, d, X, Y, kern, noise, nl.gp.DTCVAR, 100, 3) model.setBetaVals(math.exp(2)) #pdb.set_trace() model.setDefaultOptimiser(nl.gp.CG) model.setOptimiseX(True) # Optimise the GP. model.optimise(100) Xstor = ndlwrap.toarray(X) pyplot.figure() ind = numpy.nonzero(lbls[:, 0]==1) pyplot.plot(Xstor[ind, 0], Xstor[ind, 1], 'ro') ind = numpy.nonzero(lbls[:, 1]==1) pyplot.plot(Xstor[ind, 0], Xstor[ind, 1], 'bx')
# Set up kernel function kern = ndlml.cmpndKern() kern1 = ndlml.rbfKern(X) kern2 = ndlml.biasKern(X) kern3 = ndlml.whiteKern(X) kern.addKern(kern1) kern.addKern(kern2) kern.addKern(kern3) noise = ndlml.gaussianNoise(Y) # Create an GP model. model = ndlml.gp(2, 12, X, Y, kern, noise, ndlml.gp.FTC, 100, 3) model.setOptimiseX(True) model.setDefaultOptimiser(ndlml.gp.GD) model.setLearnRate(0.00005) model.setMomentum(0.9) # Optimise the GP. model.optimise(10000) Xstor = ndlwrap.toarray(X) pyplot.figure() ind = numpy.nonzero(lbls[:, 0]==1) pyplot.plot(Xstor[ind, 0], Xstor[ind, 1], 'ro')
else: sparseApprox = False # Create ndlmatrixmatrix from user preferences. Xiter = nl.matrix() Xiter.fromarray(X[filmIndices, :]) # Remove movie means and divide by movie standard deviations. y = np.reshape((filmRatings-movieMean[filmIndices].flatten())/movieStd[filmIndices].flatten(), (len(filmIndices), 1)) yiter = nl.matrix() yiter.fromarray(y) count = count + 1 if sparseApprox: param[0, -1] = lnbeta paramChange[0, -1] = lnbetaChange model = nl.gp(q, 1, Xiter, yiter, kernSp, noise, nl.gp.DTCVAR, numActive, 3) paramIter.resize(1, numActive*q+kernFtc.getNumParams()) # Set the inducing point locations. counter2 = 0 for j in range(q): for i in range(numActive): paramIter.setVal(X_u[i, j], counter2) counter2 += 1 # Set the parameters. for i in range(param.shape[1]): paramIter.setVal(param[0, i], counter2) counter2 += 1
Xstore = X Xstor = np.empty(Xstore.shape) Ystore = Y Y = nw.fromarray(Y) X = nw.fromarray(X) # Set up kernel function kern = nl.cmpndKern() kern1 = nl.rbfKern(X) kern2 = nl.biasKern(X) kern3 = nl.whiteKern(X) kern3.setVariance(1e-4) kern.addKern(kern1) kern.addKern(kern2) kern.addKern(kern3) noise = nl.gaussianNoise(Y) # Create a GP model. model = nl.gp(q, d, X, Y, kern, noise, nl.gp.DTCVAR, 100, 3) #pdb.set_trace() model.setOptimiseX(True) model.setBetaVal(math.exp(2)) model.setDefaultOptimiser(nl.gp.CG) # model.setOptimiseX(True) # # Optimise the GP. # #model.checkGradients(); model.optimise(1000)
# Set up kernel function kern = nl.cmpndKern() kern1 = nl.rbfKern(X) kern2 = nl.biasKern(X) kern3 = nl.whiteKern(X) kern.addKern(kern1) kern.addKern(kern2) kern.addKern(kern3) noise = nl.gaussianNoise(y) # Create an GP model. model = nl.gp(kern, noise, X, nl.gp.FTC, 100, 3) model.setDefaultOptimiser(nl.gp.CG) model.checkGradients() # Optimise the GP. model.optimise(100) xtest = nl.matrix(np.linspace(-1.2, 1.2, 200).reshape(200, 1)) ytest = nl.matrix(200, 1) yvar = nl.matrix(200, 1) model.posteriorMeanVar(ytest, yvar, xtest) xt = np.empty((xtest.getRows(), xtest.getCols())) yt = np.empty((ytest.getRows(), ytest.getCols())) yv = np.empty((yvar.getRows(), yvar.getCols()))
# Set up kernel function kern = nl.cmpndKern() kern1 = nl.rbfKern(X) kern2 = nl.biasKern(X) kern3 = nl.whiteKern(X) kern.addKern(kern1) kern.addKern(kern2) kern.addKern(kern3) noise = nl.gaussianNoise(Y) # Create an GP model. model = nl.gp(q, d, X, Y, kern, noise, nl.gp.FTC, 0, 3) model.setOptimiseX(True) model.setDefaultOptimiser(nl.gp.GD) model.setLearnRate(0.000005) model.setMomentum(0.5) # Optimise the GP. model.optimise(2000) Xstor = ndlwrap.toarray(X) pyplot.figure() ind = numpy.nonzero(lbls[:, 0]==1) pyplot.plot(Xstor[ind, 0], Xstor[ind, 1], 'ro')