示例#1
0
文件: search.py 项目: markm541374/GPc
def PESVS(ojf, lb, ub, ki, s, b, cfn, lsl, lsu, fname):
    overridemaxsteps = 200
    sp.random.seed(int(os.urandom(4).encode('hex'), 16))
    para = dict()
    para['kindex'] = ki[0]
    para['mprior'] = ki[1]
    para['sprior'] = ki[2]
    para['s'] = s
    para['ninit'] = 10
    para['volper'] = 1e-6
    para['DH_SAMPLES'] = 12
    para['DM_SAMPLES'] = 12
    para['DM_SUPPORT'] = 1200
    para['DM_SLICELCBPARA'] = 1.
    para['SUPPORT_MODE'] = [ESutils.SUPPORT_LAPAPR]
    para['cfn'] = cfn
    para['logsl'] = lsl
    para['logsu'] = lsu
    para['s'] = 10**lsu
    if os.path.exists(fname):
        print "starting from " + str(fname)
        OE = OPTutils.PESVS(ojf,
                            lb,
                            ub,
                            para,
                            initstate=pickle.load(open(fname, 'rb')))
    else:
        print "fresh start"
        OE = OPTutils.PESVS(ojf, lb, ub, para)

    if sum(OE.C) >= b:
        print "no further steps needed"
        k = 0
        while sum(OE.C[:k]) < b:

            k += 1
        state = [
            OE.X[:k, :], OE.Y[:k, :], OE.S[:k, :], OE.D[:k], OE.R[:k, :],
            OE.C[:k], OE.T[:k], OE.Tr[:k], OE.Ymin[:k], OE.Xmin[:k, :],
            OE.Yreg[:k, :], OE.Rreg[:k, :]
        ]
    else:
        pbar = tqdm(total=(b - sum(OE.C)))
        while sum(OE.C) < b and len(OE.C) < overridemaxsteps:
            print "used {0} of {1} eval budget".format(sum(OE.C), b)
            pbar.update(OE.C[-1])
            OE.step()
        state = [
            OE.X, OE.Y, OE.S, OE.D, OE.R, OE.C, OE.T, OE.Tr, OE.Ymin, OE.Xmin,
            OE.Yreg, OE.Rreg
        ]
        pickle.dump(state, open(fname, 'wb'))
    return state
示例#2
0
para['volper'] = 1e-7
para['DH_SAMPLES'] = 8
para['DM_SAMPLES'] = 8
para['DM_SUPPORT'] = 800
para['DM_SLICELCBPARA'] = 1.
para['SUPPORT_MODE'] = [ESutils.SUPPORT_SLICELCB, ESutils.SUPPORT_SLICEPM]
para['cfn'] = lambda x, s: ((1e-6) / s)**0.2
para['logsl'] = -8.
para['logsu'] = -2.
"""
import cProfile, pstats, StringIO
pr = cProfile.Profile()
pr.enable()
"""

OV = OPTutils.PESVS(ojf, lb, ub, para)
for i in tqdm(xrange(runn)):
    try:
        OV.step()
    except RuntimeError as e:
        print e
        break
    OE.step()

f, a = plt.subplots(7)

OE.plot(truexmin, trueymin, a, 'r')
OV.plot(truexmin, trueymin, a, 'g')
#OS.plot(truexmin,a,'b')

plt.show()