Skip to content

Commit 077c982

Browse files
committed
merge
2 parents f7a6713 + 5ddc678 commit 077c982

File tree

17 files changed

+818
-88
lines changed

17 files changed

+818
-88
lines changed
File renamed without changes.

doc/advanced/graphstructures.txt

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
2+
.. _graphstructures:
3+
4+
================
5+
Graph Structures
6+
================
7+
8+
9+
.. index::
10+
single: Apply
11+
single: graph construct; Apply
12+
13+
.. _apply:
14+
15+
-----
16+
Apply
17+
-----
18+
19+
An *Apply node* is a type of internal node used to represent a
20+
:term:`computation graph <graph>` in Theano. Unlike
21+
:ref:`Result nodes <result>`, Apply nodes are usually not
22+
manipulated directly by the end user. They may be accessed via
23+
a Result's ``owner`` field.
24+
25+
An Apply node is typically an instance of the :api:`Apply
26+
<theano.gof.graph.Apply>` class. It represents the application
27+
of an :ref:`op` on one or more inputs, where each input is a
28+
:ref:`result`. By convention, each Op is responsible for
29+
knowing how to build an Apply node from a list of
30+
inputs. Therefore, an Apply node may be obtained from an Op
31+
and a list of inputs by calling ``Op.make_node(*inputs)``.
32+
33+
Comparing with the Python language, an :ref:`apply` node is
34+
theano's version of a function call whereas an :ref:`op` is
35+
theano's version of a function definition.
36+
37+
An Apply instance has three important fields:
38+
39+
**inputs**
40+
A list of :ref:`Results <result>` that represent the arguments of
41+
the function.
42+
43+
**outputs**
44+
A list of :ref:`Results <result>` that represent the return values
45+
of the function.
46+
47+
**op**
48+
An :ref:`op` that determines the function/transformation being
49+
applied here.
50+
51+
52+
.. index::
53+
single: Constant
54+
single: graph construct; Constant
55+
56+
.. _constant:
57+
58+
--------
59+
Constant
60+
--------
61+
62+
A constant is a :ref:`Result` with one extra field, *data* (only
63+
settable once). When used in a computation graph as the input of an
64+
:ref:`Op` :ref:`application <Apply>`, it is assumed that said input
65+
will *always* take the value contained in the constant's data
66+
field. Furthermore, it is assumed that the :ref:`Op` will not under
67+
any circumstances modify the input. This means that a constant is
68+
eligible to participate in numerous optimizations: constant inlining
69+
in C code, constant folding, etc.
70+
71+
A constant does not need to be specified in a :ref:`function`'s list
72+
of inputs.
73+
74+
75+
76+
.. index::
77+
single: Result
78+
single: graph construct; Result
79+
80+
.. _result:
81+
82+
------
83+
Result
84+
------
85+
86+
A :ref:`result` is the main data structure you work with when using
87+
Theano. The symbolic inputs that you operate on are Results and what
88+
you get from applying various operations to these inputs are also
89+
Results. For example, when I type
90+
91+
>>> x = theano.tensor.ivector()
92+
>>> y = -x
93+
94+
``x`` and ``y`` are both Results, i.e. instances of the :api:`Result
95+
<theano.gof.graph.Result>` class. The :ref:`type` of both ``x`` and
96+
``y`` is ``theano.tensor.ivector``.
97+
98+
Despite what the name might suggest, a Result is not necessarily
99+
produced by a computation. Indeed, in the example above, ``x`` is only
100+
an input. However, it is still called a Result for historical reasons
101+
(and because the data structure is identical).
102+
103+
Now, unlike ``x``, ``y`` is indeed produced by a computation (in this
104+
case, negation of x). ``y`` is the Result corresponding to the output
105+
of the computation, while ``x`` is the Result corresponding to its
106+
input. The computation itself is represented by another type of node,
107+
an :ref:`apply` node, and may be accessed through ``y.owner``.
108+
109+
More specifically, a Result is a basic structure in Theano that
110+
represents a datum at a certain point in computation. It is typically
111+
an instance of the class :api:`Result <theano.gof.graph.Result>` or
112+
one of its subclasses.
113+
114+
A Result ``r`` contains four important fields:
115+
116+
**type**
117+
a :ref:`type` defining the kind of value this Result can hold in
118+
computation.
119+
120+
**owner**
121+
this is either None or an :ref:`apply` node of which the Result is
122+
an output.
123+
124+
**index**
125+
the integer such that ``owner.outputs[index] is r`` (ignored if
126+
``owner`` is None)
127+
128+
**name**
129+
a string to use in pretty-printing and debugging.
130+
131+
Result has one special subclass: :ref:`constant <constant>`.
132+
133+
134+
135+
.. index::
136+
single: Op
137+
single: graph construct; Op
138+
139+
.. _op:
140+
141+
--
142+
Op
143+
--
144+
145+
WRITEME
146+
147+
148+
149+
.. index::
150+
single: Type
151+
single: graph construct; Type
152+
153+
.. _type:
154+
155+
----
156+
Type
157+
----
158+
159+
WRITEME
160+

doc/advanced/index.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
.. _advanced:
3+
4+
===============
5+
Advanced Topics
6+
===============
7+
8+
.. toctree::
9+
:maxdepth: 2
10+
11+
graphstructures
12+

doc/advtutorial/index.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
.. _advtutorial:
3+
4+
=================
5+
Advanced Tutorial
6+
=================
7+
8+
Before tackling this tutorial, it is highly recommended to read the :ref:`basictutorial`.
9+
10+
11+
12+
File renamed without changes.

doc/bcast.png

25.2 KB
Loading
Lines changed: 122 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -6,32 +6,132 @@ Glossary of terminology
66
.. glossary::
77

88
Apply
9-
Op-related graph node (expression instance)
10-
11-
An Apply instance (`Apply API <http://lgcm.iro.umontreal.ca/epydoc/theano.gof.graph.Apply-class.html>`_)
12-
represents the application of an :term:`Op` on input :term:`Results <Result>`, producing output :term:`Results <Result>`.
13-
Users typically do not instantiate Apply directly, instead they should use an Op's ``make_node`` or ``__call__`` function.
14-
15-
Comparing with the Python language, an :term:`Apply` instance is theano's version of a function call (or expression instance) whereas :term:`Op` is theano's version of a function definition.
16-
17-
An Apply instance serves as a simple structure with three important fields:
18-
``inputs``: a list of :term:`Result` instances that represent the arguments of the function.
19-
``outputs``: a list of :term:`Result` instances that represent the return values of the function.
20-
``op``: an Op instance that determines the function/transformation being applied here.
9+
WRITEME
10+
11+
broadcasting
12+
Broadcasting is a mechanism which allows tensors with
13+
different numbers of dimensions to be added or multiplied
14+
together by (virtually) replicating the smaller tensor along
15+
the dimensions that it is lacking.
16+
17+
In a nutshell, broadcasting is the mechanism by which a scalar
18+
may be added to a matrix, a vector to a matrix or a scalar to
19+
a vector.
20+
21+
.. figure:: bcast.png
22+
23+
Broadcasting a row matrix. T and F respectively stand for
24+
True and False and indicate along which dimensions we allow
25+
broadcasting.
2126

22-
Theano.function uses the Apply instances' ``inputs`` field together with each :term:`Result`'s ``owner`` field to determine which inputs are necessary to compute the function's outputs.
23-
Theano.function uses the Apply instances' ``op`` field to know how to compute the intermediate and final Results.
27+
Unlike numpy which does broadcasting dynamically, Theano needs
28+
to know, for any operation which supports broadcasting, which
29+
dimensions will need to be broadcasted. When applicable, this
30+
information is given in the :term:`Type` of a :term:`Result`.
2431

25-
See :ref:`intro_to_ops`.
32+
For more information, see the article about broadcasting_.
2633

27-
Broadcasting
28-
implicit tensor repmat
34+
See also:
35+
36+
* `SciPy documentation about numpy's broadcasting <http://www.scipy.org/EricsBroadcastingDoc>`_
37+
* `OnLamp article about numpy's broadcasting <http://www.onlamp.com/pub/a/python/2000/09/27/numerically.html>`_
38+
39+
constant
40+
WRITEME
41+
42+
elementwise
43+
An elementwise operation ``f`` on two matrices ``M`` and ``N``
44+
is one such that:
2945

46+
``f(M, N)[i, j] = f(M[i, j], N[i, j])``
47+
48+
In other words, each element of an input matrix is combined
49+
with the corresponding element of the other(s). There are no
50+
dependencies between elements whose ``[i, j]`` coordinates do
51+
not correspond, so an elementwise operation is like a scalar
52+
operation generalized along several dimensions.
53+
54+
There exist unary, binary, ternary, etc. elementwise
55+
operations and they can work on scalars, vectors, matrices,
56+
etc. as long as all the inputs have the same dimensions or can
57+
be :term:`broadcasted <broadcasting>` to the same dimensions.
58+
59+
Examples of elementwise operations in Theano: ``add, sub, mul,
60+
div, neg, inv, log, exp, sin, cos, tan`` and many
61+
others. These operations are all subclasses of :api:`Elemwise
62+
<theano.tensor.elemwise.Elemwise>`.
63+
64+
graph
3065
WRITEME
66+
67+
op
68+
WRITEME
69+
70+
Result
71+
A :ref:`result` is the main data structure you work with when
72+
using Theano. The symbolic inputs that you operate on are
73+
Results and what you get from applying various operations to
74+
these inputs are also Results. For example, when I type
75+
76+
>>> x = theano.tensor.ivector()
77+
>>> y = -x
78+
79+
``x`` and ``y`` are both Results, i.e. instances of the
80+
:api:`Result <theano.gof.graph.Result>` class. The
81+
:term:`Type` of both ``x`` and ``y`` is
82+
``theano.tensor.ivector``.
83+
84+
For more information, see: :ref:`result`.
85+
86+
type
87+
WRITEME
88+
89+
90+
.. _broadcasting: concepts/broadcasting.html
91+
92+
93+
94+
95+
96+
97+
98+
99+
100+
101+
102+
103+
104+
105+
106+
107+
108+
109+
110+
111+
112+
113+
114+
115+
116+
117+
118+
119+
120+
121+
122+
123+
124+
125+
126+
127+
128+
129+
..
130+
Apply
131+
TRANSFERRED
31132

32-
The following pages appear to describe broadcasting, but I haven't read over them:
33-
* http://www.onlamp.com/pub/a/python/2000/09/27/numerically.html
34-
* http://www.scipy.org/EricsBroadcastingDoc
133+
Broadcasting
134+
TRANSFERRED
35135

36136
Build
37137
see :term:`Compilation`
@@ -52,14 +152,7 @@ Glossary of terminology
52152
The :term:`mode` defines how optimizations and stabilizations will be introduced, and defines which linker will be used.
53153

54154
Constant
55-
See :term:`Value`
56-
57-
Constant (`Constant API
58-
<http://lgcm.iro.umontreal.ca/epydoc/theano.gof.graph.Constant-class.html
59-
doc>`_) also has an additional property: it is forbidden for an
60-
:term:`Op` to modify the state of the data it contains. This
61-
makes it eligible to participate in numerous optimizations:
62-
constant inlining in C code, constant folding, etc.
155+
TRANSFERRED
63156

64157
DType
65158
the numeric type for :term:`Tensor` elements
@@ -435,3 +528,4 @@ Glossary of terminology
435528
Theano computation). This can be practical because the compiler
436529
knows how to assign values to those nodes, thereby creating a
437530
sort of closure.
531+
..

0 commit comments

Comments
 (0)