* doc fix

* change line

Co-authored-by: Trinkle23897 <463003665@qq.com>
This commit is contained in:
youkaichao 2020-07-08 08:30:01 +08:00 committed by GitHub
parent 9c7d31e5d6
commit dbbb859ec5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 16 deletions

View File

@ -100,14 +100,13 @@ class Batch:
* ``done`` the done flag of step :math:`t` ; * ``done`` the done flag of step :math:`t` ;
* ``obs_next`` the observation of step :math:`t+1` ; * ``obs_next`` the observation of step :math:`t+1` ;
* ``info`` the info of step :math:`t` (in ``gym.Env``, the ``env.step()``\ * ``info`` the info of step :math:`t` (in ``gym.Env``, the ``env.step()``\
function return 4 arguments, and the last one is ``info``); function returns 4 arguments, and the last one is ``info``);
* ``policy`` the data computed by policy in step :math:`t`; * ``policy`` the data computed by policy in step :math:`t`;
:class:`~tianshou.data.Batch` object can be initialized using wide variety :class:`~tianshou.data.Batch` object can be initialized by a wide variety
of arguments, starting with the key/value pairs or dictionary, but also of arguments, ranging from the key/value pairs or dictionary, to list and
list and Numpy arrays of :class:`dict` or Batch instances. In which case, Numpy arrays of :class:`dict` or Batch instances where each element is
each element is considered as an individual sample and get stacked considered as an individual sample and get stacked together:
together:
:: ::
>>> data = Batch([{'a': {'b': [0.0, "info"]}}]) >>> data = Batch([{'a': {'b': [0.0, "info"]}}])
@ -119,7 +118,7 @@ class Batch:
) )
:class:`~tianshou.data.Batch` has the same API as a native Python :class:`~tianshou.data.Batch` has the same API as a native Python
:class:`dict`. In this regard, one can access to stored data using string :class:`dict`. In this regard, one can access stored data using string
key, or iterate over stored data: key, or iterate over stored data:
:: ::
@ -132,7 +131,7 @@ class Batch:
b: [5, 5] b: [5, 5]
:class:`~tianshou.data.Batch` is also reproduce partially the Numpy API for :class:`~tianshou.data.Batch` also partially reproduces the Numpy API for
arrays. It also supports the advanced slicing method, such as batch[:, i], arrays. It also supports the advanced slicing method, such as batch[:, i],
if the index is valid. You can access or iterate over the individual if the index is valid. You can access or iterate over the individual
samples, if any: samples, if any:
@ -147,7 +146,6 @@ class Batch:
>>> for sample in data: >>> for sample in data:
>>> print(sample.a) >>> print(sample.a)
[0., 2.] [0., 2.]
[1., 3.]
>>> print(data.shape) >>> print(data.shape)
[1, 2] [1, 2]
@ -195,7 +193,7 @@ class Batch:
) )
Note that stacking of inconsistent data is also supported. In which case, Note that stacking of inconsistent data is also supported. In which case,
None is added in list or :class:`np.ndarray` of objects, 0 otherwise. ``None`` is added in list or :class:`np.ndarray` of objects, 0 otherwise.
:: ::
>>> data_1 = Batch(a=np.array([0.0, 2.0])) >>> data_1 = Batch(a=np.array([0.0, 2.0]))
@ -208,7 +206,7 @@ class Batch:
b: array([None, 'done'], dtype=object), b: array([None, 'done'], dtype=object),
) )
Also with method empty (which will set to 0 or ``None`` (with np.object)) Method ``empty_`` sets elements to 0 or ``None`` for ``np.object``.
:: ::
>>> data.empty_() >>> data.empty_()
@ -248,9 +246,9 @@ class Batch:
Convenience helpers are available to convert in-place the stored data into Convenience helpers are available to convert in-place the stored data into
Numpy arrays or Torch tensors. Numpy arrays or Torch tensors.
Finally, note that :class:`~tianshou.data.Batch` instance are serializable Finally, note that :class:`~tianshou.data.Batch` is serializable and
and therefore Pickle compatible. This is especially important for therefore Pickle compatible. This is especially important for distributed
distributed sampling. sampling.
""" """
def __init__(self, def __init__(self,
@ -618,7 +616,7 @@ class Batch:
def split(self, size: Optional[int] = None, def split(self, size: Optional[int] = None,
shuffle: bool = True) -> Iterator['Batch']: shuffle: bool = True) -> Iterator['Batch']:
"""Split whole data into multiple small batch. """Split whole data into multiple small batches.
:param int size: if it is ``None``, it does not split the data batch; :param int size: if it is ``None``, it does not split the data batch;
otherwise it will divide the data batch with the given size. otherwise it will divide the data batch with the given size.

View File

@ -424,7 +424,7 @@ class PrioritizedReplayBuffer(ReplayBuffer):
"""Update priority weight by indice in this buffer. """Update priority weight by indice in this buffer.
:param np.ndarray indice: indice you want to update weight :param np.ndarray indice: indice you want to update weight
:param np.ndarray new_weight: new priority weight you wangt to update :param np.ndarray new_weight: new priority weight you want to update
""" """
if self._replace: if self._replace:
if isinstance(indice, slice): if isinstance(indice, slice):