提交 0c6696f8 authored 作者: Pascal Lamblin's avatar Pascal Lamblin

Small documentation corrections.

上级 9ca3b2ba
...@@ -85,7 +85,7 @@ The second step is to combine ``x`` and ``y`` into their sum ``z``: ...@@ -85,7 +85,7 @@ The second step is to combine ``x`` and ``y`` into their sum ``z``:
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)
x + y (x + y)
------------------------------------------- -------------------------------------------
......
...@@ -97,17 +97,17 @@ Here is code to compute this gradient: ...@@ -97,17 +97,17 @@ Here is code to compute this gradient:
>>> y = x**2 >>> y = x**2
>>> gy = T.grad(y, x) >>> gy = T.grad(y, x)
>>> pp(gy) >>> pp(gy)
'fill(x ** 2, 1.0) * 2 * x ** (2 - 1)' '((fill((x ** 2), 1.0) * 2) * (x ** (2 - 1)))'
>>> f = function([x], gy) >>> f = function([x], gy)
>>> f(4) >>> f(4)
array(8.0) array(8.0)
>>> f(94.2) >>> f(94.2)
array(188.40000000000001) array(188.40000000000001)
In the example above, we can see from ``pp(gw)`` that we are computing In the example above, we can see from ``pp(gy)`` that we are computing
the correct symbolic gradient. the correct symbolic gradient.
``fill(x ** 2, 1.0)`` means to make a matrix of the same shape as ``x ** ``fill((x ** 2), 1.0)`` means to make a matrix of the same shape as
2`` and fill it with 1.0. ``x ** 2`` and fill it with 1.0.
.. note:: .. note::
The optimizer will simplify the symbolic gradient expression. The optimizer will simplify the symbolic gradient expression.
...@@ -252,7 +252,7 @@ array(5.9000000000000004) ...@@ -252,7 +252,7 @@ array(5.9000000000000004)
Mode Mode
==== ====
The ``mode`` parameter to ``theano.function`` controls how the The ``mode`` parameter to :api:`theano.function` controls how the
inputs-to-outputs graph is transformed into a callable object. inputs-to-outputs graph is transformed into a callable object.
Theano defines the following modes by name: Theano defines the following modes by name:
...@@ -263,11 +263,11 @@ Theano defines the following modes by name: ...@@ -263,11 +263,11 @@ Theano defines the following modes by name:
implementations. This mode can take much longer than the other modes, implementations. This mode can take much longer than the other modes,
but can identify many kinds of problems. but can identify many kinds of problems.
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 ``theano.compile.mode.default_mode`` directly, overridden by setting :api:`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
``theano.function``. :api:`theano.function`.
For a finer level of control over which optimizations are applied, and For a finer level of control over which optimizations are applied, and
whether C or python implementations are used, read whether C or python implementations are used, read
......
...@@ -49,7 +49,7 @@ Here we instantiate an empty Module. ...@@ -49,7 +49,7 @@ Here we instantiate an empty Module.
>>> m.state = T.dscalar() >>> m.state = T.dscalar()
>>> m.inc = T.dscalar('inc') >>> m.inc = T.dscalar('inc')
Then we declares for use with our Module. Then we declare Variables for use with our Module.
Since we assign these input Variables as attributes of the Module, Since we assign these input Variables as attributes of the Module,
they will be *member Variables* of the Module. they will be *member Variables* of the Module.
Member Variables are special in a few ways, which we will see shortly. Member Variables are special in a few ways, which we will see shortly.
...@@ -57,7 +57,7 @@ Member Variables are special in a few ways, which we will see shortly. ...@@ -57,7 +57,7 @@ Member Variables are special in a few ways, which we will see shortly.
.. note:: .. note::
There is no need to name the Variable explicitly here. ``m.state`` will There is no need to name the Variable explicitly here. ``m.state`` will
be given the name 'state' automatically. be given the name ``'state'`` automatically.
.. note:: .. note::
...@@ -70,9 +70,9 @@ Member Variables are special in a few ways, which we will see shortly. ...@@ -70,9 +70,9 @@ Member Variables are special in a few ways, which we will see shortly.
>>> m.new_state = m.state + m.inc >>> m.new_state = m.state + m.inc
This line creates a Variable corresponding to some symbolic computation. This line creates a Variable corresponding to some symbolic computation.
Although this line also assigns a Variable to a Module attribute, it does not Although this line also assigns a Variable to a Module attribute, it
become a member Variable like state and inc because it represents an expression does not become a member Variable like ``state`` and ``inc`` because it
result. represents an expression *result*.
>>> m.add = Method(m.inc, m.new_state, {m.state: m.new_state}) >>> m.add = Method(m.inc, m.new_state, {m.state: m.new_state})
...@@ -94,17 +94,19 @@ computation and whose attributes contain values such as numbers and numpy ...@@ -94,17 +94,19 @@ computation and whose attributes contain values such as numbers and numpy
ndarrays. ndarrays.
At this point something special happens for our member Variables too. At this point something special happens for our member Variables too.
In the 'acc' object, make allocates room to store numbers for m's member In the ``acc`` object, make allocates room to store numbers for ``m``'s
Variables. By using the string 'state' as a keyword argument, we tell Theano to member Variables. By using the string ``'state'`` as a keyword
store the number 0 for the member Variable called 'state'. By not mentioning argument, we tell Theano to store the number ``0`` for the member
the 'inc' variable, we associate None to the 'inc' Variable. Variable called ``state``. By not mentioning the ``inc`` variable, we
associate ``None`` to the ``inc`` Variable.
>>> acc.state, acc.inc >>> acc.state, acc.inc
array(0.0), None array(0.0), None
Since 'state' was declared as a member Variable of 'm', we can access it's value Since ``state`` was declared as a member Variable of ``m``, we can
in the 'acc' object by the same attribute. Ditto for 'inc'. access it's value in the ``acc`` object by the same attribute.
Ditto for ``inc``.
.. note:: .. note::
...@@ -119,16 +121,19 @@ array(2.0) ...@@ -119,16 +121,19 @@ array(2.0)
>>> acc.state, acc.inc >>> acc.state, acc.inc
array(2.0), None array(2.0), None
When we call the ``acc.add`` method, the value 2 is used for the symbolic 'm.inc' When we call the ``acc.add`` method, the value ``2`` is used for the
The first line evaluates the output and all the updates given to the symbolic ``m.inc``. The first line evaluates the output and all the
'acc' Method's ``updates`` field. We only had updates given in the ``updates`` argument of the call to Method that
one update which mapped ``state`` to ``new_state`` and you can see declared ``acc``. We only had one update which mapped ``state`` to
that it works as intended, adding the argument to the internal state. ``new_state`` and you can see that it works as intended, adding the
argument to the internal state.
Note also that 'acc.inc' is still None after our call. Since 'm.inc' was listed
as an input the Method, the method got it's own private storage container for Note also that ``acc.inc`` is still ``None`` after our call. Since
'm.inc'. If we had left 'm.inc' out of the Method input list, then it the ``m.inc`` was listed as an input in the call to Method that created
method would have used the module's storage for ``m.inc`` instead. ``m.add``, when ``acc.add`` was created by the call to ``m.make``, a
private storage container was allocated to hold the first parameter.
If we had left ``m.inc`` out of the Method input list, then ``acc.add``
would have used ``acc.inc`` instead.
>>> acc.state = 39.99 >>> acc.state = 39.99
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论