def learn_xnes_batch(): x0 = np.array([0.0, 0.0, 0.0]) l = opt.XNES(objf_batch, x0) l.minimize = True l.mustMinimize = True l.verbose = False l.maxLearningSteps = int(args["<n>"]) l.batchSize = 25 r = l.learn() return r
def learn_xnes(x0=np.array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0])): try: l = opt.XNES(objf, x0) l.minimize = True l.mustMinimize = True l.verbose = False l.maxLearningSteps = int(args["<n>"]) l.batchSize = 25 r = l.learn() return r except: print("errrrrrrrrrrror single learning")
p.wait() objs = [float(x.stdout.read()) for x in processes] sum_objs = sum(objs) return (sum_objs) print("blablabla") for f in args["<swf_file>"]: print(type(f)) print("performance of optimized policy on training set:") #x0 = array([0.0 for e in norm[0]]) x0 = array([0.0, 0.0, 0.0, 0.0, 0.0, 0.0]) import pybrain.optimization as opt lopt = [ ("xnes", opt.XNES(objf, x0)), # ("r1",opt.Rank1NES(objf, x0)), # ("snes",opt.SNES(objf, x0)), # ("fem",opt.FEM(objf, x0)), # ("ves",opt.VanillaGradientEvolutionStrategies(objf, x0)), # ("memetic",opt.MemeticSearch(objf, x0)), # ("inmemetic",opt.InnerMemeticSearch(objf, x0)), # ("imemetic",opt.InverseMemeticSearch(objf, x0)), # ("inimemetic",opt.InnerInverseMemeticSearch(objf, x0)), # ("pso",opt.ParticleSwarmOptimizer(objf, x0)), # ("ga",opt.GA(objf, x0)), # ("spsa",opt.SimpleSPSA(objf, x0)), # ("pgpe",opt.PGPE(objf, x0)), # ("es",opt.ES(objf, x0)) ] for desc, l in lopt:
def objf(x): processes = [ subprocess.Popen(getperf(f, x), stdout=subprocess.PIPE, shell=True) for f in args["<swf_file>"] ] for p in processes: if p.poll() is None: p.wait() objs = [float(x.stdout.read()) for x in processes] return (sum(objs)) print("performance of optimized policy on training set:") x0 = array([0.0, 0.0]) import pybrain.optimization as opt lopt = [("xnes", opt.XNES(objf, x0))] # ("snes",opt.SNES(objf, x0)), # ("fem",opt.FEM(objf, x0)), # ("memetic",opt.MemeticSearch(objf, x0)), # ("inmemetic",opt.InnerMemeticSearch(objf, x0)), # ("imemetic",opt.InverseMemeticSearch(objf, x0)), # ("inimemetic",opt.InnerInverseMemeticSearch(objf, x0)), # ("spsa",opt.SimpleSPSA(objf, x0)), # ("pgpe",opt.PGPE(objf, x0)), # ("es",opt.ES(objf, x0))] for desc, l in lopt: l.minimize = True l.mustMinimize = True l.maxEvaluations = int(args["<n>"]) r = l.learn() print(desc)