hyp.mean = np.array([]) sn = 0.1 hyp.lik = np.array([np.log(sn)]) ##----------------------------------------------------------## ## STANDARD GP (prediction) ## ##----------------------------------------------------------## xs = np.arange(2004+1./24.,2024-1./24.,1./12.) # TEST POINTS xs = xs.reshape(len(xs),1) vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,xs) ym = vargout[0]; ys2 = vargout[1] m = vargout[2]; s2 = vargout[3] plotter(xs,ym,ys2,x,y) ##----------------------------------------------------------## ## STANDARD GP (training) ## ## OPTIMIZE HYPERPARAMETERS ## ##----------------------------------------------------------## ## -> parameter training using (off the shelf) conjugent gradient (CG) optimization (NOTE: SCG is faster) from time import clock t0 = clock() vargout = min_wrapper(hyp,gp,'SCG',inffunc,meanfunc,covfunc,likfunc,x,y,None,None,True) t1 = clock() hyp = vargout[0] vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,xs) ym = vargout[0]; ys2 = vargout[1] m = vargout[2]; s2 = vargout[3]
hyp2.cov = np.array([-1.0,0.0]) hyp2.mean = np.array([0.5,1.0]) hyp2.lik = np.array([np.log(0.1)]) ### PREDICTION import time t0 = time.time() print 'prediction' vargout = gp(hyp2,inffunc,meanfunc,covfunc,likfunc,x,y,xstar) ym = vargout[0]; ys2 = vargout[1]; m = vargout[2]; s2 = vargout[3] print time.time() - t0 ### PLOT results plotter(xstar,ym,ys2,x,y,[-2, 2, -0.9, 3.9]) ### GET negative log marginal likelihood [nlml, post] = gp(hyp2,inffunc,meanfunc,covfunc,likfunc,x,y,None,None,False) print "nlml2 = ", nlml ###----------------------------------------------------------### ### STANDARD GP (example 3) ### ###----------------------------------------------------------### ### TRAINING: OPTIMIZE hyperparameters [hyp2_opt, fopt, gopt, funcCalls] = min_wrapper(hyp2,gp,'CG',inffunc,meanfunc,covfunc,likfunc,x,y,None,None,True) print "nlml_opt = ", fopt #[hyp2_opt, fopt, gopt, funcCalls] = min_wrapper(hyp2,gp,'BFGS',inffunc,meanfunc,covfunc,likfunc,x,y,None,None,True) #print fopt
hyp = hyperParameters() hyp.cov = np.array([np.log(0.25),np.log(1.0),np.log(3.0)]) hyp.mean = np.array([0.5,1.0]) sn = 0.1; hyp.lik = np.array([np.log(sn)]) #_________________________________ # STANDARD GP: ## PREDICTION vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,None,None,False) print "nlml = ",vargout[0] vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,z) ym = vargout[0]; ys2 = vargout[1] m = vargout[2]; s2 = vargout[3] ## Plot results plotter(z,ym,ys2,x,y,[-1.9, 1.9, -0.9, 3.9]) print "pre" + str(x) x = np.delete(x, 0, 0) x = np.delete(x, 5, 0) print "post" + str(x) y = np.delete(y, 0, 0) y = np.delete(y, 5, 0) vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,None,None,False) print "nlml = ",vargout[0] vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,z) ym = vargout[0]; ys2 = vargout[1] m = vargout[2]; s2 = vargout[3] ## Plot results plotter(z,ym,ys2,x,y,[-1.9, 1.9, -0.9, 3.9])
hyp = hyperParameters() hyp.cov = np.array([np.log(0.25),np.log(1.0),np.log(3.0)]) hyp.mean = np.array([0.5,1.0]) sn = 0.1; hyp.lik = np.array([np.log(sn)]) #_________________________________ # STANDARD GP: ## PREDICTION vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,None,None,False) print "nlml = ",vargout[0] vargout = gp(hyp,inffunc,meanfunc,covfunc,likfunc,x,y,z) ym = vargout[0]; ys2 = vargout[1] m = vargout[2]; s2 = vargout[3] ## Plot results plotter(z,ym,ys2,x,y,[-1.9, 1.9, -0.9, 3.9]) ########################################################### covfunc = [ ['kernels.covSEiso'] ] ## SET (hyper)parameters hyp2 = hyperParameters() hyp2.cov = np.array([-1.0,0.0]) hyp2.lik = np.array([np.log(0.1)]) vargout = min_wrapper(hyp2,gp,'SCG',inffunc,[],covfunc,likfunc,x,y,None,None,True) hyp2 = vargout[0] #hyp2.cov = np.array([-0.993396880620537,0.685943441677086]) #hyp2.lik = np.array([-1.902546786026883]) vargout = gp(hyp2,inffunc,[],covfunc,likfunc,x,y,None,None,False) print "nlml2 = ",vargout[0]