Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
dc7a2384
提交
dc7a2384
authored
8月 28, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
changed old tests, gradients must now be variables, not numpy
ambiguous whether to turn numpy into sparse or dense variable
上级
07ee83bf
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
16 行删除
+18
-16
gradient.py
theano/gradient.py
+6
-5
test_gradient.py
theano/tests/test_gradient.py
+12
-11
没有找到文件。
theano/gradient.py
浏览文件 @
dc7a2384
...
@@ -20,9 +20,9 @@ from theano import gof
...
@@ -20,9 +20,9 @@ from theano import gof
from
theano.gof
import
Variable
from
theano.gof
import
Variable
from
theano.gof.python25
import
all
from
theano.gof.python25
import
all
import
theano.gof.utils
import
theano.gof.utils
tensor
=
None
from
theano.gof.nan_type
import
NaNType
from
theano.gof.nan_type
import
NaNType
from
theano.printing
import
min_informative_str
from
theano.printing
import
min_informative_str
tensor
=
None
_msg_retType
=
'op.grad(...) returned a non-list'
_msg_retType
=
'op.grad(...) returned a non-list'
...
@@ -604,13 +604,14 @@ def grad(cost, wrt, g_cost = None, consider_constant = None, warn_type = 'ignore
...
@@ -604,13 +604,14 @@ def grad(cost, wrt, g_cost = None, consider_constant = None, warn_type = 'ignore
def
grad_sources_inputs
(
sources
,
graph_inputs
,
warn_type
=
'ignored'
):
def
grad_sources_inputs
(
sources
,
graph_inputs
,
warn_type
=
'ignored'
):
global
tensor
if
tensor
is
None
:
from
theano
import
tensor
outputs
,
output_grads
=
zip
(
*
sources
)
outputs
,
output_grads
=
zip
(
*
sources
)
for
output_grad
in
output_grads
:
if
not
hasattr
(
output_grad
,
'type'
):
raise
TypeError
(
'output grads must be theano variables.'
'Ambiguous whether
%
s should be made into tensor'
' or sparse theano variable'
%
str
(
type
(
output_grad
)))
if
graph_inputs
is
None
:
if
graph_inputs
is
None
:
graph_inputs
=
gof
.
graph
.
inputs
(
outputs
)
graph_inputs
=
gof
.
graph
.
inputs
(
outputs
)
...
...
theano/tests/test_gradient.py
浏览文件 @
dc7a2384
...
@@ -11,6 +11,7 @@ from theano import gradient
...
@@ -11,6 +11,7 @@ from theano import gradient
from
theano.tensor.nnet.Conv3D
import
conv3D
from
theano.tensor.nnet.Conv3D
import
conv3D
from
theano
import
config
from
theano
import
config
one
=
theano
.
tensor
.
as_tensor_variable
(
1.
)
def
_grad_sources_inputs
(
*
args
):
def
_grad_sources_inputs
(
*
args
):
# warn_type was introduced after this code, it complains throughout for nothing.
# warn_type was introduced after this code, it complains throughout for nothing.
...
@@ -31,7 +32,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -31,7 +32,7 @@ class test_grad_sources_inputs(unittest.TestCase):
pass
pass
a
=
retNone
()
.
make_node
()
a
=
retNone
()
.
make_node
()
try
:
try
:
_grad_sources_inputs
([(
a
.
out
,
1
)],
None
)
_grad_sources_inputs
([(
a
.
out
,
one
)],
None
)
except
ValueError
,
e
:
except
ValueError
,
e
:
self
.
assertTrue
(
e
[
0
]
is
gradient
.
_msg_retType
)
self
.
assertTrue
(
e
[
0
]
is
gradient
.
_msg_retType
)
return
return
...
@@ -49,10 +50,10 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -49,10 +50,10 @@ class test_grad_sources_inputs(unittest.TestCase):
i
=
theano
.
tensor
.
vector
()
i
=
theano
.
tensor
.
vector
()
j
=
theano
.
tensor
.
vector
()
j
=
theano
.
tensor
.
vector
()
a1
=
retNone
()
.
make_node
(
i
)
a1
=
retNone
()
.
make_node
(
i
)
g
=
_grad_sources_inputs
([(
a1
.
out
,
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
out
,
one
)],
None
)
a2
=
retNone
()
.
make_node
(
i
,
j
)
a2
=
retNone
()
.
make_node
(
i
,
j
)
try
:
try
:
g
=
_grad_sources_inputs
([(
a2
.
out
,
1
)],
None
)
g
=
_grad_sources_inputs
([(
a2
.
out
,
one
)],
None
)
except
ValueError
,
e
:
except
ValueError
,
e
:
return
return
self
.
fail
()
self
.
fail
()
...
@@ -68,7 +69,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -68,7 +69,7 @@ class test_grad_sources_inputs(unittest.TestCase):
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
return
gval
,
return
gval
,
a1
=
O
()
.
make_node
()
a1
=
O
()
.
make_node
()
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
one
)],
None
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
0
]]
is
gval
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
0
]]
is
gval
)
def
test_1in_Nout
(
self
):
def
test_1in_Nout
(
self
):
...
@@ -84,7 +85,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -84,7 +85,7 @@ class test_grad_sources_inputs(unittest.TestCase):
gz1
,
gz2
=
grads
gz1
,
gz2
=
grads
return
gval
,
return
gval
,
a1
=
O
()
.
make_node
()
a1
=
O
()
.
make_node
()
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
one
)],
None
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
0
]]
is
gval
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
0
]]
is
gval
)
def
test_Nin_1out
(
self
):
def
test_Nin_1out
(
self
):
...
@@ -101,7 +102,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -101,7 +102,7 @@ class test_grad_sources_inputs(unittest.TestCase):
gz
,
=
grads
gz
,
=
grads
return
(
gval0
,
gval1
)
return
(
gval0
,
gval1
)
a1
=
O
()
.
make_node
()
a1
=
O
()
.
make_node
()
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
one
)],
None
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
0
]]
is
gval0
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
0
]]
is
gval0
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
1
]]
is
gval1
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
1
]]
is
gval1
)
...
@@ -117,7 +118,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -117,7 +118,7 @@ class test_grad_sources_inputs(unittest.TestCase):
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
return
gval0
,
gval1
return
gval0
,
gval1
a1
=
O
()
.
make_node
()
a1
=
O
()
.
make_node
()
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a1
.
outputs
[
0
],
one
)],
None
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
0
]]
is
gval0
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
0
]]
is
gval0
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
1
]]
is
gval1
)
self
.
assertTrue
(
g
[
a1
.
inputs
[
1
]]
is
gval1
)
...
@@ -133,7 +134,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -133,7 +134,7 @@ class test_grad_sources_inputs(unittest.TestCase):
return
[
1
]
return
[
1
]
i
=
theano
.
tensor
.
matrix
()
i
=
theano
.
tensor
.
matrix
()
a1
=
O
(
self
)
.
make_node
(
i
)
a1
=
O
(
self
)
.
make_node
(
i
)
g
=
grad_sources_inputs
([(
a1
.
outputs
[
0
],
1
)],
None
,
warn_type
=
False
)
g
=
grad_sources_inputs
([(
a1
.
outputs
[
0
],
one
)],
None
,
warn_type
=
False
)
self
.
assertTrue
(
g
[
i
]
is
1
)
self
.
assertTrue
(
g
[
i
]
is
1
)
def
test_some_None_igrads
(
self
):
def
test_some_None_igrads
(
self
):
...
@@ -155,12 +156,12 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -155,12 +156,12 @@ class test_grad_sources_inputs(unittest.TestCase):
k
=
theano
.
tensor
.
matrix
()
k
=
theano
.
tensor
.
matrix
()
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a2
=
O
(
self
,
True
)
.
make_node
(
a1
.
outputs
[
1
],
k
)
a2
=
O
(
self
,
True
)
.
make_node
(
a1
.
outputs
[
1
],
k
)
g
=
grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
)],
None
,
warn_type
=
False
)
g
=
grad_sources_inputs
([(
a2
.
outputs
[
0
],
one
)],
None
,
warn_type
=
False
)
self
.
assertTrue
(
g
[
i
]
is
1
and
j
not
in
g
and
k
not
in
g
)
self
.
assertTrue
(
g
[
i
]
is
1
and
j
not
in
g
and
k
not
in
g
)
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a2
=
O
(
self
,
True
)
.
make_node
(
k
,
a1
.
outputs
[
1
])
a2
=
O
(
self
,
True
)
.
make_node
(
k
,
a1
.
outputs
[
1
])
g
=
_grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
)],
None
)
g
=
_grad_sources_inputs
([(
a2
.
outputs
[
0
],
one
)],
None
)
self
.
assertTrue
(
g
[
k
]
is
1
and
i
not
in
g
and
j
not
in
g
)
self
.
assertTrue
(
g
[
k
]
is
1
and
i
not
in
g
and
j
not
in
g
)
def
test_inputs
(
self
):
def
test_inputs
(
self
):
...
@@ -186,7 +187,7 @@ class test_grad_sources_inputs(unittest.TestCase):
...
@@ -186,7 +187,7 @@ class test_grad_sources_inputs(unittest.TestCase):
k
=
theano
.
tensor
.
matrix
()
k
=
theano
.
tensor
.
matrix
()
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a1
=
O
(
self
,
True
)
.
make_node
(
i
,
j
)
a2
=
O
(
self
,
True
)
.
make_node
(
k
,
a1
.
outputs
[
1
])
a2
=
O
(
self
,
True
)
.
make_node
(
k
,
a1
.
outputs
[
1
])
g
=
_grad_sources_inputs
([(
a2
.
outputs
[
0
],
1
),
(
a1
.
outputs
[
1
],
4
),
g
=
_grad_sources_inputs
([(
a2
.
outputs
[
0
],
one
),
(
a1
.
outputs
[
1
],
4
),
(
a1
.
outputs
[
0
],
3
),
(
a1
.
outputs
[
0
],
3
)],
a1
.
outputs
)
(
a1
.
outputs
[
0
],
3
),
(
a1
.
outputs
[
0
],
3
)],
a1
.
outputs
)
self
.
assertTrue
(
g
[
a2
.
inputs
[
0
]]
==
1
)
self
.
assertTrue
(
g
[
a2
.
inputs
[
0
]]
==
1
)
self
.
assertTrue
(
g
[
a2
.
inputs
[
1
]]
==
5
)
self
.
assertTrue
(
g
[
a2
.
inputs
[
1
]]
==
5
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论