-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replace prioritized_replay_buffer as PrioritizedBufferWrapper (#233)
* Add perwrapper * Add descriptions & Change config parameter * Delete prioritized_replay_buffer & Add descriptions * Change minor parameters name & descriptions * Fix isseus commented
- Loading branch information
1 parent
b8ab7ab
commit a302479
Showing
8 changed files
with
130 additions
and
85 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
# -*- coding: utf-8 -*- | ||
"""Abstract Buffer & BufferWrapper class. | ||
- Author: Euijin Jeong | ||
- Contact: euijin.jeong@medipixel.io | ||
""" | ||
|
||
from abc import ABC, abstractmethod | ||
from typing import Any, Tuple | ||
|
||
import numpy as np | ||
|
||
|
||
class BaseBuffer(ABC): | ||
"""Abstract Buffer used for replay buffer.""" | ||
|
||
@abstractmethod | ||
def add(self, transition: Tuple[Any, ...]) -> Tuple[Any, ...]: | ||
pass | ||
|
||
@abstractmethod | ||
def sample(self) -> Tuple[np.ndarray, ...]: | ||
pass | ||
|
||
@abstractmethod | ||
def __len__(self) -> int: | ||
pass | ||
|
||
|
||
class BufferWrapper(BaseBuffer): | ||
"""Abstract BufferWrapper used for buffer wrapper. | ||
Attributes: | ||
buffer (Buffer): Hold replay buffer as am attribute | ||
""" | ||
|
||
def __init__(self, base_buffer: BaseBuffer): | ||
"""Initialize a ReplayBuffer object. | ||
Args: | ||
base_buffer (int): ReplayBuffer which should be hold | ||
""" | ||
self.buffer = base_buffer | ||
|
||
def add(self, transition: Tuple[Any, ...]) -> Tuple[Any, ...]: | ||
return self.buffer.add(transition) | ||
|
||
def sample(self) -> Tuple[np.ndarray, ...]: | ||
return self.buffer.sample() | ||
|
||
def __len__(self) -> int: | ||
"""Return the current size of internal memory.""" | ||
return len(self.buffer) |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.