Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ac1e27e4
提交
ac1e27e4
authored
11月 21, 2013
作者:
Frédéric Bastien
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1614 from pascanur/new_fix_grad_scan
New fix grad scan
上级
b7a21266
685323b8
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
49 行增加
和
20 行删除
+49
-20
scan_op.py
theano/scan_module/scan_op.py
+13
-12
test_scan.py
theano/scan_module/tests/test_scan.py
+36
-8
没有找到文件。
theano/scan_module/scan_op.py
浏览文件 @
ac1e27e4
...
...
@@ -1561,19 +1561,16 @@ class Scan(PureOp):
for
idx
in
xrange
(
self
.
n_mit_mot
+
self
.
n_mit_sot
):
mintap
=
numpy
.
min
(
self
.
tap_array
[
idx
])
maxtap
=
numpy
.
max
(
self
.
tap_array
[
idx
])
if
idx
<
self
.
n_mit_mot
:
outmaxtap
=
numpy
.
max
(
self
.
mitmot_out_taps
()[
idx
])
else
:
outmaxtap
=
0
seq
=
outs
[
idx
]
for
k
in
self
.
tap_array
[
idx
]:
if
maxtap
<
0
:
dim_offset
=
abs
(
maxtap
)
else
:
dim_offset
=
0
if
maxtap
==
mintap
and
maxtap
!=
0
:
nw_seq
=
seq
[:
abs
(
maxtap
)]
elif
maxtap
-
k
!=
0
:
nw_seq
=
seq
[
dim_offset
+
k
-
mintap
-
1
:
\
-
(
maxtap
-
k
+
1
)][::
-
1
]
if
outmaxtap
-
k
!=
0
:
nw_seq
=
seq
[
k
-
mintap
:
-
(
outmaxtap
-
k
)][::
-
1
]
else
:
nw_seq
=
seq
[
dim_offset
+
k
-
mintap
-
1
:
-
1
][::
-
1
]
nw_seq
=
seq
[
k
-
mintap
:
][::
-
1
]
outer_inp_seqs
.
append
(
nw_seq
)
outer_inp_seqs
+=
[
x
[:
-
1
][::
-
1
]
for
x
in
self
.
outer_sitsot_outs
(
outs
)]
...
...
@@ -1627,7 +1624,11 @@ class Scan(PureOp):
n_mitmot_inps
=
0
for
idx
in
xrange
(
self
.
n_mit_mot
):
outer_inp_mitmot
.
append
(
dC_douts
[
idx
][::
-
1
])
if
isinstance
(
dC_douts
[
idx
]
.
type
,
DisconnectedType
):
out
=
outs
[
idx
]
outer_inp_mitmot
.
append
(
tensor
.
zeros_like
(
out
))
else
:
outer_inp_mitmot
.
append
(
dC_douts
[
idx
][::
-
1
])
mitmot_inp_taps
.
append
([])
mitmot_out_taps
.
append
([])
undefined
=
False
...
...
@@ -1648,7 +1649,7 @@ class Scan(PureOp):
if
_sh
in
gof
.
graph
.
inputs
([
dC_dinps_t
[
ins_pos
]]):
undefined
=
True
n_mitmot_inps
_
+=
1
n_mitmot_inps
+=
1
ins_pos
+=
1
n_mitmot_outs
+=
1
mitmot_inp_taps
[
idx
]
.
append
(
-
self
.
tap_array
[
idx
][
jdx
])
...
...
theano/scan_module/tests/test_scan.py
浏览文件 @
ac1e27e4
...
...
@@ -3577,10 +3577,8 @@ class T_Scan(unittest.TestCase):
assert
not
opt_obj
.
belongs_to_set
(
scan_node2
,
[
scan_node1
])
def
test_remove_constants_and_unused_inputs_scan_non_seqs
(
self
):
"""Test the opt remove_constants_and_unused_inputs_scan for
non sequences.
"""
#Test the opt remove_constants_and_unused_inputs_scan for
#non sequences.
W
=
theano
.
tensor
.
matrix
(
name
=
'W'
)
v
=
theano
.
tensor
.
ivector
(
name
=
'v'
)
y1
,
_
=
theano
.
scan
(
lambda
i
,
W
:
W
[
i
],
sequences
=
v
,
...
...
@@ -3616,10 +3614,7 @@ class T_Scan(unittest.TestCase):
assert
(
len
(
inp
)
==
len
(
set
(
inp
)))
def
test_remove_constants_and_unused_inputs_scan_seqs
(
self
):
"""
Test the opt remove_constants_and_unused_inputs_scan for sequences.
"""
#Test the opt remove_constants_and_unused_inputs_scan for sequences.
W
=
theano
.
tensor
.
matrix
(
name
=
'W'
)
v
=
theano
.
tensor
.
ivector
(
name
=
'v'
)
vv
=
theano
.
tensor
.
matrix
(
name
=
'vv'
)
...
...
@@ -3661,6 +3656,39 @@ class T_Scan(unittest.TestCase):
inp
=
scan_node
.
op
.
outer_non_seqs
(
scan_node
)
assert
len
(
inp
)
==
1
def
test_hessian_bug_grad_grad_two_scans
(
self
):
#Bug reported by Bitton Tenessi
W_flat
=
tensor
.
fvector
(
name
=
'W'
)
W_flat
.
tag
.
test_value
=
numpy
.
ones
((
8
,),
dtype
=
numpy
.
float32
)
W
=
W_flat
.
reshape
((
2
,
2
,
2
))
def
loss_outer
(
i_outer
,
sum_outer
,
W
):
def
loss_inner
(
i_inner
,
sum_inner
,
W
):
return
sum_inner
+
(
W
**
2
)
.
sum
()
.
sum
()
.
sum
()
result_inner
,
_
=
theano
.
scan
(
fn
=
loss_inner
,
outputs_info
=
tensor
.
as_tensor_variable
(
numpy
.
asarray
(
0
,
dtype
=
numpy
.
float32
)),
sequences
=
tensor
.
arange
(
1
,
dtype
=
'int32'
),
non_sequences
=
[
W
],
)
return
sum_outer
+
result_inner
[
-
1
]
result_outer
,
_
=
theano
.
scan
(
fn
=
loss_outer
,
outputs_info
=
tensor
.
as_tensor_variable
(
numpy
.
asarray
(
0
,
dtype
=
numpy
.
float32
)),
sequences
=
tensor
.
arange
(
1
,
dtype
=
'int32'
),
non_sequences
=
[
W
],
)
cost
=
result_outer
[
-
1
]
H
=
theano
.
gradient
.
hessian
(
cost
,
W_flat
)
f
=
theano
.
function
([
W_flat
],
H
)
f
(
numpy
.
ones
((
8
,),
dtype
=
'float32'
))
def
test_speed
():
#
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论