def run_search(self): print "begin PES:" try: del (self.pesobj) except: pass self.pesobj = PES.PES_inplane( self.X, self.Y, self.S, self.D, self.lb.flatten(), self.ub.flatten(), self.para['kindex'], self.para['mprior'], self.para['sprior'], self.para['axis'], self.para['value'], DH_SAMPLES=self.para['DH_SAMPLES'], DM_SAMPLES=self.para['DM_SAMPLES'], DM_SUPPORT=self.para['DM_SUPPORT'], DM_SLICELCBPARA=self.para['DM_SLICELCBPARA'], mode=self.para['SUPPORT_MODE'], noS=True) self.train_costest() [Qmin, ymin, ierror] = self.pesobj.search_acq(self.costest, self.para['sfn'], volper=self.para['volper']) return [Qmin, 0., [sp.NaN]]
def run_search(self): print "begin PESIS:" try: #print "aaa" del (self.pesobj) #print "bbb" except: print "ccc" self.pesobj = PES.PES(self.X, self.Y, self.S, self.D, self.lb.flatten(), self.ub.flatten(), self.para['kindex'], self.para['mprior'], self.para['sprior'], DH_SAMPLES=self.para['DH_SAMPLES'], DM_SAMPLES=self.para['DM_SAMPLES'], DM_SUPPORT=self.para['DM_SUPPORT'], DM_SLICELCBPARA=self.para['DM_SLICELCBPARA'], mode=self.para['SUPPORT_MODE'], noS=True) [xmin, ymin, ierror] = self.pesobj.search_pes(-1, volper=self.para['volper']) return [xmin, 0., [sp.NaN]]
def run_search(self): print "begin PES:" try: del (self.pesobj) except: pass self.pesobj = PES.PES(self.X, self.Y, self.S, self.D, self.lb.flatten(), self.ub.flatten(), self.para['kindex'], self.para['mprior'], self.para['sprior'], DH_SAMPLES=self.para['DH_SAMPLES'], DM_SAMPLES=self.para['DM_SAMPLES'], DM_SUPPORT=self.para['DM_SUPPORT'], DM_SLICELCBPARA=self.para['DM_SLICELCBPARA'], mode=self.para['SUPPORT_MODE']) [Qmin, ymin, ierror] = self.pesobj.search_acq(self.para['cfn'], self.para['logsl'], self.para['logsu'], volper=self.para['volper']) return [Qmin[:-1], 10**Qmin[-1], [sp.NaN]]
def PESvsaq(optstate, persist, **para): para = copy.deepcopy(para) if persist == None: persist = {'n': 0, 'd': len(para['ub'])} n = persist['n'] d = persist['d'] if n < para['nrandinit']: persist['n'] += 1 return randomaq(optstate, persist, **para) logger.info('PESvsaq') #logger.debug(sp.vstack([e[0] for e in optstate.ev])) #raise x = sp.vstack(optstate.x) y = sp.vstack(optstate.y) s = sp.vstack([e['s'] for e in optstate.ev]) dx = [e['d'] for e in optstate.ev] pesobj = PES.PES(x, y, s, dx, para['lb'], para['ub'], para['kindex'], para['mprior'], para['sprior'], DH_SAMPLES=para['DH_SAMPLES'], DM_SAMPLES=para['DM_SAMPLES'], DM_SUPPORT=para['DM_SUPPORT'], DM_SLICELCBPARA=para['DM_SLICELCBPARA'], mode=para['SUPPORT_MODE'], noS=para['noS']) [xmin, ymin, ierror] = pesobj.search_acq(para['cfn'], para['logsl'], para['logsu'], volper=para['volper']) logger.debug([xmin, ymin, ierror]) para['ev']['s'] = 10**xmin[-1] xout = [i for i in xmin[:-1]] return xout, para['ev'], persist, { 'HYPdraws': [k.hyp for k in pesobj.G.kf], 'mindraws': pesobj.Z, 'DIRECTmessage': ierror, 'PESmin': ymin } return
def pcs(self): self.pesobj = PES.PES(self.X, self.Y, self.S, self.D, self.lb.flatten(), self.ub.flatten(), self.para['kindex'], self.para['mprior'], self.para['sprior'], DH_SAMPLES=self.para['DH_SAMPLES'], DM_SAMPLES=self.para['DM_SAMPLES'], DM_SUPPORT=self.para['DM_SUPPORT'], DM_SLICELCBPARA=self.para['DM_SLICELCBPARA'], mode=self.para['SUPPORT_MODE']) xmin = self.reccomend() plt.figure(1) plt.plot(xmin[0], xmin[1], 'r.') print xmin plt.figure(2) plt.subplot(4, 1, 1) ns = 6000 sup = sp.linspace(-1, 1, ns) for i in xrange(2): X = sp.vstack([xmin for k in xrange(ns)]) print X.shape for j in xrange(ns): X[j, i] = sup[j] [m, v] = self.pesobj.G.infer_diag_post(X, [[sp.NaN]] * ns) s = sp.sqrt(v) plt.subplot(4, 1, 2 * i + 1) plt.fill_between(sup, (m - 2 * s).flatten(), (m + 2 * s).flatten(), facecolor='lightblue', edgecolor='lightblue') plt.plot(sup, m.flatten()) [m, v] = self.pesobj.G.infer_diag_post(X, [[i]] * ns) s = sp.sqrt(v) plt.subplot(4, 1, 2 * i + 2) plt.fill_between(sup, (m - 2 * s).flatten(), (m + 2 * s).flatten(), facecolor='lightblue', edgecolor='lightblue') plt.plot(sup, m.flatten(), 'r') p = sp.exp(-0.5 * (m**2) / v) plt.twinx().plot(sup, p.flatten(), 'g') return
def run_search(self): print "begin PESFS:" try: del (self.pesobj) except: pass self.pesobj = PES.PES(self.X, self.Y, self.S, self.D, self.lb.flatten(), self.ub.flatten(), self.para['kindex'], self.para['mprior'], self.para['sprior'], DH_SAMPLES=self.para['DH_SAMPLES'], DM_SAMPLES=self.para['DM_SAMPLES'], DM_SUPPORT=self.para['DM_SUPPORT'], DM_SLICELCBPARA=self.para['DM_SLICELCBPARA'], mode=self.para['SUPPORT_MODE']) [xmin, ymin, ierror] = self.pesobj.search_pes(self.sdefault, volper=self.para['volper']) return [xmin, self.para['s'], [sp.NaN]]
black = [0, 0, 0] red = [255, 0, 0] green = [0, 255, 0] blue = [0, 0, 255] w = 600 h = 600 # display list of line segments from contouring routine gr = racg.Graphics(w=600, h=600) gr.Clear() s = 0.5 * 10**8 k = 3 x0, y0 = 200, 100 gr.Clear() G = lambda s: lambda x, y: F(x, y) - s ix = 50 iy = 50 for y0 in range(1, 600, iy): for x0 in range(1, 600, ix): ctr.ShowLevelSet(gr, G(s), x0, y0, blue) gr.Point([x0, y0], red) ch = gr.Show("result", 15) if ch == ord('e'): break gr.Show("result", -1) fn = "ImplicitFunction-ContourVelocity-%02d.jpg" % k #gr.Save(fn) gr.Close()
def PESbsaq(optstate, persist, **para): para = copy.deepcopy(para) if persist == None: persist = {'n': 0, 'd': len(para['ub'])} n = persist['n'] d = persist['d'] if n < para['nrandinit']: persist['n'] += 1 para['ev']['xa'] = sp.random.uniform(para['xal'], para['xau']) return randomaq(optstate, persist, **para) logger.info('PESssaq') x = sp.hstack( [sp.vstack([e['xa'] for e in optstate.ev]), sp.vstack(optstate.x)]) y = sp.vstack(optstate.y) s = sp.vstack([e['s'] for e in optstate.ev]) dx = [e['d'] for e in optstate.ev] print "\n at pesinplane x {} axis 0".format(x) pesobj = PES.PES_inplane(x, y, s, dx, [para['xal']] + para['lb'], [para['xau']] + para['ub'], para['kindex'], para['mprior'], para['sprior'], 0, 0, DH_SAMPLES=para['DH_SAMPLES'], DM_SAMPLES=para['DM_SAMPLES'], DM_SUPPORT=para['DM_SUPPORT'], DM_SLICELCBPARA=para['DM_SLICELCBPARA'], mode=para['SUPPORT_MODE']) if para['traincfn']: # #print "XXXXXXXXXXXXXXx" cx = sp.vstack([e['xa'] for e in optstate.ev]) cc = sp.vstack([e for e in optstate.c]) #print cx #print cc #print optstate.ev #print optstate.x cfn = objectives.traincfn(cx, cc) """ if len(cc)%5==0: from matplotlib import pyplot as plt f,a = plt.subplots(1) xt = sp.linspace(0,1,100) m = sp.empty(100) for i in xrange(100): m[i]=cfn(0.,**{'xa':xt[i]}) a.plot(xt,m,'b') for i in xrange(len(optstate.c)): a.plot(cx[i,0],cc[i,0],'ro') plt.show() """ else: cfn = para['cfn'] [xmin, ymin, ierror] = pesobj.search_acq(cfn, lambda s: para['ev']['s'], volper=para['volper']) logger.debug([xmin, ymin, ierror]) para['ev']['xa'] = xmin[0] xout = [i for i in xmin[1:]] return xout, para['ev'], persist, { 'HYPdraws': [k.hyp for k in pesobj.G.kf], 'mindraws': pesobj.Z, 'DIRECTmessage': ierror, 'PESmin': ymin }
# Creates stitch outlines for each shape if args.noOutline is not True: subshapeLineGroups = prependShapeTraces(paths, subshapeLineGroups, maxStitchDistance=maxStitchDistance) #DEBUG lines: [[[Line(0+0j, 300+0j), Line(300+0j, 300+300j), Line(300+300j, 0+300j) , Line(0+300j, 0+0j)]]] PECCommands = createPECStitchRoutines(subshapeLineGroups, fillColors, threadWidth, maxStitchDistance=maxStitchDistance) left, right, bottom, top = shape.bbox() pec = PEC(label="simple", colors=PECColors, commands=PECCommands, size=complex(right - left, top - bottom)) # Render the PEC commands renderPEC(pec) pes = PES(PEC=pec, shape=shape) encodedPES = pes.encode() with open(args.outputFile, "w") as f: f.write(encodedPES) print("Wrote {} to disk.".format(args.outputFile)) if args.debugRendering: loadedPES = pyembroidery.read(args.outputFile) if loadedPES is not None: print("Generating debug image.") debugImagePath = replaceFilenameAndExtensionFromPath(args.outputFile, "debugPicture" + getFilenameAndExtensionFromPath(args.outputFile)[0], "png") pyembroidery.write_png(loadedPES, debugImagePath) print("Image written to disk: {}".format(debugImagePath)) else:
from scipy import linalg as spl from scipy import stats as sps from matplotlib import pyplot as plt import GPdc import PES import DIRECT # ------------------------------------------------------------------------- # 2d nt = 60 d = 2 lb = sp.array([-1.0] * d) ub = sp.array([1.0] * d) [X, Y, S, D] = ESutils.gen_dataset(nt, d, lb, ub, GPdc.SQUEXP, sp.array([1.5, 0.35, 0.30])) G = PES.makeG(X, Y, S, D, GPdc.SQUEXP, sp.array([0.0, -1.0, -1.0]), sp.array([1.0, 1.0, 1.0]), 6) nz = 8 Z = PES.drawmins_inplane( G, nz, sp.array([-1.0] * d), sp.array([1.0] * d), axis=0, value=0.0, SUPPORT=500, SLICELCB_PARA=1.0 ) print Z Ga = [ GPdc.GPcore(*PES.addmins_inplane(G, X, Y, S, D, Z[i, :], axis=0, value=0.0, MINPOLICY=PES.NOMIN) + [G.kf]) for i in xrange(nz) ] np = 220 sup = sp.linspace(-1, 1, np) Dp = [[sp.NaN]] * np Xp0 = sp.vstack([sp.array([i, Z[0, 1]]) for i in sup])
def directwrap(Q, extra): x = sp.array([Q]) s = sf acq = PES.PESgain(G, Ga, Z, x, [[sp.NaN]], [s]) R = -acq / cost(x, s) return (R, 0)
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 import PES nt=20 d=1 lb = sp.array([-1.]*d) ub = sp.array([1.]*d) [X,Y,S,D] = ESutils.gen_dataset(nt,d,lb,ub,GPdc.SQUEXP,sp.array([1.5,0.15])) G = PES.makeG(X,Y,S,D,GPdc.SQUEXP,sp.array([0.,-1.]),sp.array([1.,1.]),18) H = sp.vstack([i.hyp for i in G.kf]) f,a = plt.subplots(1) a.plot(H[:,0],H[:,1],'r.') 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(Xp,Dp) z=5 f,a = plt.subplots(z+2) for e,i in enumerate(sp.random.choice(range(m.shape[0]),size=z,replace=False)): s = sp.sqrt(V[i,:]) a[e].fill_between(sup,sp.array(m[i,:]-2.*s).flatten(),sp.array(m[i,:]+2.*s).flatten(),facecolor='lightblue',edgecolor='lightblue')
import ESutils import DIRECT import scipy as sp from scipy import linalg as spl from scipy import stats as sps from matplotlib import pyplot as plt import GPdc import PES nt=12 d=1 lb = sp.array([-1.]*d) ub = sp.array([1.]*d) [X,Y,S,D] = ESutils.gen_dataset(nt,d,lb,ub,GPdc.SQUEXP,sp.array([1.5,0.15])) G = PES.makeG(X,Y,S,D,GPdc.SQUEXP,sp.array([0.,-1.]),sp.array([1.,1.]),12) Z=PES.drawmins(G,8,sp.array([-1.]),sp.array([1.]),SUPPORT=400,SLICELCB_PARA=1.) Ga = GPdc.GPcore(*PES.addmins(G,X,Y,S,D,Z[0,:])+[G.kf]) 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) [mp,Vp] = Ga.infer_diag_post(Xp,Dp) f,a = plt.subplots(2) 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')
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 import PES nt = 20 d = 1 lb = sp.array([-1.] * d) ub = sp.array([1.] * d) [X, Y, S, D] = ESutils.gen_dataset(nt, d, lb, ub, GPdc.SQUEXP, sp.array([1.5, 0.15])) G = PES.makeG(X, Y, S, D, GPdc.SQUEXP, sp.array([0., -1.]), sp.array([1., 1.]), 18) H = sp.vstack([i.hyp for i in G.kf]) f, a = plt.subplots(1) a.plot(H[:, 0], H[:, 1], 'r.') 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(Xp, Dp) z = 5 f, a = plt.subplots(z + 2) for e, i in enumerate( sp.random.choice(range(m.shape[0]), size=z, replace=False)): s = sp.sqrt(V[i, :])
return val black = [0,0,0] red = [255,0,0] green = [0,255,0] blue = [0,0,255] w = 600 h = 600 # display list of line segments from contouring routine gr = racg.Graphics(w=600,h=600) gr.Clear() s = 0.5*10**8 k = 4 x0,y0 = 200,100 gr.Clear() G = lambda s: lambda x,y: F(x,y)-s ix = 100 iy = 100 for y0 in range(1,600,iy): for x0 in range(1,600,ix): ctr.ShowLevelSet(gr,G(s), x0, y0, blue, tmax = 50) gr.Point([x0,y0],red) ch = gr.Show("result",15) if ch == ord('e'): break gr.Show("result",-1) fn = "ImplicitFunction-ContourVelocity-%02d.jpg" % k #gr.Save(fn) gr.Close()
from scipy import stats as sps from matplotlib import pyplot as plt import GPdc import PES import DIRECT #------------------------------------------------------------------------- #2d nt = 60 d = 2 lb = sp.array([-1.] * d) ub = sp.array([1.] * d) [X, Y, S, D] = ESutils.gen_dataset(nt, d, lb, ub, GPdc.SQUEXP, sp.array([1.5, 0.35, 0.30])) G = PES.makeG(X, Y, S, D, GPdc.SQUEXP, sp.array([0., -1., -1.]), sp.array([1., 1., 1.]), 6) nz = 8 Z = PES.drawmins_inplane(G, nz, sp.array([-1.] * d), sp.array([1.] * d), axis=0, value=0., SUPPORT=500, SLICELCB_PARA=1.) print Z Ga = [ GPdc.GPcore(*PES.addmins_inplane( G, X, Y, S, D, Z[i, :], axis=0, value=0., MINPOLICY=PES.NOMIN) + [G.kf]) for i in xrange(nz)
lb = sp.array([-1.] * d) ub = sp.array([1.] * d) [X, Y, S, D] = ESutils.gen_dataset(nt, d, lb, ub, GPdc.SQUEXP, sp.array([1.5, 0.35, 0.30])) kindex = GPdc.SQUEXP mprior = sp.array([0.] + [-1.] * d) sprior = sp.array([1.] * (d + 1)) pesobj = PES.PES(X, Y, S, D, lb, ub, kindex, mprior, sprior, DH_SAMPLES=8, DM_SAMPLES=8, DM_SUPPORT=400, DM_SLICELCBPARA=1., mode=ESutils.SUPPORT_SLICEEI) np = 150 sup = sp.linspace(-1, 1, np) Dp = [[sp.NaN]] * np Sp = sp.array([[1e-3] * np]).T Xp0 = sp.vstack([sp.array([i, pesobj.Z[0, 1]]) for i in sup]) Xp1 = sp.vstack([sp.array([pesobj.Z[0, 0], i]) for i in sup]) f, a = plt.subplots(d)
sp.array([1.5, 0.55, 0.25])) kindex = GPdc.SQUEXP mprior = sp.array([0.] + [-1.] * d) sprior = sp.array([1.] * (d + 1)) axis = 0 value = 0. pesobj = PES.PES_inplane(X, Y, S, D, lb, ub, kindex, mprior, sprior, axis, value, DH_SAMPLES=8, DM_SAMPLES=8, DM_SUPPORT=400, DM_SLICELCBPARA=1., AM_POLICY=PES.NOMIN, mode=ESutils.SUPPORT_SLICEEI) def cfn(x): return 1. - (0.6 * x[0])**0.1 def sfn(x):