def drawmins(G,n,lb,ub,SUPPORT=300,mode = [ESutils.SUPPORT_SLICELCB],SLICELCB_PARA=1.): #draw support points W = sp.vstack([ESutils.draw_support(G, lb,ub,SUPPORT/len(mode),m, para = SLICELCB_PARA) for m in mode]) if False: print 'how did I get here' plt.figure() plt.plot(W[:,0],W[:,1],'g.') plt.show() #draw in samples on the support print "drawing mins from support" R = ESutils.draw_min(G,W,n) if False: plt.figure() plt.plot(R[:,0],R[:,1],'r.') plt.show() #plt.show() return R
# To change this license header, choose License Headers in Project Properties. # To change this template file, choose Tools | Templates # and open the template in the editor. import ESutils import scipy as sp from scipy import linalg as spl from scipy import stats as sps from matplotlib import pyplot as plt #uniform test import GPdc X = ESutils.draw_support(2, sp.array([-2,-1]),sp.array([0,3]),500,ESutils.SUPPORT_UNIFORM) for i in xrange(X.shape[0]): plt.plot(X[i,0],X[i,1],'r.') plt.axis([-5,5,-5,5]) #2d gp test nt=34 X = ESutils.draw_support(2, sp.array([-1.,-1.]),sp.array([1.,1.]),nt,ESutils.SUPPORT_UNIFORM) D = [[sp.NaN]]*(nt) hyp = sp.array([1.5,0.25,0.25]) kf = GPdc.gen_sqexp_k_d(hyp) Kxx = GPdc.buildKsym_d(kf,X,D) Y = spl.cholesky(Kxx,lower=True)*sp.matrix(sps.norm.rvs(0,1.,nt)).T+sp.matrix(sps.norm.rvs(0,1e-3,nt)).T S = sp.matrix([1e-6]*nt).T
#!/usr/bin/env python2 #encoding: UTF-8 #Draw 200 hyperparameters from the posterior, plot the draws on a countour plot, first for very few points, then a large number import ESutils import scipy as sp from scipy import linalg as spl from scipy import stats as sps from matplotlib import pyplot as plt import GPdc #test on a single point nt = 3 X = ESutils.draw_support(1, sp.array([-1.]), sp.array([1.]), nt, ESutils.SUPPORT_UNIFORM) D = [[sp.NaN]] * (nt) hyp = sp.array([1.5, 0.15]) kf = GPdc.gen_sqexp_k_d(hyp) Kxx = GPdc.buildKsym_d(kf, X, D) Y = spl.cholesky(Kxx, lower=True) * sp.matrix(sps.norm.rvs( 0, 1., nt)).T + sp.matrix(sps.norm.rvs(0, 1e-3, nt)).T S = sp.matrix([1e-6] * nt).T G = GPdc.GPcore(X, Y, S, D, GPdc.kernel(GPdc.SQUEXP, 2, hyp)) ng = 40 A = sp.empty([ng, ng]) print 'startimage1' sup = sp.logspace(-3, 2, ng) for i, hi in enumerate(sup):
self.D = D return X = ESutils.draw_support_inplane(bob(2), sp.array([-2, -1]), sp.array([0, 3]), 500, ESutils.SUPPORT_UNIFORM, 1, 0.5) for i in xrange(X.shape[0]): plt.plot(X[i, 0], X[i, 1], 'r.') plt.axis([-5, 5, -5, 5]) #2d gp test import GPdc nt = 34 X = ESutils.draw_support(bob(2), sp.array([-1., -1.]), sp.array([1., 1.]), nt, ESutils.SUPPORT_UNIFORM) D = [[sp.NaN]] * (nt) hyp = sp.array([1.5, 0.15, 0.15]) kf = GPdc.gen_sqexp_k_d(hyp) Kxx = GPdc.buildKsym_d(kf, X, D) Y = spl.cholesky(Kxx, lower=True) * sp.matrix(sps.norm.rvs( 0, 1., nt)).T + sp.matrix(sps.norm.rvs(0, 1e-3, nt)).T S = sp.matrix([1e-6] * nt).T lb = sp.array([-2., -2., -2.]) ub = sp.array([2., 2., 2.]) #MLEH = GPdc.searchMLEhyp(X,Y,S,D,lb,ub,GPdc.SQUEXP,mx=10000) G = GPdc.GPcore(X, Y, S, D, GPdc.kernel(GPdc.SQUEXP, 2, sp.array([1.5, 0.15, 0.15]))) #np=180 #sup = sp.linspace(-1,1,np)
self.D=D return X = ESutils.draw_support_inplane(bob(2), sp.array([-2,-1]),sp.array([0,3]),500,ESutils.SUPPORT_UNIFORM,1,0.5) for i in xrange(X.shape[0]): plt.plot(X[i,0],X[i,1],'r.') plt.axis([-5,5,-5,5]) #2d gp test import GPdc nt=34 X = ESutils.draw_support(bob(2), sp.array([-1.,-1.]),sp.array([1.,1.]),nt,ESutils.SUPPORT_UNIFORM) D = [[sp.NaN]]*(nt) hyp = sp.array([1.5,0.15,0.15]) kf = GPdc.gen_sqexp_k_d(hyp) Kxx = GPdc.buildKsym_d(kf,X,D) Y = spl.cholesky(Kxx,lower=True)*sp.matrix(sps.norm.rvs(0,1.,nt)).T+sp.matrix(sps.norm.rvs(0,1e-3,nt)).T S = sp.matrix([1e-6]*nt).T lb = sp.array([-2.,-2.,-2.]) ub = sp.array([2.,2.,2.]) #MLEH = GPdc.searchMLEhyp(X,Y,S,D,lb,ub,GPdc.SQUEXP,mx=10000) G = GPdc.GPcore(X,Y,S,D,GPdc.kernel(GPdc.SQUEXP,2,sp.array([1.5,0.15,0.15]))) #np=180 #sup = sp.linspace(-1,1,np) #Dp = [[sp.NaN]]*np #Xp = sp.vstack([sp.array([i]) for i in sup])
#!/usr/bin/env python2 #encoding: UTF-8 #Draw 200 hyperparameters from the posterior, plot the draws on a countour plot, first for very few points, then a large number import ESutils import scipy as sp from scipy import linalg as spl from scipy import stats as sps from matplotlib import pyplot as plt import GPdc #test on a single point nt=3 X = ESutils.draw_support(1, sp.array([-1.]),sp.array([1.]),nt,ESutils.SUPPORT_UNIFORM) D = [[sp.NaN]]*(nt) hyp = sp.array([1.5,0.15]) kf = GPdc.gen_sqexp_k_d(hyp) Kxx = GPdc.buildKsym_d(kf,X,D) Y = spl.cholesky(Kxx,lower=True)*sp.matrix(sps.norm.rvs(0,1.,nt)).T+sp.matrix(sps.norm.rvs(0,1e-3,nt)).T S = sp.matrix([1e-6]*nt).T G = GPdc.GPcore(X,Y,S,D,GPdc.kernel(GPdc.SQUEXP,2,hyp)) ng = 40 A = sp.empty([ng,ng]) print 'startimage1' sup = sp.logspace(-3,2,ng) for i,hi in enumerate(sup): for j,hj in enumerate(sup):
Dp = [[sp.NaN]] * np Xp = sp.vstack([sp.array([i]) for i in sup]) [m, V] = g.infer_diag_post(Xp, Dp) f, a = plt.subplots(3) s = sp.sqrt(V[0, :]) a[0].fill_between(sup, sp.array(m[0, :] - 2. * s).flatten(), sp.array(m[0, :] + 2. * s).flatten(), facecolor='lightblue', edgecolor='lightblue') a[0].plot(sup, m[0, :].flatten()) a[0].plot(sp.array(X[:, 0]).flatten(), Y, 'g.') ns = 500 R = ESutils.draw_support(g, lb, ub, ns, ESutils.SUPPORT_UNIFORM) w = sp.ones(ns) R2 = ESutils.draw_support(g, lb, ub, ns, ESutils.SUPPORT_SLICELCB, para=2.) w2 = sp.exp(-g.infer_LCB_post(R2, [[sp.NaN]] * ns, 2.)) a[0].twinx().plot(R2.flatten(), w2.flatten(), 'rx') [m0, V0] = g.infer_full_post(R, [[sp.NaN]] * ns) ndr = 10000 Z = g.draw_post(R, [[sp.NaN]] * ns, ndr) Z2 = g.draw_post(R2, [[sp.NaN]] * ns, ndr) H = sp.zeros(ns) H2 = sp.zeros(ns) for i in xrange(ndr): H[sp.argmin(Z[i, :])] += 1 H2[sp.argmin(Z2[i, :])] += 1
np=100 sup = sp.linspace(-1,1,np) Dp = [[sp.NaN]]*np Xp = sp.vstack([sp.array([i]) for i in sup]) [m,V] = g.infer_diag_post(Xp,Dp) f,a = plt.subplots(3) s = sp.sqrt(V[0,:]) a[0].fill_between(sup,sp.array(m[0,:]-2.*s).flatten(),sp.array(m[0,:]+2.*s).flatten(),facecolor='lightblue',edgecolor='lightblue') a[0].plot(sup,m[0,:].flatten()) a[0].plot(sp.array(X[:,0]).flatten(),Y,'g.') ns=500 R = ESutils.draw_support(g,lb,ub,ns,ESutils.SUPPORT_UNIFORM) w = sp.ones(ns) R2 = ESutils.draw_support(g,lb,ub,ns,ESutils.SUPPORT_SLICELCB,para=2.) w2 = sp.exp(-g.infer_LCB_post(R2,[[sp.NaN]]*ns,2.)) a[0].twinx().plot(R2.flatten(),w2.flatten(),'rx') [m0,V0] = g.infer_full_post(R,[[sp.NaN]]*ns) ndr=10000 Z = g.draw_post(R, [[sp.NaN]]*ns,ndr) Z2 = g.draw_post(R2, [[sp.NaN]]*ns,ndr) H = sp.zeros(ns) H2 = sp.zeros(ns) for i in xrange(ndr): H[sp.argmin(Z[i,:])]+=1 H2[sp.argmin(Z2[i,:])]+=1