Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4e010efd
提交
4e010efd
authored
8月 06, 2010
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
reverted the many copies scan used to do since it introduced bugs and the…
reverted the many copies scan used to do since it introduced bugs and the corner case it was suppose to address was fixed by Pascal L.
上级
a21a33fd
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
32 行增加
和
25 行删除
+32
-25
scan.py
theano/scan.py
+4
-25
test_scan.py
theano/tests/test_scan.py
+28
-0
没有找到文件。
theano/scan.py
浏览文件 @
4e010efd
...
@@ -377,7 +377,6 @@ def scan(fn, sequences=[], outputs_info=[], non_sequences=[],
...
@@ -377,7 +377,6 @@ def scan(fn, sequences=[], outputs_info=[], non_sequences=[],
seqs
=
[
sequences
]
seqs
=
[
sequences
]
else
:
else
:
seqs
=
sequences
seqs
=
sequences
if
not
(
type
(
outputs_info
)
in
(
list
,
tuple
)):
if
not
(
type
(
outputs_info
)
in
(
list
,
tuple
)):
outs_info
=
[
outputs_info
]
outs_info
=
[
outputs_info
]
else
:
else
:
...
@@ -633,29 +632,10 @@ def scan(fn, sequences=[], outputs_info=[], non_sequences=[],
...
@@ -633,29 +632,10 @@ def scan(fn, sequences=[], outputs_info=[], non_sequences=[],
# remove shared variables from the non sequences list
# remove shared variables from the non sequences list
# such that we can compile the function ( the user has the option to add them when
# such that we can compile the function ( the user has the option to add them when
# writing scan, because in some situations this might make the code more readable)
# writing scan, because in some situations this might make the code more readable)
# Also duplicate the list of non sequences arguments to contain copies of the
# non-shared inputs ( this fixes the case when one of this inputs has a default
# update attached to it that belongs to some shared random stream )
#
# Note : In that case, scan assumes that you do not want to draw new numbers at
# every call ( you would have made the internal function do that explicitly
# if you wanted to) but rather to use that initial draw as a matrix of values
new_non_seqs
=
[]
notshared_other_args
=
[]
notshared_other_args
=
[]
notshared_other_args_copies
=
[]
for
non_seq
in
non_seqs
:
for
non_seq
in
non_seqs
:
if
not
isinstance
(
non_seq
,
SharedVariable
):
if
not
isinstance
(
non_seq
,
SharedVariable
):
if
n_fixed_steps
not
in
[
-
1
,
1
]:
non_seq_copy
=
non_seq
.
type
()
if
non_seq
.
name
:
non_seq_copy
.
name
=
non_seq
.
name
+
'_copy'
else
:
non_seq_copy
=
non_seq
notshared_other_args
+=
[
non_seq
]
notshared_other_args
+=
[
non_seq
]
notshared_other_args_copies
+=
[
non_seq_copy
]
new_non_seqs
+=
[
non_seq_copy
]
else
:
new_non_seqs
+=
[
non_seq
]
# add only the not shared variables to the arguments of the dummy
# add only the not shared variables to the arguments of the dummy
# function [ a function should not get shared variables as input ]
# function [ a function should not get shared variables as input ]
...
@@ -663,10 +643,10 @@ def scan(fn, sequences=[], outputs_info=[], non_sequences=[],
...
@@ -663,10 +643,10 @@ def scan(fn, sequences=[], outputs_info=[], non_sequences=[],
for
arg
in
args
:
for
arg
in
args
:
if
not
isinstance
(
arg
,
SharedVariable
):
if
not
isinstance
(
arg
,
SharedVariable
):
dummy_args
+=
[
arg
]
dummy_args
+=
[
arg
]
dummy_args
+=
notshared_other_args
_copies
dummy_args
+=
notshared_other_args
# arguments for the lambda expression that gives us the output
# arguments for the lambda expression that gives us the output
# of the inner function
# of the inner function
args
+=
n
ew_n
on_seqs
args
+=
non_seqs
# when we apply the lambda expression we get a mixture of update rules
# when we apply the lambda expression we get a mixture of update rules
# and outputs that needs to be separated
# and outputs that needs to be separated
...
@@ -776,9 +756,8 @@ def scan(fn, sequences=[], outputs_info=[], non_sequences=[],
...
@@ -776,9 +756,8 @@ def scan(fn, sequences=[], outputs_info=[], non_sequences=[],
# or defult behaviour ( like always add the extra outputs at the end !?)
# or defult behaviour ( like always add the extra outputs at the end !?)
# But I did not bother implementing this, I leave it to the user to clearly
# But I did not bother implementing this, I leave it to the user to clearly
# express what he/she wants to do
# express what he/she wants to do
raise
ValueError
(
'There has been a terrible mistake in our input arguments'
raise
ValueError
(
'Scan is totally lost. Make sure that you indicate for each'
' and scan is totally lost. Make sure that you indicate for every '
' output what taps you want to use, or None, if you do not want to'
' output what taps you want to use, or None, if you do not want to '
' use any !'
)
' use any !'
)
inner_fn_inputs
=
[
input
.
variable
for
input
in
\
inner_fn_inputs
=
[
input
.
variable
for
input
in
\
dummy_f
.
maker
.
expanded_inputs
[:
dummy_notshared_ins
+
dummy_notshared_init_outs
]]
dummy_f
.
maker
.
expanded_inputs
[:
dummy_notshared_ins
+
dummy_notshared_init_outs
]]
...
...
theano/tests/test_scan.py
浏览文件 @
4e010efd
...
@@ -975,6 +975,34 @@ class T_Scan(unittest.TestCase):
...
@@ -975,6 +975,34 @@ class T_Scan(unittest.TestCase):
print
f
([
2
,
3
])
print
f
([
2
,
3
])
assert
numpy
.
allclose
(
f
([
2
,
3
])
,
5
)
assert
numpy
.
allclose
(
f
([
2
,
3
])
,
5
)
def
test_computing_gradient
(
self
):
x1
=
theano
.
tensor
.
scalar
()
x2
=
theano
.
shared
(
numpy
.
array
([
1
,
2
,
3
,
4
,
5
]))
K
=
x2
*
x1
out
,
updates
=
theano
.
scan
(
lambda
i
,
v
:
theano
.
tensor
.
grad
(
K
[
i
],
v
),
sequences
=
theano
.
tensor
.
arange
(
K
.
shape
[
0
]),
non_sequences
=
x1
)
f
=
theano
.
function
([
x1
],
out
)
print
f
(
3.
)
assert
numpy
.
all
(
f
(
3.
)
!=
0.
)
'''
def test_shared_updates(self):
X = theano.shared( numpy.array( [[1,2,3],[4,5,6]]))
out,updates = theano.scan( lambda :{X: X+1}, outputs_info = [], non_sequences= [],
sequences = [], n_steps = 10)
f = theano.function([],[], updates = updates)
f()
print X.value
'''
if
__name__
==
'__main__'
:
if
__name__
==
'__main__'
:
unittest
.
main
()
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论