in level_replay/level_sampler.py [0:0]
def sample(self, strategy=None):
if not strategy:
strategy = self.strategy
if strategy == 'random':
seed_idx = np.random.choice(range((len(self.seeds))))
seed = self.seeds[seed_idx]
return int(seed)
if strategy == 'sequential':
seed_idx = self.next_seed_index
self.next_seed_index = (self.next_seed_index + 1) % len(self.seeds)
seed = self.seeds[seed_idx]
return int(seed)
num_unseen = (self.unseen_seed_weights > 0).sum()
proportion_seen = (len(self.seeds) - num_unseen)/len(self.seeds)
if self.replay_schedule == 'fixed':
if proportion_seen >= self.rho:
# Sample replay level with fixed prob = 1 - nu OR if all levels seen
if np.random.rand() > self.nu or not proportion_seen < 1.0:
return self._sample_replay_level()
# Otherwise, sample a new level
return self._sample_unseen_level()
else: # Default to proportionate schedule
if proportion_seen >= self.rho and np.random.rand() < proportion_seen:
return self._sample_replay_level()
else:
return self._sample_unseen_level()