Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- envs = [gym.make(self.env_name) for _ in range(multiprocessing.cpu_count())]
- amount_per_thread = int(np.floor(self.population_size / multiprocessing.cpu_count()))
- left_over = self.population_size - amount_per_thread * multiprocessing.cpu_count()
- fitnesses = np.zeros(len(self.population))
- def get_weights_reward(begin, size, env):
- for i in range(begin, begin + size):
- fitnesses[i] = -self.get_reward(self.population[i],
- self.sess,
- env,
- self.meta)
- threads = []
- idx = 0
- for i in range(multiprocessing.cpu_count()):
- amt = (amount_per_thread + 1) if i < left_over else amount_per_thread
- thread = threading.Thread(target=get_weights_reward,
- args=[idx, amt, envs[i]])
- threads.append(thread)
- idx += amt
- assert idx == len(self.population)
- for t in threads:
- t.start()
- for t in threads:
- t.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement