コード例 #1
0
    def __init__(self, size, alpha):
        """Create Prioritized Replay buffer.

        Parameters
        ----------
        size: int
            Max number of transitions to store in the buffer. When the buffer
            overflows the old memories are dropped.
        alpha: float
            how much prioritization is used
            (0 - no prioritization, 1 - full prioritization)

        See Also
        --------
        ReplayBuffer.__init__
        """
        super(PrioritizedReplayBuffer, self).__init__(size)
        assert alpha >= 0
        self._alpha = alpha

        self.it_capacity = 1
        while self.it_capacity < size*2:     # We use double the soft capacity of the PER for the segment trees to allow for any overflow over the soft capacity limit before samples are removed
            self.it_capacity *= 2

        self._it_sum = SumSegmentTree(self.it_capacity)
        self._it_min = MinSegmentTree(self.it_capacity)
        self._max_priority = 1.0
コード例 #2
0
ファイル: buffer.py プロジェクト: mahaitongdae/mpg
    def __init__(self, args, buffer_id):
        """Create Prioritized Replay buffer.

        Parameters
        ----------
        size: int
          Max number of transitions to store in the buffer. When the buffer
          overflows the old memories are dropped.
        alpha: float
          how much prioritization is used
          (0 - no prioritization, 1 - full prioritization)
        beta: float
          To what degree to use importance weights
          (0 - no corrections, 1 - full correction)

        See Also
        --------
        ReplayBuffer.__init__
        """
        super(PrioritizedReplayBuffer, self).__init__(args, buffer_id)
        assert self.args.alpha > 0
        self._alpha = args.replay_alpha
        self._beta = args.replay_beta

        it_capacity = 1
        while it_capacity < self.args.size:
            it_capacity *= 2

        self._it_sum = SumSegmentTree(it_capacity)
        self._it_min = MinSegmentTree(it_capacity)
        self._max_priority = 1.0
コード例 #3
0
ファイル: replay_buffer.py プロジェクト: LQNew/LWDRLD
    def __init__(self, max_size, alpha):
        """Create Prioritized Replay buffer.

		Parameters
		----------
		max_size: int
			Max number of transitions to store in the buffer. 
			When the buffer overflows the old memories are dropped.
		alpha: float
			how much prioritization is used (0: no prioritization, 1: full prioritization)
		
		See Also
		--------
		ReplayBuffer.__init__
		"""
        super(PrioritizedReplayBuffer, self).__init__(max_size)
        assert alpha >= 0
        self._alpha = alpha

        it_capacity = 1
        while it_capacity < max_size:
            it_capacity *= 2

        self._it_sum = SumSegmentTree(it_capacity)
        self._it_min = MinSegmentTree(it_capacity)
        self._max_priority = 1.0
コード例 #4
0
    def __init__(self,
                 size,
                 frame_history_len,
                 alpha,
                 num_branches,
                 non_pixel_dimension,
                 add_non_pixel=False):
        """
        ----------
        alpha: float
            how much prioritization is used
            (0 - no prioritization, 1 - full prioritization)
        """
        super(PrioritizedReplayBuffer,
              self).__init__(size, frame_history_len, non_pixel_dimension,
                             add_non_pixel)

        self.num_branches = num_branches

        assert alpha > 0
        self._alpha = alpha

        it_capacity = 1
        while it_capacity < size:
            it_capacity *= 2

        self._it_sum = SumSegmentTree(it_capacity)
        self._it_min = MinSegmentTree(it_capacity)
        self._max_priority = 1.0
コード例 #5
0
    def __init__(self, size, alpha, device):
        #print(self.__mro__)
        super().__init__(size, device)
        assert alpha >= 0
        self._alpha = alpha
        it_capacity = 2
        while it_capacity < size:
            it_capacity *= 2

        self._it_sum = SumSegmentTree(it_capacity)
        self._it_min = MinSegmentTree(it_capacity)
        self._max_priority = 1.0
コード例 #6
0
 def _add_type_if_not_exist(self, type_id):  # O(1)
     if type_id in self.types:  # check it to avoid double insertion
         return False
     self.types[type_id] = len(self.types)
     self.type_values.append(self.types[type_id])
     self.type_keys.append(type_id)
     self.batches.append([])
     self._batches_next_idx.append(0)
     self._it_sum.append(SumSegmentTree(self._it_capacity))
     self._it_min.append(
         MinSegmentTree(self._it_capacity,
                        neutral_element=(float('inf'), -1)))
     return True
コード例 #7
0
ファイル: memory.py プロジェクト: majkee15/gym_lab
 def __init__(self,
              alpha=0.6,
              capacity=100000,
              replace=False,
              tuple_class=Transition):
     super().__init__(capacity, replace, tuple_class)
     assert alpha >= 0
     self.max_priority, self.tree_ptr = 1.0, 0
     self.alpha = alpha
     # capacity must be positive and a power of 2.
     # tree_capacity = 1
     # while tree_capacity < self.capacity:
     #     tree_capacity *= 2
     # Tree capacity has to be a power of 2
     m = np.ceil(np.log(self.capacity) / np.log(2))
     tree_capacity = np.power(2, m).astype(int)
     self.sum_tree = SumSegmentTree(tree_capacity)
     self.min_tree = MinSegmentTree(tree_capacity)
コード例 #8
0
    def __init__(self,
                 obs_dim: int,
                 size: int,
                 batch_size: int,
                 alpha: float = 0.6):
        """Initialization."""
        assert alpha >= 0

        super(PrioritizedReplayBuffer, self).__init__(obs_dim, size,
                                                      batch_size)
        self.max_priority, self.tree_ptr = 1.0, 0
        self.alpha = alpha

        # capacity must be positive and a power of 2.
        tree_capacity = 1
        while tree_capacity < self.max_size:
            tree_capacity *= 2

        self.sum_tree = SumSegmentTree(tree_capacity)
        self.min_tree = MinSegmentTree(tree_capacity)