Skip to content

Instantly share code, notes, and snippets.

@dariocazzani
Created May 8, 2018 19:48
Show Gist options
  • Save dariocazzani/e6594e482cd6ce7363a1a4a1491a1571 to your computer and use it in GitHub Desktop.
Save dariocazzani/e6594e482cd6ce7363a1a4a1491a1571 to your computer and use it in GitHub Desktop.
WorldModels-VAE-train
def train():
es = cma.CMAEvolutionStrategy(_NUM_PARAMS * [0], 0.1, {'popsize': 16})
rewards_through_gens = []
generation = 1
try:
while not es.stop():
solutions = es.ask()
with mp.Pool(mp.cpu_count()) as p:
rewards = list(tqdm.tqdm(p.imap(play, list(solutions)), total=len(solutions)))
es.tell(solutions, rewards)
rewards = np.array(rewards) *(-1.)
generation+=1
rewards_through_gens.append(rewards)
np.save('rewards', rewards_through_gens)
except (KeyboardInterrupt, SystemExit):
print("Manual Interrupt")
except Exception as e:
print("Exception: {}".format(e))
return es
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment