This repository was archived by the owner on Jun 16, 2025. It is now read-only.
Repository navigation
This repository was archived by the owner on Jun 16, 2025. It is now read-only.
About PER #2
Copy link
Copy link
Open
Description
Hi, could you please tell what kind of PER is this ? Have you ever tried standard PER to benchmark Jericho ?
Lines 29 to 64 in 20908da
| class PrioritizedReplayMemory(object): | |
| def __init__(self, capacity=100000, priority_fraction=0.0): | |
| self.priority_fraction = priority_fraction | |
| self.alpha_capacity = int(capacity * priority_fraction) | |
| self.beta_capacity = capacity - self.alpha_capacity | |
| self.alpha_memory, self.beta_memory = [], [] | |
| self.alpha_position, self.beta_position = 0, 0 | |
| def push(self, is_prior=False, *args): | |
| """Saves a transition.""" | |
| if self.priority_fraction == 0.0: | |
| is_prior = False | |
| if is_prior: | |
| if len(self.alpha_memory) < self.alpha_capacity: | |
| self.alpha_memory.append(None) | |
| self.alpha_memory[self.alpha_position] = Transition(*args) | |
| self.alpha_position = (self.alpha_position + 1) % self.alpha_capacity | |
| else: | |
| if len(self.beta_memory) < self.beta_capacity: | |
| self.beta_memory.append(None) | |
| self.beta_memory[self.beta_position] = Transition(*args) | |
| self.beta_position = (self.beta_position + 1) % self.beta_capacity | |
| def sample(self, batch_size): | |
| if self.priority_fraction == 0.0: | |
| from_beta = min(batch_size, len(self.beta_memory)) | |
| res = random.sample(self.beta_memory, from_beta) | |
| else: | |
| from_alpha = min(int(self.priority_fraction * batch_size), len(self.alpha_memory)) | |
| from_beta = min(batch_size - int(self.priority_fraction * batch_size), len(self.beta_memory)) | |
| res = random.sample(self.alpha_memory, from_alpha) + random.sample(self.beta_memory, from_beta) | |
| random.shuffle(res) | |
| return res | |
| def __len__(self): | |
| return len(self.alpha_memory) + len(self.beta_memory) |
Metadata
Metadata
Assignees
Labels
No labels
Activity