def ojf(x, s, d, override=False): #print "called ojf: "+str(x) try: x = x.flatten(0) except: pass xlow = [-2., -2.] xupp = [2., 2.] xthis = [ xlow[i] + 0.5 * (xin + 1) * (xupp[i] - xlow[i]) for i, xin in enumerate(x) ] hyp = [10**i for i in xthis] print hyp t0 = time.clock() llk = sp.clip( GPdc.GP_LKonly(X, Y, S, D, GPdc.kernel(GPdc.MAT52, 1, sp.array(hyp))).plk(pm, ps), -1e60, 1e60) t1 = time.clock() if llk < -1.: out = sp.log(-llk) + 1. else: out = -llk print "--->llk: {0} {1} t: {2}".format(llk, out, t1 - t0) return [out, t1 - t0]
def llks(self, hy, sub): t0 = time.clock() Xs = sp.empty([sub, self.d]) Ys = sp.empty([sub, 1]) Ss = sp.zeros([sub, 1]) Ds = [] ix = npr.choice(range(self.n), size=sub, replace=False) for i, x in enumerate(ix): Xs[i, :] = self.X[x, :] Ys[i, :] = self.Y[x, :] Ds.append(self.D[x]) t1 = time.clock() r = GPdc.GP_LKonly(Xs, Ys, Ss, Ds, GPdc.kernel(self.ki, self.d, hy)).llk() t2 = time.clock() #print [t1-t0,t2-t1] return [r, t2 - t0]
def f(loghyp): ub = hm + 1.8 * hs lb = hm - 1.8 * hs if all(loghyp < ub) and all(loghyp > lb): r = GPdc.GP_LKonly( X, Y, S, D, GPdc.kernel(ki, X.shape[1], [10**i for i in loghyp])).plk(hm, hs) if sp.isnan(r): class MJMError(Exception): pass print 'nan from GPLKonly with input' print[X, Y, S, D, ki, hm, hs, n, burn, subsam] raise MJMError('nan from GPLKonly with input') else: r = -1e99 #print [loghyp, r] return r
def ojfa(x, s, d, override=False): #print "called ojf: "+str(x) try: x = x.flatten(0) except: pass xlow = [-2., -2.] xupp = [2., 2.] xthis = [ xlow[i] + 0.5 * (xin + 1) * (xupp[i] - xlow[i]) for i, xin in enumerate(x[1:]) ] hyp = [10**i for i in xthis] #hyp = [10**i for i in x.flatten()[1:]] print hyp t0 = time.clock() sub = x.flatten()[0] npts = int((1. - 0.9 * sub) * n) if override: npts = n print "subsampling {0} of {1} at x[0]={2}".format(npts, n, x.flatten()[0]) ps = npr.choice(range(n), size=npts, replace=False) Xd = sp.vstack([X[i] for i in ps]) Yd = sp.vstack([Y[i] for i in ps]) Sd = sp.vstack([S[i] for i in ps]) Dd = [[sp.NaN]] * npts llk = GPdc.GP_LKonly(Xd, Yd, Sd, Dd, GPdc.kernel(GPdc.MAT52, 1, sp.array(hyp))).plk(pm, ps) t1 = time.clock() if llk < -1.: out = sp.log(-llk) + 1. else: out = -llk print "--->llk: {0} {1} t: {2}".format(llk, out, t1 - t0) return [out, t1 - t0]
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): A[i, j] = GPdc.GP_LKonly(X, Y, S, D, GPdc.kernel(GPdc.SQUEXP, 2, sp.array([hi, hj]))).plk( sp.array([0., -1.]), sp.array([1., 1.])) A = -sp.log10(-A + sp.amax(A) + 1.) plt.figure() plt.contour(sp.log10(sup), sp.log10(sup), A, 30) print 'draw hyps 1' X = ESutils.drawhyp_plk(X, Y, S, D, GPdc.SQUEXP, sp.array([0., -1.]), sp.array([1., 1.]), 200) plt.plot(sp.log10(X[:, 1]), sp.log10(X[:, 0]), 'b.') #lots of points nt = 100 X = ESutils.draw_support(1, sp.array([-1.]), sp.array([1.]), nt, ESutils.SUPPORT_UNIFORM) D = [[sp.NaN]] * (nt)
def llk(self, hy): t0 = time.clock() r = GPdc.GP_LKonly(self.X, self.Y, self.S, self.D, GPdc.kernel(self.ki, self.d, hy)).llk() t1 = time.clock() return [r, t1 - t0]