Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
fdeda4f8
提交
fdeda4f8
authored
1月 04, 2011
作者:
Razvan Pascanu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixed a bug reported by cityhall consisting in not calling tensor.as_tensor on…
Fixed a bug reported by cityhall consisting in not calling tensor.as_tensor on arguments before calling make_node
上级
79ebf621
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
38 行增加
和
2 行删除
+38
-2
scan.py
theano/scan.py
+10
-2
test_scan.py
theano/tests/test_scan.py
+28
-0
没有找到文件。
theano/scan.py
浏览文件 @
fdeda4f8
...
...
@@ -44,7 +44,7 @@ import tensor
import
misc.safe_asarray
as
safe_asarray
from
tensor
import
opt
,
TensorType
import
gof
from
gof
import
Optimizer
,
toolbox
,
Op
,
Apply
from
gof
import
Optimizer
,
toolbox
,
Op
,
Apply
,
Variable
from
compile
import
optdb
,
SharedVariable
,
function
,
Param
import
compile
import
gradient
...
...
@@ -1559,8 +1559,15 @@ class Scan(Op):
theano
.
config
.
floatX
))
inner_gfn_ins
=
inner_g_outs
+
self
.
inputs
g_args
=
[
self
.
n_steps
]
+
g_outs
[:
self
.
n_outs_not_shared
]
\
# Make sure you don't have numbers in here
if
not
isinstance
(
self
.
n_steps
,
Variable
):
n_steps
=
tensor
.
as_tensor
(
self
.
n_steps
)
else
:
n_steps
=
self
.
n_steps
g_args
=
[
n_steps
]
+
g_outs
[:
self
.
n_outs_not_shared
]
\
+
scan_outputs
+
args
[
1
:]
truncate_gradient
=
self
.
truncate_gradient
for
x
in
self
.
store_steps
[:
self
.
n_outs_not_shared
]:
if
x
>
0
:
...
...
@@ -1571,6 +1578,7 @@ class Scan(Op):
self
.
n_seqs
,
self
.
n_outs
,
self
.
n_outs_not_shared
,
self
.
go_backwards
,
self
.
seqs_taps
,
self
.
outs_taps
,
truncate_gradient
)
g_scan_outs
=
g_scan
(
g_args
)
if
not
type
(
g_scan_outs
)
in
(
list
,
tuple
):
g_scan_outs
=
[
g_scan_outs
]
...
...
theano/tests/test_scan.py
浏览文件 @
fdeda4f8
...
...
@@ -1039,6 +1039,34 @@ class T_Scan(unittest.TestCase):
assert
updates
[
b
]
.
type
.
ndim
==
b
.
type
.
ndim
def
test_scan_as_tensor_on_gradients
(
self
):
"""
Bug reported by cityhall on scan when computing the gradients
"""
to_scan
=
theano
.
tensor
.
dvector
(
'to_scan'
)
seq
=
theano
.
tensor
.
dmatrix
(
'seq'
)
f1
=
theano
.
tensor
.
dscalar
(
'f1'
)
def
scanStep
(
prev
,
seq
,
f1
):
return
prev
+
f1
*
seq
scanned
,
_
=
theano
.
scan
(
fn
=
scanStep
,
\
sequences
=
[
seq
],
\
outputs_info
=
[
to_scan
],
\
non_sequences
=
[
f1
])
f_scan
=
theano
.
function
(
inputs
=
[
to_scan
,
seq
,
f1
],
outputs
=
scanned
)
f_scan
([
1
,
2
,
3
],
numpy
.
arange
(
12
)
.
reshape
([
4
,
3
]),
1.
)
t_grad
=
theano
.
tensor
.
grad
(
scanned
.
sum
(),
wrt
=
[
to_scan
,
f1
],
consider_constant
=
[
seq
])
f_grad
=
theano
.
function
(
inputs
=
[
to_scan
,
seq
,
f1
],
outputs
=
t_grad
)
f_scan
([
1
,
2
,
3
],
numpy
.
arange
(
12
)
.
reshape
([
4
,
3
]),
1.
)
f_grad
([
1
,
2
,
3
],
numpy
.
arange
(
12
)
.
reshape
([
4
,
3
]),
1.
)
if
__name__
==
'__main__'
:
unittest
.
main
()
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论