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

merge

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