import gpbo import scipy as sp #dimensionality D=2 #noise variance s=0. #number of step to take n=100 #define a simple 2d objective in x which also varies with respect to the environmental variable def f(x,**ev): y=-sp.cos(x[0])-sp.cos(x[1])+2 #fixed cost c=1. #noise n = sp.random.normal()*s #we want to check the noiseless value when evaluating performance if 'cheattrue' in ev.keys(): if ev['cheattrue']: n=0 print('f inputs x:{} ev:{} outputs y:{} (n:{}) c:{}'.format(x,ev,y+n,n,c)) return y+n,c,dict() #arguments to generate default config are objective function, dimensionality,number of initialization points, number of steps, noise variance, result directory and result filename C=gpbo.core.config.switchdefault(f,D,10,n,s,'results','stopping.csv') #set the target global regret C.choosepara['regretswitch']=1e-2 out = gpbo.search(C) print out
def runexp(f, lb, ub, path, nreps, confs, indexoffset=0): for i_ in xrange(nreps): ii = i_ + indexoffset for C in confs: if C[0][:2] == 'ei': C[1].path = path C[1].fname = '{}_{}.csv'.format(C[0], ii) C[1].aqpara['lb'] = lb C[1].aqpara['ub'] = ub C[1].reccpara['lb'] = lb C[1].reccpara['ub'] = ub def wrap(x, **ev): tmp = copy.deepcopy(ev) tmp['xa'] = 0 return f(x, **tmp) C[1].ojf = wrap try: out = gpbo.search(C[1]) except: pass elif C[0][:5] == 'pesfs': C[1].path = path C[1].fname = '{}_{}.csv'.format(C[0], ii) C[1].aqpara['lb'] = lb C[1].aqpara['ub'] = ub C[1].reccpara['lb'] = lb C[1].reccpara['ub'] = ub def wrap(x, **ev): tmp = copy.deepcopy(ev) tmp['xa'] = 0 return f(x, **tmp) C[1].ojf = wrap try: out = gpbo.search(C[1]) except: pass elif C[0][:5] == 'pesbs': C[1].path = path C[1].fname = '{}_{}.csv'.format(C[0], ii) C[1].aqpara['lb'] = [i for i in lb] C[1].aqpara['ub'] = [i for i in ub] C[1].reccpara['lb'] = [i for i in lb] C[1].reccpara['ub'] = [i for i in ub] C[1].ojf = f try: out = gpbo.search(C[1]) except: pass elif C[0][:9] == 'switching': C[1].path = path C[1].fname = '{}_{}.csv'.format(C[0], ii) C[1].ojf = f try: out = gpbo.search(C[1]) except: pass elif C[0][:5] == 'pesvs': C[1].path = path C[1].fname = '{}_{}.csv'.format(C[0], ii) C[1].aqpara['lb'] = [i for i in lb] C[1].aqpara['ub'] = [i for i in ub] C[1].reccpara['lb'] = [i for i in lb] C[1].reccpara['ub'] = [i for i in ub] C[1].ojf = f try: out = gpbo.search(C[1]) except: pass elif C[0][:4] == 'mtbo': try: optmtbo(f, lb, ub, 1. - (1. / C[1]['lowtask']), C[1]['nsteps'], ninit=C[1]['ninit'], fpath=path, fname='{}_{}.csv'.format(C[0], ii), mod=C[1]['switchestimator']) except: pass elif C[0][:7] == 'fabolas': try: optfabolas(f, lb, ub, C[1]['nsteps'], C[1]['ninit'], fname='{}_{}.csv'.format(C[0], ii), fpath=path) except: raise elif C[0][:6] == 'fabmod': try: optfabolas_mod(f, lb, ub, C[1]['nsteps'], C[1]['ninit'], fname='{}_{}.csv'.format(C[0], ii), fpath=path, switchestimator=C[1]['switchestimator'], switchkernel=C[1]['switchkernel'], timelimit=C[1]['timelimit']) except: raise else: print("not an optimization method")