提交 f16ac4a8 authored 作者: james@X40's avatar james@X40

merge

......@@ -47,12 +47,12 @@ Here we instantiate an empty Module.
>>> m.state = T.dscalar()
>>> m.inc = T.dscalar('inc')
Then we declare a Variable for use with our Module. That Variable will
be a :ref:`member` of the Module, which means that it will be
accessible as a field of the object we will create later (for reading
and writing). It will also be accessible from any :ref:`method`
defined in our Module.
Then we declares for use with our Module.
Since we assign these input Variables as attributes of the Module,
they will be *member Variables* of the Module.
Member Variables are special in a few ways, which we will see shortly.
.. note::
......@@ -60,11 +60,6 @@ defined in our Module.
be given the name 'state' automatically.
>>> m.inc = T.dscalar('inc')
The ``inc`` variable doesn't need to be declared as a member of ``m`` because
we only use it as a Method input.
.. note::
Since we made it a member of ``m``, the ``acc`` object will have an
......@@ -74,9 +69,10 @@ we only use it as a Method input.
>>> m.new_state = m.state + m.inc
This line creates a Variable corresponding to some symbolic computation. It
doesn't matter to Theano whether we put it inside ``m`` or not. Feel free to
put such results of symbolic computation wherever is most convenient.
This line creates a Variable corresponding to some symbolic computation.
Although this line also assigns a Variable to a Module attribute, it does not
become a member Variable like state and inc because it represents an expression
result.
>>> m.add = Method(m.inc, m.new_state, {m.state: m.new_state})
......@@ -97,16 +93,18 @@ Calling ``make`` on ``m`` creates an object that can do real
computation and whose attributes contain values such as numbers and numpy
ndarrays.
The keyword arguments given to make are optional and are used to
assign initial values to each Member. If a Member is omitted, the
initial value is None.
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
Variables. By using the string 'state' as a keyword argument, we tell Theano to
store the number 0 for the member Variable called 'state'. By not mentioning
the 'inc' variable, we associate None to the 'inc' Variable.
>>> acc.state, acc.inc
array(0.0), None
Since state was declared as a Member, we can access it using
'.state'.
Since 'state' was declared as a member Variable of 'm', we can access it's value
in the 'acc' object by the same attribute. Ditto for 'inc'.
.. note::
......@@ -118,8 +116,8 @@ Since state was declared as a Member, we can access it using
>>> acc.add(2)
array(2.0)
>>> acc.state
array(2.0)
>>> acc.state, acc.inc
array(2.0), None
When we call the ``acc.add`` method, all the updates given to the
corresponding Method's ``updates`` field are performed. We only had
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论