Created
May 8, 2018 19:48
-
-
Save dariocazzani/e6594e482cd6ce7363a1a4a1491a1571 to your computer and use it in GitHub Desktop.
WorldModels-VAE-train
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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