提交 a69de34a authored 作者: Razvan Pascanu's avatar Razvan Pascanu

Tutorial updated

上级 3aa84cbd
...@@ -41,13 +41,13 @@ As a developer, you should clone this repository like this: ...@@ -41,13 +41,13 @@ As a developer, you should clone this repository like this:
.. code-block:: bash .. code-block:: bash
hg clone 'http://username:password@pylearn.org/hg/Theano' hg clone 'http://username:password@hg.assembla.com/theano Theano'
You can also clone the code anonymously: You can also clone the code anonymously:
.. code-block:: bash .. code-block:: bash
hg clone http://pylearn.org/hg/Theano hg clone http://hg.assembla.com/theano Theano
Setting up your environment Setting up your environment
=========================== ===========================
......
...@@ -15,11 +15,13 @@ ...@@ -15,11 +15,13 @@
TODO TODO
.. _libdoc_compile_function:
compile.function compile.function
================ ================
This page is about :api:`theano.function This page is about `theano.function`, the interface for compiling
<theano.compile.function_module.function>`, the interface for compiling
graphs into callable objects. graphs into callable objects.
The signature for this function is: The signature for this function is:
...@@ -402,6 +404,11 @@ For a finer level of control over which optimizations are applied, and whether ...@@ -402,6 +404,11 @@ For a finer level of control over which optimizations are applied, and whether
C or python implementations are used, read :api:`compile.mode.Mode`. C or python implementations are used, read :api:`compile.mode.Mode`.
.. _compile_debugMode:
DebugMode ??
.. toctree:: .. toctree::
function function
......
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://web.resource.org/cc/"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="144.18471"
height="188.09711"
id="svg2"
sodipodi:version="0.32"
inkscape:version="0.45.1"
sodipodi:docbase="/u/breuleuo/hg/theano/doc"
sodipodi:docname="bcast.svg"
inkscape:output_extension="org.inkscape.output.svg.inkscape"
version="1.0"
inkscape:export-filename="/u/breuleuo/hg/theano/doc/bcast.png"
inkscape:export-xdpi="249.67973"
inkscape:export-ydpi="249.67973">
<defs
id="defs4">
<marker
inkscape:stockid="Arrow2Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow2Lend"
style="overflow:visible">
<path
id="path3247"
style="font-size:12px;fill-rule:evenodd;stroke-width:0.625;stroke-linejoin:round"
d="M 8.7185878,4.0337352 L -2.2072895,0.016013256 L 8.7185884,-4.0017078 C 6.97309,-1.6296469 6.9831476,1.6157441 8.7185878,4.0337352 z "
transform="matrix(-1.1,0,0,-1.1,-1.1,0)" />
</marker>
<marker
inkscape:stockid="Arrow1Lend"
orient="auto"
refY="0"
refX="0"
id="Arrow1Lend"
style="overflow:visible">
<path
id="path3229"
d="M 0,0 L 5,-5 L -12.5,0 L 5,5 L 0,0 z "
style="fill-rule:evenodd;stroke:#000000;stroke-width:1pt;marker-start:none"
transform="matrix(-0.8,0,0,-0.8,-10,0)" />
</marker>
</defs>
<sodipodi:namedview
id="base"
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1.0"
gridtolerance="10000"
guidetolerance="10"
objecttolerance="10"
inkscape:pageopacity="0.0"
inkscape:pageshadow="2"
inkscape:zoom="2.8"
inkscape:cx="55.423257"
inkscape:cy="90.829331"
inkscape:document-units="px"
inkscape:current-layer="layer1"
inkscape:window-width="1272"
inkscape:window-height="937"
inkscape:window-x="0"
inkscape:window-y="0" />
<metadata
id="metadata7">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<g
inkscape:label="Layer 1"
inkscape:groupmode="layer"
id="layer1"
transform="translate(-106.70114,-419.13306)">
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
x="116.79369"
y="428.03931"
id="text2160"><tspan
sodipodi:role="line"
id="tspan2162"
x="116.79369"
y="428.03931"
style="font-family:Monospace">1 2</tspan><tspan
sodipodi:role="line"
x="116.79369"
y="443.03931"
id="tspan2164"
style="font-family:Monospace">3 4</tspan><tspan
sodipodi:role="line"
x="116.79369"
y="458.03931"
id="tspan2166"
style="font-family:Monospace">5 6</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
x="180.75143"
y="506.09698"
id="text2184"><tspan
sodipodi:role="line"
id="tspan2186"
x="180.75143"
y="506.09698"
style="font-family:Monospace">1 2</tspan><tspan
sodipodi:role="line"
x="180.75143"
y="521.09698"
id="tspan2188"
style="fill:#0000ff;font-family:Monospace">1 2</tspan><tspan
sodipodi:role="line"
x="180.75143"
y="536.09698"
id="tspan2190"
style="fill:#0000ff;font-family:Monospace">1 2</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
x="150.42657"
y="577.06024"
id="text2192"><tspan
sodipodi:role="line"
id="tspan2194"
x="150.42657"
y="577.06024"
style="font-family:Monospace">2 4</tspan><tspan
sodipodi:role="line"
x="150.42657"
y="592.06024"
id="tspan2196"
style="font-family:Monospace">4 6</tspan><tspan
sodipodi:role="line"
x="150.42657"
y="607.06024"
id="tspan2198"
style="font-family:Monospace">6 8</tspan></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
x="180.81337"
y="428.06268"
id="text2200"><tspan
sodipodi:role="line"
x="180.81337"
y="428.06268"
id="tspan2206"
style="font-family:Monospace">1 2</tspan><tspan
sodipodi:role="line"
x="180.81337"
y="443.06268"
style="font-family:Monospace"
id="tspan2208" /><tspan
sodipodi:role="line"
x="180.81337"
y="458.06268"
style="font-family:Monospace"
id="tspan2210" /></text>
<text
xml:space="preserve"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
x="156.64333"
y="442.89511"
id="text2216"><tspan
sodipodi:role="line"
x="156.64333"
y="442.89511"
id="tspan2218"
style="font-family:Monospace">+</tspan><tspan
sodipodi:role="line"
x="156.64333"
y="457.89511"
style="font-family:Monospace"
id="tspan2220" /><tspan
sodipodi:role="line"
x="156.64333"
y="472.89511"
style="font-family:Monospace"
id="tspan2222" /></text>
<text
xml:space="preserve"
style="font-size:6px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
x="106.13571"
y="465.37097"
id="text2224"><tspan
sodipodi:role="line"
x="106.13571"
y="465.37097"
id="tspan2226"
style="font-size:6px;font-family:Monospace">shape: (3, 2)</tspan><tspan
sodipodi:role="line"
x="106.13571"
y="472.87097"
style="font-size:6px;font-family:Monospace"
id="tspan2240">bcast: (F, F)</tspan><tspan
sodipodi:role="line"
x="106.13571"
y="480.37097"
style="font-size:6px;font-family:Monospace"
id="tspan2228" /><tspan
sodipodi:role="line"
x="106.13571"
y="487.87097"
style="font-size:6px;font-family:Monospace"
id="tspan2230" /></text>
<text
xml:space="preserve"
style="font-size:6px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
x="168.05223"
y="465.34521"
id="text2232"><tspan
sodipodi:role="line"
x="168.05223"
y="465.34521"
id="tspan2234"
style="font-size:6px;font-family:Monospace">shape: (1, 2)</tspan><tspan
sodipodi:role="line"
x="168.05223"
y="472.84521"
style="font-size:6px;font-family:Monospace"
id="tspan2242">bcast: (<tspan
style="fill:#0000ff"
id="tspan2244">T</tspan>, F)</tspan><tspan
sodipodi:role="line"
x="168.05223"
y="480.34521"
style="font-size:6px;font-family:Monospace"
id="tspan2236" /><tspan
sodipodi:role="line"
x="168.05223"
y="487.84521"
style="font-size:6px;font-family:Monospace"
id="tspan2238" /></text>
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;marker-end:url(#Arrow2Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 161.11933,479.10061 L 161.37187,491.98006"
id="path2248" />
<text
id="text3469"
y="506.03931"
x="116.79369"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
xml:space="preserve"><tspan
style="font-family:Monospace"
y="506.03931"
x="116.79369"
id="tspan3471"
sodipodi:role="line">1 2</tspan><tspan
style="font-family:Monospace"
id="tspan3473"
y="521.03931"
x="116.79369"
sodipodi:role="line">3 4</tspan><tspan
style="font-family:Monospace"
id="tspan3475"
y="536.03931"
x="116.79369"
sodipodi:role="line">5 6</tspan></text>
<text
id="text3485"
y="520.89514"
x="156.64333"
style="font-size:12px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
xml:space="preserve"><tspan
style="font-family:Monospace"
id="tspan3487"
y="520.89514"
x="156.64333"
sodipodi:role="line">+</tspan><tspan
id="tspan3489"
style="font-family:Monospace"
y="535.89514"
x="156.64333"
sodipodi:role="line" /><tspan
id="tspan3491"
style="font-family:Monospace"
y="550.89514"
x="156.64333"
sodipodi:role="line" /></text>
<text
id="text3493"
y="543.37097"
x="106.13571"
style="font-size:6px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
xml:space="preserve"><tspan
style="font-size:6px;font-family:Monospace"
id="tspan3495"
y="543.37097"
x="106.13571"
sodipodi:role="line">shape: (3, 2)</tspan><tspan
id="tspan3497"
style="font-size:6px;font-family:Monospace"
y="550.87097"
x="106.13571"
sodipodi:role="line">bcast: (F, F)</tspan><tspan
id="tspan3499"
style="font-size:6px;font-family:Monospace"
y="558.37097"
x="106.13571"
sodipodi:role="line" /><tspan
id="tspan3501"
style="font-size:6px;font-family:Monospace"
y="565.87097"
x="106.13571"
sodipodi:role="line" /></text>
<text
id="text3503"
y="543.34521"
x="168.05223"
style="font-size:6px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
xml:space="preserve"><tspan
style="font-size:6px;font-family:Monospace"
id="tspan3505"
y="543.34521"
x="168.05223"
sodipodi:role="line">shape: (<tspan
style="fill:#0000ff"
id="tspan3515">3</tspan>, 2)</tspan><tspan
id="tspan3507"
style="font-size:6px;font-family:Monospace"
y="550.84521"
x="168.05223"
sodipodi:role="line">bcast: (<tspan
id="tspan3509"
style="fill:#0000ff">T</tspan>, F)</tspan><tspan
id="tspan3511"
style="font-size:6px;font-family:Monospace"
y="558.34521"
x="168.05223"
sodipodi:role="line" /><tspan
id="tspan3513"
style="font-size:6px;font-family:Monospace"
y="565.84521"
x="168.05223"
sodipodi:role="line" /></text>
<path
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.81574231;stroke-linecap:butt;stroke-linejoin:miter;marker-end:url(#Arrow2Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1"
d="M 209.4424,497.10811 L 209.6746,534.39419"
id="path3517" />
<text
id="text3519"
y="517.36304"
x="211.73936"
style="font-size:6px;font-style:normal;font-weight:normal;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Aharoni CLM"
xml:space="preserve"><tspan
id="tspan3523"
style="font-size:6px;font-family:Monospace"
y="517.36304"
x="211.73936"
sodipodi:role="line">broadcasted</tspan><tspan
id="tspan3525"
style="font-size:6px;font-family:Monospace"
y="524.86304"
x="211.73936"
sodipodi:role="line" /><tspan
id="tspan3527"
style="font-size:6px;font-family:Monospace"
y="532.36304"
x="211.73936"
sodipodi:role="line" /></text>
<path
id="path3533"
d="M 161.11933,553.10061 L 161.37187,565.98006"
style="fill:none;fill-rule:evenodd;stroke:#000000;stroke-width:0.5;stroke-linecap:butt;stroke-linejoin:miter;marker-end:url(#Arrow2Lend);stroke-miterlimit:4;stroke-dasharray:none;stroke-opacity:1" />
</g>
</svg>
...@@ -12,6 +12,8 @@ ...@@ -12,6 +12,8 @@
TODO: What does (or compatible) mean? Talk about casting rules, refer . TODO: What does (or compatible) mean? Talk about casting rules, refer .
.. _libdoc_tensor_type:
TensorType TensorType
========== ==========
...@@ -20,6 +22,8 @@ TensorType ...@@ -20,6 +22,8 @@ TensorType
.. method:: quux() .. method:: quux()
.. _libdoc_tensor_creation:
Creation Creation
======== ========
...@@ -80,6 +84,8 @@ Basic indexing. ...@@ -80,6 +84,8 @@ Basic indexing.
Advanced indexing. Advanced indexing.
.. _libdoc_tensor_elementwise:
Elementwise Elementwise
=========== ===========
...@@ -92,9 +98,48 @@ Logic Functions ...@@ -92,9 +98,48 @@ Logic Functions
Mathematical Mathematical
------------ ------------
.. _libdoc_tensor_broadcastable:
Broadcasting in Theano vs. Numpy Broadcasting in Theano vs. Numpy
-------------------------------- --------------------------------
Broadcasting is a mechanism which allows tensors with
different numbers of dimensions to be added or multiplied
together by (virtually) replicating the smaller tensor along
the dimensions that it is lacking.
In a nutshell, broadcasting is the mechanism by which a scalar
may be added to a matrix, a vector to a matrix or a scalar to
a vector.
.. figure:: bcast.png
Broadcasting a row matrix. T and F respectively stand for
True and False and indicate along which dimensions we allow
broadcasting.
If the second argument were a vector, its shape would be
``(2,)`` and its broadcastable pattern ``(F,)``. They would
be automatically expanded to the **left** to match the
dimensions of the matrix (adding ``1`` to the shape and ``T``
to the pattern), resulting in ``(1, 2)`` and ``(T, F)``.
It would then behave just like the example above.
Unlike numpy which does broadcasting dynamically, Theano needs
to know, for any operation which supports broadcasting, which
dimensions will need to be broadcasted. When applicable, this
information is given in the :ref:`type` of a *Variable*.
See also:
* :ref:`How broadcasting is used in Theano's tensor types <tensortypes>`
* `SciPy documentation about numpy's broadcasting <http://www.scipy.org/EricsBroadcastingDoc>`_
* `OnLamp article about numpy's broadcasting <http://www.onlamp.com/pub/a/python/2000/09/27/numerically.html>`_
Random Sampling Random Sampling
=============== ===============
......
...@@ -26,17 +26,32 @@ array(28.4) ...@@ -26,17 +26,32 @@ array(28.4)
Let's break this down into several steps. The first step is to define Let's break this down into several steps. The first step is to define
two symbols representing the quantities that you want two symbols (*Variables*) representing the quantities that you want
to add. Note that from now on, we will use the term :term:`Variable` to add. Note that from now on, we will use the term
to mean "symbol" (in other words, ``x``, ``y``, ``z`` are all Variable *Variable* to mean "symbol" (in other words,
objects). The output of the function ``f`` is a ``numpy.ndarray`` ``x``, ``y``, ``z`` are all *Variable* objects). The output of the function
with zero dimensions. ``f`` is a ``numpy.ndarray`` with zero dimensions.
If you are following along and typing into an interpreter, you may have If you are following along and typing into an interpreter, you may have
noticed that there was a slight delay in executing the ``function`` noticed that there was a slight delay in executing the ``function``
instruction. Behind the scenes, ``f`` was being compiled into C code. instruction. Behind the scenes, ``f`` was being compiled into C code.
.. note:
A *Variable* is the main data structure you work with when
using Theano. The symbolic inputs that you operate on are
*Variables* and what you get from applying various operations to
these inputs are also *Variables*. For example, when I type
>>> x = theano.tensor.ivector()
>>> y = -x
``x`` and ``y`` are both Variables, i.e. instances of the
``theano.gof.graph.Variable`` class. The
type of both ``x`` and ``y`` is ``theano.tensor.ivector``.
------------------------------------------- -------------------------------------------
**Step 1** **Step 1**
...@@ -46,11 +61,11 @@ instruction. Behind the scenes, ``f`` was being compiled into C code. ...@@ -46,11 +61,11 @@ instruction. Behind the scenes, ``f`` was being compiled into C code.
In Theano, all symbols must be typed. In particular, ``T.dscalar`` In Theano, all symbols must be typed. In particular, ``T.dscalar``
is the type we assign to "0-dimensional arrays (`scalar`) of doubles is the type we assign to "0-dimensional arrays (`scalar`) of doubles
(`d`)". It is a Theano :term:`Type`. (`d`)". It is a Theano :ref:`type`.
``dscalar`` is not a class. Therefore, neither ``x`` nor ``y`` ``dscalar`` is not a class. Therefore, neither ``x`` nor ``y``
are actually instances of ``dscalar``. They are instances of are actually instances of ``dscalar``. They are instances of
:api:`TensorVariable <theano.tensor.basic.TensorVariable>`. ``x`` and ``y`` :ref:`TensorVariable <libdoc_tensor_type>`. ``x`` and ``y``
are, however, assigned the theano Type ``dscalar`` in their ``type`` are, however, assigned the theano Type ``dscalar`` in their ``type``
field, as you can see here: field, as you can see here:
...@@ -66,7 +81,7 @@ True ...@@ -66,7 +81,7 @@ True
You can learn more about the structures in Theano in :ref:`graphstructures`. You can learn more about the structures in Theano in :ref:`graphstructures`.
By calling ``T.dscalar`` with a string argument, you create a By calling ``T.dscalar`` with a string argument, you create a
:term:`Variable` representing a floating-point scalar quantity with the *Variable* representing a floating-point scalar quantity with the
given name. If you provide no argument, the symbol will be unnamed. Names given name. If you provide no argument, the symbol will be unnamed. Names
are not required, but they can help debugging. are not required, but they can help debugging.
...@@ -78,8 +93,8 @@ The second step is to combine ``x`` and ``y`` into their sum ``z``: ...@@ -78,8 +93,8 @@ The second step is to combine ``x`` and ``y`` into their sum ``z``:
>>> z = x + y >>> z = x + y
``z`` is yet another :term:`Variable` which represents the addition of ``z`` is yet another *Variable* which represents the addition of
``x`` and ``y``. You can use the :api:`pp <theano.printing.pp>` ``x`` and ``y``. You can use the :ref:`pp <libdoc_printing>`
function to pretty-print out the computation associated to ``z``. function to pretty-print out the computation associated to ``z``.
>>> print pp(z) >>> print pp(z)
...@@ -94,7 +109,7 @@ and giving ``z`` as output: ...@@ -94,7 +109,7 @@ and giving ``z`` as output:
>>> f = function([x, y], z) >>> f = function([x, y], z)
The first argument to ``function`` is a list of :term:`Variables <Variable>` The first argument to :ref:`function <libdoc_compile_function>` is a list of Variables
that will be provided as inputs to the function. The second argument that will be provided as inputs to the function. The second argument
is a single Variable *or* a list of Variables. For either case, the second is a single Variable *or* a list of Variables. For either case, the second
argument is what we want to see as output when we apply the function. argument is what we want to see as output when we apply the function.
...@@ -131,7 +146,7 @@ array([[ 11., 22.], ...@@ -131,7 +146,7 @@ array([[ 11., 22.],
It is possible to add scalars to matrices, vectors to matrices, It is possible to add scalars to matrices, vectors to matrices,
scalars to vectors, etc. The behavior of these operations is defined scalars to vectors, etc. The behavior of these operations is defined
by :term:`broadcasting`. by :ref:`broadcasting <libdoc_tensor_broadcastable>`.
The following types are available: The following types are available:
......
...@@ -110,9 +110,7 @@ put logic inside of the print_eval function that would, for example, only ...@@ -110,9 +110,7 @@ put logic inside of the print_eval function that would, for example, only
print something out if a certain kind of Op was used, at a certain program print something out if a certain kind of Op was used, at a certain program
position, or if a particular value shows up in one of the inputs or outputs. position, or if a particular value shows up in one of the inputs or outputs.
This can be a really powerful debugging tool. Read about more things you can .. TODO: documentation for link.WrapLinkerMany
do with :api:`link.WrapLinkerMany`.
Note well the call to ``fn`` inside the call to ``print_eval``; without it, This can be a really powerful debugging tool. Note the call to ``fn`` inside the call to ``print_eval``; without it, the graph wouldn't get computed at all!
the graph wouldn't get computed at all!
...@@ -7,7 +7,7 @@ Using DebugMode ...@@ -7,7 +7,7 @@ Using DebugMode
The DebugMode evaluation mode (available via ``mode='DEBUG_MODE'``, The DebugMode evaluation mode (available via ``mode='DEBUG_MODE'``,
:api:`DebugMode`) includes a number of self-checks and assertions that see :ref:`this <function_mode>`) includes a number of self-checks and assertions that
can help to diagnose several kinds of programmer errors that can lead can help to diagnose several kinds of programmer errors that can lead
to incorrect output. to incorrect output.
...@@ -41,7 +41,7 @@ In the example above, there is no way to guarantee that a future call to say, ...@@ -41,7 +41,7 @@ In the example above, there is no way to guarantee that a future call to say,
If you instantiate DebugMode using the constructor ``compile.DebugMode`` If you instantiate DebugMode using the constructor ``compile.DebugMode``
rather than the keyword ``DEBUG_MODE`` you can configure its behaviour via rather than the keyword ``DEBUG_MODE`` you can configure its behaviour via
constructor arguments. See :api:`DebugMode` for details. constructor arguments. See :ref:`DebugMode <compile_debugMode>` for details.
The keyword version of DebugMode (which you get by using ``mode='DEBUG_MODE``) The keyword version of DebugMode (which you get by using ``mode='DEBUG_MODE``)
is quite strict, and can raise several different Exception types. is quite strict, and can raise several different Exception types.
...@@ -56,7 +56,6 @@ This error is typically not raised directly. ...@@ -56,7 +56,6 @@ This error is typically not raised directly.
However, you can use ``except DebugModeError: ...`` to catch any of the more However, you can use ``except DebugModeError: ...`` to catch any of the more
specific types of Exception. specific types of Exception.
For detailed documentation see :api:`DebugModeError`.
BadCLinkerOutput BadCLinkerOutput
...@@ -66,7 +65,6 @@ This exception means that python (``perform``) and c (``c_code``) for an Op ...@@ -66,7 +65,6 @@ This exception means that python (``perform``) and c (``c_code``) for an Op
didn't compute the same thing like they were supposed to. didn't compute the same thing like they were supposed to.
The problem might be a bug in either ``perform`` or ``c_code`` (or both). The problem might be a bug in either ``perform`` or ``c_code`` (or both).
For detailed documentation see :api:`BadCLinkerOutput`.
BadOptimization BadOptimization
...@@ -82,7 +80,6 @@ exception object will indicate which optimization was at fault. ...@@ -82,7 +80,6 @@ exception object will indicate which optimization was at fault.
The exception object also contains information such as a snapshot of the The exception object also contains information such as a snapshot of the
before/after graph where the optimization introduced the error. before/after graph where the optimization introduced the error.
For detailed documentation see :api:`BadOptimization`.
BadDestroyMap BadDestroyMap
...@@ -93,7 +90,6 @@ supposed to. If either the ``perform`` or ``c_code`` implementation of an Op ...@@ -93,7 +90,6 @@ supposed to. If either the ``perform`` or ``c_code`` implementation of an Op
might modify any input, it has to advertise that fact via the ``destroy_map`` might modify any input, it has to advertise that fact via the ``destroy_map``
attribute. attribute.
For detailed documentation on the Exception, see :api:`BadDestroyMap`.
For detailed documentation on the ``destroy_map`` attribute, see :ref:`inplace`. For detailed documentation on the ``destroy_map`` attribute, see :ref:`inplace`.
...@@ -105,7 +101,6 @@ This happens when an Op's perform() or c_code() creates an alias or alias-like ...@@ -105,7 +101,6 @@ This happens when an Op's perform() or c_code() creates an alias or alias-like
dependency between an input and an output... and it didn't warn the dependency between an input and an output... and it didn't warn the
optimization system via the ``view_map`` attribute. optimization system via the ``view_map`` attribute.
For detailed documentation on the Exception, see :api:`BadViewMap`.
For detailed documentation on the ``view_map`` attribute, see :ref:`views`. For detailed documentation on the ``view_map`` attribute, see :ref:`views`.
...@@ -119,7 +114,6 @@ steps are ordered by ``id(object)`` somehow, such as via the default object ...@@ -119,7 +114,6 @@ steps are ordered by ``id(object)`` somehow, such as via the default object
hash function. A Stochastic optimization invalidates the pattern of work hash function. A Stochastic optimization invalidates the pattern of work
whereby we debug in DEBUG_MODE and then run the full-size jobs in FAST_RUN. whereby we debug in DEBUG_MODE and then run the full-size jobs in FAST_RUN.
For detailed documentation see :api:`StochasticOrder`.
...@@ -136,6 +130,5 @@ introduced into the computations. It indicates which Op created the first ...@@ -136,6 +130,5 @@ introduced into the computations. It indicates which Op created the first
NaN. These floating-point values can be allowed by passing the NaN. These floating-point values can be allowed by passing the
``check_isfinite=False`` argument to DebugMode. ``check_isfinite=False`` argument to DebugMode.
For detailed documentation see :api:`InvalidValueError`.
...@@ -22,7 +22,7 @@ the logistic curve, which is given by: ...@@ -22,7 +22,7 @@ the logistic curve, which is given by:
A plot of the logistic function, with x on the x-axis and s(x) on the A plot of the logistic function, with x on the x-axis and s(x) on the
y-axis. y-axis.
You want to compute the function :term:`elementwise` on matrices of You want to compute the function :ref:`elementwise <libdoc_tensor_elementwise>` on matrices of
doubles, which means that you want to apply this function to each doubles, which means that you want to apply this function to each
individual element of the matrix. individual element of the matrix.
...@@ -58,7 +58,7 @@ Computing more than one thing at the same time ...@@ -58,7 +58,7 @@ Computing more than one thing at the same time
============================================== ==============================================
Theano supports functions with multiple outputs. For example, we can Theano supports functions with multiple outputs. For example, we can
compute the :term:`elementwise` difference, absolute difference, and compute the :ref:`elementwise <libdoc_tensor_elementwise>` difference, absolute difference, and
squared difference between two matrices ``a`` and ``b`` at the same time: squared difference between two matrices ``a`` and ``b`` at the same time:
>>> a, b = T.dmatrices('a', 'b') >>> a, b = T.dmatrices('a', 'b')
...@@ -134,19 +134,17 @@ array([[ 0.25 , 0.19661193], ...@@ -134,19 +134,17 @@ array([[ 0.25 , 0.19661193],
The resulting function computes the gradient of its first argument The resulting function computes the gradient of its first argument
with respect to the second. In this way, Theano can be used for with respect to the second. In this way, Theano can be used for
`automatic differentiation`_. `automatic differentiation <http://en.wikipedia.org/wiki/Automatic_differentiation>`_.
.. note:: .. note::
The second argument of ``T.grad`` can be a list, case in which it The second argument of ``T.grad`` can be a list, in which case the
will output is also a list. The order in both list is important, element
*i* of the output list is the gradient of the first argument of
The variable of ``T.grad`` has the same dimensions as the ``T.grad`` with respect to the *i*-th element of the list given as second argument.
second argument. This is exactly like the first derivative if the The first arguement of ``T.grad`` has to be a scalar (a tensor
first argument is a scalar or a tensor of size 1 but not if it is of size 1). For more information on the semantics of the arguments of
larger. For more information on the semantics when the first ``T.grad`` and details about the implementation, see :ref:`this <libdoc_gradient>`.
argument has a larger size and details about the implementation,
see :api:`tensor.grad`.
Setting a default value for an argument Setting a default value for an argument
...@@ -294,8 +292,9 @@ the substitutions have to work in any order. ...@@ -294,8 +292,9 @@ the substitutions have to work in any order.
Mode Mode
==== ====
The ``mode`` parameter to :api:`theano.function` controls how the The ``mode`` parameter to :ref:`theano.function <libdoc_compile_function>`
inputs-to-outputs graph is transformed into a callable object. controls how the inputs-to-outputs graph is transformed into a callable
object.
Theano defines the following modes by name: Theano defines the following modes by name:
...@@ -307,15 +306,11 @@ Theano defines the following modes by name: ...@@ -307,15 +306,11 @@ Theano defines the following modes by name:
The default mode is typically ``FAST_RUN``, but it can be controlled via The default mode is typically ``FAST_RUN``, but it can be controlled via
the environment variable ``THEANO_DEFAULT_MODE``, which can in turn be the environment variable ``THEANO_DEFAULT_MODE``, which can in turn be
overridden by setting :api:`theano.compile.mode.default_mode` directly, overridden by setting `theano.compile.mode.default_mode` directly,
which can in turn be overridden by passing the keyword argument to which can in turn be overridden by passing the keyword argument to
:api:`theano.function`. :ref:`theano.function <libdoc_compile_function>`.
For a finer level of control over which optimizations are applied, and
whether C or python implementations are used, read
:api:`compile.mode.Mode`.
.. _automatic differentiation: http://en.wikipedia.org/wiki/Automatic_differentiation
...@@ -48,7 +48,7 @@ and 2 columns. ...@@ -48,7 +48,7 @@ and 2 columns.
Broadcasting Broadcasting
============ ============
Numpy does :term:`broadcasting` of numpy arrays of different shapes during Numpy does *broadcasting* of arrays of different shapes during
arithmetic operations. What this means in general is that the smaller arithmetic operations. What this means in general is that the smaller
array is *broadcasted* across the larger array so that they have array is *broadcasted* across the larger array so that they have
compatible shapes. The example below shows an instance of compatible shapes. The example below shows an instance of
...@@ -60,6 +60,6 @@ compatible shapes. The example below shows an instance of ...@@ -60,6 +60,6 @@ compatible shapes. The example below shows an instance of
array([2., 4., 6.]) array([2., 4., 6.])
The smaller array ``b`` in this case is *broadcasted* to the same size The smaller array ``b`` in this case is *broadcasted* to the same size
as a during the multiplication. This trick is often useful in as ``a`` during the multiplication. This trick is often useful in
simplifying how expression are written. More details about *broadcasting* simplifying how expression are written. More details about *broadcasting*
can be found at `numpy user guide <http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`__ . can be found at `numpy user guide <http://docs.scipy.org/doc/numpy/user/basics.broadcasting.html>`__.
...@@ -28,7 +28,7 @@ Predefined types ...@@ -28,7 +28,7 @@ Predefined types
---------------- ----------------
Predefined types are Predefined types are
located in the :api:`theano.tensor` package. The name of the types follow located in the :ref:`theano.tensor <libdoc_tensor>` package. The name of the types follow
a recipe: a recipe:
``<dtype><dimensionality>`` ``<dtype><dimensionality>``
...@@ -48,26 +48,26 @@ d double floating point 64 ...@@ -48,26 +48,26 @@ d double floating point 64
Dimensionality is one of: Dimensionality is one of:
====== ====== ========================================== ============================================= ====== ====== ======================================================== ===========================================================
code shape Rows :term:`broadcastable <broadcasting>`? Columns :term:`broadcastable <broadcasting>`? code shape Rows :ref:`broadcastable <libdoc_tensor_broadcastable>`? Columns :ref:`broadcastable <libdoc_tensor_broadcastable>`?
====== ====== ========================================== ============================================= ====== ====== ======================================================== ===========================================================
scalar [] Yes Yes scalar [] Yes Yes
vector [n] Yes N/A (vectors are used like row vectors) vector [n] Yes N/A (vectors are used like row vectors)
row [1, n] Yes No row [1, n] Yes No
col [m, 1] No Yes col [m, 1] No Yes
matrix [m, n] No No matrix [m, n] No No
====== ====== ========================================== ============================================= ====== ====== ======================================================== ============================================================
So, if you want a row of 32-bit floats, it is available So, if you want a row of 32-bit floats, it is available
as :api:`theano.tensor.frow <theano.tensor.basic.frow>`. as :ref:`theano.tensor.frow <libdoc_tensor_type>`.
If you want a matrix of unsigned 32-bit integers it is available as If you want a matrix of unsigned 32-bit integers it is available as
:api:`theano.tensor.imatrix <theano.tensor.basic.imatrix>`. :ref:`theano.tensor.imatrix <libdoc_tensor_type>`.
Each of the types described above can be constructed by two methods: Each of the types described above can be constructed by two methods:
a singular version (e.g., :api:`dmatrix <theano.tensor.basic.dmatrix>`) a singular version (e.g., :ref:`dmatrix <libdoc_tensor_creation>`)
and a plural version (:api:`dmatrices <theano.tensor.dmatrices>`). and a plural version (:ref:`dmatrices <libdoc_tensor_creation>`).
When called, the singular version takes a single When called, the singular version takes a single
argument which is the name of the :term:`Variable` we want to make and it argument which is the name of the *Variable* we want to make and it
makes a single Variable of that type. The plural version can either take makes a single Variable of that type. The plural version can either take
an integer or several strings. If an integer is provided, the method an integer or several strings. If an integer is provided, the method
will return that many Variables and if strings are provided, it will will return that many Variables and if strings are provided, it will
...@@ -91,7 +91,7 @@ Custom tensor types ...@@ -91,7 +91,7 @@ Custom tensor types
If you wish to use a type of tensor which is not already available here If you wish to use a type of tensor which is not already available here
(for example, a 3D tensor) you can build an appropriate type using (for example, a 3D tensor) you can build an appropriate type using
:api:`theano.tensor.TensorType <theano.tensor.basic.TensorType>`. :ref:`theano.tensor.TensorType <libdoc_tensor_type>`.
The first argument you pass is the `dtype` and the second is the The first argument you pass is the `dtype` and the second is the
`broadcastable pattern`. `broadcastable pattern`.
...@@ -116,10 +116,10 @@ complex128 complex 128 (two float64) ...@@ -116,10 +116,10 @@ complex128 complex 128 (two float64)
.. note:: .. note::
Even though :api:`theano.tensor` does not define any type Even though :ref:`theano.tensor <libdoc_tensor>` does not define any type
using ``complex`` dtypes (``complex64`` or ``complex128``), using ``complex`` dtypes (``complex64`` or ``complex128``),
you can define them explicitly with you can define them explicitly with
:api:`TensorType <theano.tensor.basic.TensorType>` (see example :ref:`TensorType <libdoc_tensor_type>` (see example
below). However, few operations are fully supported for complex below). However, few operations are fully supported for complex
types: as of version 0.1, only elementary operations (``+-*/``) types: as of version 0.1, only elementary operations (``+-*/``)
have C implementations. Additionally, complex types have received have C implementations. Additionally, complex types have received
...@@ -128,8 +128,7 @@ complex128 complex 128 (two float64) ...@@ -128,8 +128,7 @@ complex128 complex 128 (two float64)
The broadcastable pattern indicates both the number of dimensions and The broadcastable pattern indicates both the number of dimensions and
whether a particular dimension must have length 1. whether a particular dimension must have length 1.
Here is a table mapping the :term:`broadcastable Here is a table mapping the :ref:`broadcastable <libdoc_tensor_broadcastable>` pattern to what kind of tensor it encodes:
<broadcasting>` pattern to what kind of tensor it encodes:
===================== ================================= ===================== =================================
pattern interpretation pattern interpretation
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论