## implementation I implemented HER solely as a replay buffer. It is done by temporarily directly re-writing transitions storage (`self._meta`) during the `sample_indices()` call. The original transitions are cached and will be restored at the beginning of the next sampling or when other methods is called. This will make sure that. for example, n-step return calculation can be done without altering the policy. There is also a problem with the original indices sampling. The sampled indices are not guaranteed to be from different episodes. So I decided to perform re-writing based on the episode. This guarantees that the sampled transitions from the same episode will have the same re-written goal. This also make the re-writing ratio calculation slightly differ from the paper, but it won't be too different if there are many episodes in the buffer. In the current commit, HER replay buffer only support 'future' strategy and online sampling. This is the best of HER in term of performance and memory efficiency. I also add a few more convenient replay buffers (`HERVectorReplayBuffer`, `HERReplayBufferManager`), test env (`MyGoalEnv`), gym wrapper (`TruncatedAsTerminated`), unit tests, and a simple example (examples/offline/fetch_her_ddpg.py). ## verification I have added unit tests for almost everything I have implemented. HER replay buffer was also tested using DDPG on [`FetchReach-v3` env](https://github.com/Farama-Foundation/Gymnasium-Robotics). I used default DDPG parameters from mujoco example and didn't tune anything further to get this good result! (train script: examples/offline/fetch_her_ddpg.py). 
143 lines
2.2 KiB
ReStructuredText
143 lines
2.2 KiB
ReStructuredText
tianshou.data
|
|
=============
|
|
|
|
|
|
Batch
|
|
-----
|
|
|
|
.. autoclass:: tianshou.data.Batch
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
|
|
Buffer
|
|
------
|
|
|
|
ReplayBuffer
|
|
~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.ReplayBuffer
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
PrioritizedReplayBuffer
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.PrioritizedReplayBuffer
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
HERReplayBuffer
|
|
~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.HERReplayBuffer
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
ReplayBufferManager
|
|
~~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.ReplayBufferManager
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
PrioritizedReplayBufferManager
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.PrioritizedReplayBufferManager
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
|
|
HERReplayBufferManager
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.HERReplayBufferManager
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
VectorReplayBuffer
|
|
~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.VectorReplayBuffer
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
PrioritizedVectorReplayBuffer
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.PrioritizedVectorReplayBuffer
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
HERVectorReplayBuffer
|
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.HERVectorReplayBuffer
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
CachedReplayBuffer
|
|
~~~~~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.CachedReplayBuffer
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
Collector
|
|
---------
|
|
|
|
Collector
|
|
~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.Collector
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
AsyncCollector
|
|
~~~~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.AsyncCollector
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|
|
|
|
|
|
Utils
|
|
-----
|
|
|
|
to_numpy
|
|
~~~~~~~~
|
|
|
|
.. autofunction:: tianshou.data.to_numpy
|
|
|
|
to_torch
|
|
~~~~~~~~
|
|
|
|
.. autofunction:: tianshou.data.to_torch
|
|
|
|
to_torch_as
|
|
~~~~~~~~~~~
|
|
|
|
.. autofunction:: tianshou.data.to_torch_as
|
|
|
|
SegmentTree
|
|
~~~~~~~~~~~
|
|
|
|
.. autoclass:: tianshou.data.SegmentTree
|
|
:members:
|
|
:undoc-members:
|
|
:show-inheritance:
|