这是indexloc提供的服务,不要输入任何密码
Skip to content

write tutorials to specify the standard of Batch #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 29 commits into from
Jul 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
3a565b1
add doc for len exceptions
youkaichao Jul 16, 2020
1f7964b
doc move; unify is_scalar_value function
youkaichao Jul 17, 2020
1598a01
remove some issubclass check
youkaichao Jul 17, 2020
62fda2f
bugfix for shape of Batch(a=1)
youkaichao Jul 17, 2020
32ce479
keep moving doc
youkaichao Jul 17, 2020
9ae8211
keep writing batch tutorial
youkaichao Jul 17, 2020
548fdfb
draft version of Batch tutorial done
youkaichao Jul 17, 2020
35827bc
improving doc
youkaichao Jul 17, 2020
8775e98
keep improving doc
youkaichao Jul 17, 2020
679d966
batch tutorial done
youkaichao Jul 17, 2020
44034b6
rename _is_number
youkaichao Jul 17, 2020
94f69b1
rename _is_scalar
youkaichao Jul 17, 2020
6ec46c1
shape property do not raise exception
youkaichao Jul 18, 2020
17d907a
restore some doc string
youkaichao Jul 18, 2020
1b2b087
grammarly [ci skip]
Trinkle23897 Jul 18, 2020
80fa524
grammarly + fix warning of building docs
Trinkle23897 Jul 18, 2020
d112f5a
polish docs
Trinkle23897 Jul 18, 2020
697a754
trim and re-arrange batch tutorial
youkaichao Jul 18, 2020
316914b
go straight to the point
youkaichao Jul 18, 2020
c5755ee
minor fix for batch doc
Trinkle23897 Jul 18, 2020
40660a9
add shape / len in basic usage
youkaichao Jul 18, 2020
c70a66f
keep improving tutorial
youkaichao Jul 18, 2020
38980fd
unify _to_array_with_correct_type to remove duplicate code
youkaichao Jul 18, 2020
b000381
delegate type convertion to Batch.__init__
youkaichao Jul 18, 2020
67068dc
further delegate type convertion to Batch.__init__
youkaichao Jul 18, 2020
736023a
bugfix for setattr
youkaichao Jul 18, 2020
c7ed637
add a _parse_value function
youkaichao Jul 19, 2020
39a393e
remove dummy function call
youkaichao Jul 19, 2020
67aee9e
polish docs
Trinkle23897 Jul 19, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docs/_static/images/aggregation.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images/batch_reserve.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/_static/images/batch_tree.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ Tianshou is still under development, you can also check out the documents in sta

tutorials/dqn
tutorials/concepts
tutorials/batch
tutorials/trick
tutorials/cheatsheet

Expand Down
491 changes: 491 additions & 0 deletions docs/tutorials/batch.rst

Large diffs are not rendered by default.

42 changes: 34 additions & 8 deletions docs/tutorials/concepts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,42 @@ Here is a more detailed description, where ``Env`` is the environment and ``Mode
:align: center
:height: 300

Data Batch
----------

.. automodule:: tianshou.data.Batch
:members:
:noindex:
Batch
-----

Tianshou provides :class:`~tianshou.data.Batch` as the internal data structure to pass any kind of data to other methods, for example, a collector gives a :class:`~tianshou.data.Batch` to policy for learning. Let's take a look at this script:
::

Data Buffer
-----------
>>> import torch, numpy as np
>>> from tianshou.data import Batch
>>> data = Batch(a=4, b=[5, 5], c='2312312', d=('a', -2, -3))
>>> # the list will automatically be converted to numpy array
>>> data.b
array([5, 5])
>>> data.b = np.array([3, 4, 5])
>>> print(data)
Batch(
a: 4,
b: array([3, 4, 5]),
c: '2312312',
d: array(['a', '-2', '-3'], dtype=object),
)
>>> data = Batch(obs={'index': np.zeros((2, 3))}, act=torch.zeros((2, 2)))
>>> data[:, 1] += 6
>>> print(data[-1])
Batch(
obs: Batch(
index: array([0., 6., 0.]),
),
act: tensor([0., 6.]),
)

In short, you can define a :class:`~tianshou.data.Batch` with any key-value pair, and perform some common operations over it.

:ref:`batch_concept` is a dedicated tutorial for :class:`~tianshou.data.Batch`. We strongly recommend every user to read it so as to correctly understand and use :class:`~tianshou.data.Batch`.

Buffer
------

.. automodule:: tianshou.data.ReplayBuffer
:members:
Expand Down
1 change: 1 addition & 0 deletions test/base/test_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ def test_batch():
'd': Batch(e=np.array(3.0))}])
assert len(batch2) == 1
assert Batch().shape == []
assert Batch(a=1).shape == []
assert batch2.shape[0] == 1
with pytest.raises(IndexError):
batch2[-2]
Expand Down
Loading