Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
8a965eb4
提交
8a965eb4
authored
4月 09, 2015
作者:
Pascal Lamblin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #2727 from carriepl/scan_connection_pattern
Stop confusing inner and outer outputs in connection_pattern()
上级
81727020
d61f56fc
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
76 行增加
和
19 行删除
+76
-19
scan_op.py
theano/scan_module/scan_op.py
+38
-19
test_scan.py
theano/scan_module/tests/test_scan.py
+38
-0
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
8a965eb4
...
@@ -1471,35 +1471,54 @@ class Scan(PureOp):
...
@@ -1471,35 +1471,54 @@ class Scan(PureOp):
# input to `z_t` then `x` is an input to `z_t`.
# input to `z_t` then `x` is an input to `z_t`.
n_outs
=
len
(
node
.
outputs
)
n_outs
=
len
(
node
.
outputs
)
outer_iidx_from_
inner_iidx
=
self
.
get_outer_iidx_from_inner_i
idx_seq
()
outer_iidx_from_
outer_oidx
=
self
.
get_outer_iidx_from_outer_o
idx_seq
()
for
steps
in
xrange
(
n_outs
):
for
steps
in
xrange
(
n_outs
):
for
iidx
in
xrange
(
n_outs
):
for
iidx
in
xrange
(
n_outs
):
for
jidx
in
xrange
(
n_outs
):
for
jidx
in
xrange
(
n_outs
):
# Get the idx of the
first inner input corresponding to
# Get the idx of the
outer input corresponding to that
#
that inn
er output
#
out
er output
j_inp_idx
=
self
.
get_input_pos
(
jidx
)
j_inp_idx
=
outer_iidx_from_outer_oidx
[
jidx
]
if
j_inp_idx
==
-
1
:
if
j_inp_idx
!=
-
1
:
# No corresponding inner input : default to what scan
if
connection_pattern
[
j_inp_idx
][
iidx
]
==
True
:
# was doing in the previous version in those cases
for
k
in
xrange
(
len
(
connection_pattern
)):
# which *seems* to be a hack designed to avoid passing
if
connection_pattern
[
k
][
jidx
]:
# the condition below but it's not certain.
connection_pattern
[
k
][
iidx
]
=
True
j_inp_idx
=
0
else
:
# Get the idx of the outer input corresponding to that
# inner input
j_inp_idx
=
outer_iidx_from_inner_iidx
[
j_inp_idx
]
if
connection_pattern
[
j_inp_idx
][
iidx
]
==
True
:
for
k
in
xrange
(
len
(
connection_pattern
)):
if
connection_pattern
[
k
][
jidx
]:
connection_pattern
[
k
][
iidx
]
=
True
node
.
tag
.
connection_pattern
=
connection_pattern
node
.
tag
.
connection_pattern
=
connection_pattern
return
connection_pattern
return
connection_pattern
def
get_outer_iidx_from_outer_oidx_seq
(
self
):
""" Return a sequence where the value at the i-th position is the
index of the outer input corresponding to the i-th outer output
NOTE: mitmots, mitsots, sitsots and shared outputs have corresponding
outer inputs but not nitsots.
"""
nb_outer_outputs
=
(
self
.
n_mit_mot
+
self
.
n_mit_sot
+
self
.
n_sit_sot
+
self
.
n_nit_sot
+
self
.
n_shared_outs
)
result
=
[
-
1
]
*
nb_outer_outputs
# Process mitmots, mitsots and sitsots
input_offset
=
1
+
self
.
n_seqs
output_offset
=
0
for
i
in
range
(
len
(
self
.
tap_array
)):
result
[
output_offset
]
=
input_offset
input_offset
+=
1
output_offset
+=
1
# Process shared inputs/outputs
output_offset
+=
self
.
n_nit_sot
for
i
in
range
(
self
.
n_shared_outs
):
result
[
output_offset
]
=
input_offset
input_offset
+=
1
output_offset
+=
1
return
result
def
get_outer_iidx_from_inner_iidx_seq
(
self
):
def
get_outer_iidx_from_inner_iidx_seq
(
self
):
""" Return a sequence where the value at the i-th position is the
""" Return a sequence where the value at the i-th position is the
index of the outer input corresponding to the i-th inner input
index of the outer input corresponding to the i-th inner input
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
8a965eb4
...
@@ -836,8 +836,22 @@ class T_Scan(unittest.TestCase):
...
@@ -836,8 +836,22 @@ class T_Scan(unittest.TestCase):
outputs_info
=
[{
'initial'
:
a0
,
'taps'
:
[
-
2
,
-
1
]},
outputs_info
=
[{
'initial'
:
a0
,
'taps'
:
[
-
2
,
-
1
]},
{
'initial'
:
b0
,
'taps'
:
[
-
2
,
-
1
]}],
{
'initial'
:
b0
,
'taps'
:
[
-
2
,
-
1
]}],
n_steps
=
2
)
n_steps
=
2
)
tensor
.
grad
(
a
[
-
1
],
a0
)
tensor
.
grad
(
a
[
-
1
],
a0
)
# Also validate that the methods get_outer_iidx_from_outer_oidx_seq
# and get_outer_iidx_from_inner_iidx_seq produce the correct results
scan_node
=
a
.
owner
.
inputs
[
0
]
.
owner
result
=
scan_node
.
op
.
get_outer_iidx_from_outer_oidx_seq
()
expected_result
=
[
1
,
2
]
assert
(
result
==
expected_result
)
result
=
scan_node
.
op
.
get_outer_iidx_from_inner_iidx_seq
()
expected_result
=
[
1
,
1
,
2
,
2
]
assert
(
result
==
expected_result
)
def
test_connection_pattern2
(
self
):
def
test_connection_pattern2
(
self
):
# This tests for a crash in connection_pattern() when a scan node
# This tests for a crash in connection_pattern() when a scan node
# has more than one mitmot (multiple input taps as well as
# has more than one mitmot (multiple input taps as well as
...
@@ -858,6 +872,18 @@ class T_Scan(unittest.TestCase):
...
@@ -858,6 +872,18 @@ class T_Scan(unittest.TestCase):
scan_node
=
g_out
[
0
]
.
owner
.
inputs
[
1
]
.
owner
.
inputs
[
1
]
.
owner
.
inputs
[
0
]
.
owner
scan_node
=
g_out
[
0
]
.
owner
.
inputs
[
1
]
.
owner
.
inputs
[
1
]
.
owner
.
inputs
[
0
]
.
owner
connection_pattern
=
scan_node
.
op
.
connection_pattern
(
scan_node
)
connection_pattern
=
scan_node
.
op
.
connection_pattern
(
scan_node
)
# Also validate that the methods get_outer_iidx_from_outer_oidx_seq
# and get_outer_iidx_from_inner_iidx_seq produce the correct results
scan_node
=
out
.
owner
.
inputs
[
0
]
.
owner
result
=
scan_node
.
op
.
get_outer_iidx_from_outer_oidx_seq
()
expected_result
=
[
2
]
assert
(
result
==
expected_result
)
result
=
scan_node
.
op
.
get_outer_iidx_from_inner_iidx_seq
()
expected_result
=
[
1
,
2
,
2
]
assert
(
result
==
expected_result
)
def
test_grad_two_scans
(
self
):
def
test_grad_two_scans
(
self
):
# data input & output
# data input & output
...
@@ -1870,6 +1896,18 @@ class T_Scan(unittest.TestCase):
...
@@ -1870,6 +1896,18 @@ class T_Scan(unittest.TestCase):
analytic_grad
[
max_err_pos
],
analytic_grad
[
max_err_pos
],
num_grad
.
gx
[
max_err_pos
]))
num_grad
.
gx
[
max_err_pos
]))
# Also validate that the methods get_outer_iidx_from_outer_oidx_seq
# and get_outer_iidx_from_inner_iidx_seq produce the correct results
scan_node
=
updates
.
values
()[
0
]
.
owner
result
=
scan_node
.
op
.
get_outer_iidx_from_outer_oidx_seq
()
expected_result
=
[
3
,
-
1
,
4
]
assert
(
result
==
expected_result
)
result
=
scan_node
.
op
.
get_outer_iidx_from_inner_iidx_seq
()
expected_result
=
[
1
,
2
,
3
,
4
,
6
]
assert
(
result
==
expected_result
)
def
test_grad_multiple_outs_some_truncate
(
self
):
def
test_grad_multiple_outs_some_truncate
(
self
):
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
vW_in
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,
2
),
low
=-.
1
,
high
=.
1
))
vW_in
=
asarrayX
(
rng
.
uniform
(
size
=
(
2
,
2
),
low
=-.
1
,
high
=.
1
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论