本文整理匯總了Python中baselines.common.segment_tree.SumSegmentTree方法的典型用法代碼示例。如果您正苦於以下問題:Python segment_tree.SumSegmentTree方法的具體用法?Python segment_tree.SumSegmentTree怎麽用?Python segment_tree.SumSegmentTree使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類baselines.common.segment_tree
的用法示例。
在下文中一共展示了segment_tree.SumSegmentTree方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: __init__
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
def __init__(self,
limit,
alpha,
transition_small_epsilon=1e-6,
demo_epsilon=0.2,
nb_rollout_steps=100):
super(PrioritizedMemory, self).__init__(limit, nb_rollout_steps)
assert alpha > 0
self._alpha = alpha
self._transition_small_epsilon = transition_small_epsilon
self._demo_epsilon = demo_epsilon
it_capacity = 1
while it_capacity < self.maxsize:
it_capacity *= 2 # Size must be power of 2
self._it_sum = SumSegmentTree(it_capacity)
self._it_min = MinSegmentTree(it_capacity)
self._max_priority = 1.0
示例2: __init__
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
def __init__(self, size, alpha, epsilon, timesteps, initial_p, final_p):
super(DoublePrioritizedReplayBuffer, self).__init__(size)
assert alpha > 0
self._alpha = alpha
self._epsilon = epsilon
self._beta_schedule = LinearSchedule(timesteps, initial_p=initial_p, final_p=final_p)
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
self._it_sum2 = SumSegmentTree(it_capacity)
self._it_min2 = MinSegmentTree(it_capacity)
self._max_priority2 = 1.0
示例3: __init__
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
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
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
示例4: __init__
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
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
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: test_tree_set
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
def test_tree_set():
tree = SumSegmentTree(4)
tree[2] = 1.0
tree[3] = 3.0
assert np.isclose(tree.sum(), 4.0)
assert np.isclose(tree.sum(0, 2), 0.0)
assert np.isclose(tree.sum(0, 3), 1.0)
assert np.isclose(tree.sum(2, 3), 1.0)
assert np.isclose(tree.sum(2, -1), 1.0)
assert np.isclose(tree.sum(2, 4), 4.0)
示例6: test_tree_set_overlap
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
def test_tree_set_overlap():
tree = SumSegmentTree(4)
tree[2] = 1.0
tree[2] = 3.0
assert np.isclose(tree.sum(), 3.0)
assert np.isclose(tree.sum(2, 3), 3.0)
assert np.isclose(tree.sum(2, -1), 3.0)
assert np.isclose(tree.sum(2, 4), 3.0)
assert np.isclose(tree.sum(1, 2), 0.0)
示例7: test_prefixsum_idx
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
def test_prefixsum_idx():
tree = SumSegmentTree(4)
tree[2] = 1.0
tree[3] = 3.0
assert tree.find_prefixsum_idx(0.0) == 2
assert tree.find_prefixsum_idx(0.5) == 2
assert tree.find_prefixsum_idx(0.99) == 2
assert tree.find_prefixsum_idx(1.01) == 3
assert tree.find_prefixsum_idx(3.00) == 3
assert tree.find_prefixsum_idx(4.00) == 3
示例8: test_prefixsum_idx2
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
def test_prefixsum_idx2():
tree = SumSegmentTree(4)
tree[0] = 0.5
tree[1] = 1.0
tree[2] = 1.0
tree[3] = 3.0
assert tree.find_prefixsum_idx(0.00) == 0
assert tree.find_prefixsum_idx(0.55) == 1
assert tree.find_prefixsum_idx(0.99) == 1
assert tree.find_prefixsum_idx(1.51) == 2
assert tree.find_prefixsum_idx(3.00) == 3
assert tree.find_prefixsum_idx(5.50) == 3
示例9: __init__
# 需要導入模塊: from baselines.common import segment_tree [as 別名]
# 或者: from baselines.common.segment_tree import SumSegmentTree [as 別名]
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
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