Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
90aefc28
提交
90aefc28
authored
9月 05, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
changed gradient.grad to not introduce integer-valued gradients
上级
b115fbc9
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
31 行增加
和
3 行删除
+31
-3
gradient.py
theano/gradient.py
+30
-3
basic.py
theano/tensor/basic.py
+1
-0
没有找到文件。
theano/gradient.py
浏览文件 @
90aefc28
...
@@ -444,7 +444,7 @@ def grad(cost, wrt, g_cost=None, consider_constant=None, warn_type=False,
...
@@ -444,7 +444,7 @@ def grad(cost, wrt, g_cost=None, consider_constant=None, warn_type=False,
grad_dict
=
{}
grad_dict
=
{}
# by default, the gradient of the cost is 1
# by default, the gradient of the cost is 1
if
g_cost
is
None
:
if
g_cost
is
None
:
g_cost
=
tensor
.
ones_like
(
cost
)
g_cost
=
_float_
ones_like
(
cost
)
grad_dict
[
cost
]
=
g_cost
grad_dict
[
cost
]
=
g_cost
# the gradient of the constants is 0
# the gradient of the constants is 0
...
@@ -477,12 +477,18 @@ def grad(cost, wrt, g_cost=None, consider_constant=None, warn_type=False,
...
@@ -477,12 +477,18 @@ def grad(cost, wrt, g_cost=None, consider_constant=None, warn_type=False,
if
add_names
:
if
add_names
:
cost_name
=
cost
.
name
cost_name
=
cost
.
name
# Make sure we didn't initialize the grad_dict with any ints
for
var
in
grad_dict
:
g
=
grad_dict
[
var
]
if
hasattr
(
g
.
type
,
'dtype'
):
assert
g
.
type
.
dtype
.
find
(
'float'
)
!=
-
1
rval
=
_populate_grad_dict
(
var_to_node_to_idx
,
rval
=
_populate_grad_dict
(
var_to_node_to_idx
,
grad_dict
,
wrt
,
cost_name
)
grad_dict
,
wrt
,
cost_name
)
for
i
in
xrange
(
len
(
rval
)):
for
i
in
xrange
(
len
(
rval
)):
if
isinstance
(
rval
[
i
]
.
type
,
DisconnectedType
):
if
isinstance
(
rval
[
i
]
.
type
,
DisconnectedType
):
rval
[
i
]
=
wrt
[
i
]
.
zeros_like
(
)
rval
[
i
]
=
_float_zeros_like
(
wrt
[
i
]
)
if
using_tuple
:
if
using_tuple
:
rval
=
tuple
(
rval
)
rval
=
tuple
(
rval
)
...
@@ -931,10 +937,31 @@ def grad_sources_inputs(sources, graph_inputs):
...
@@ -931,10 +937,31 @@ def grad_sources_inputs(sources, graph_inputs):
for
key
in
grad_dict
:
for
key
in
grad_dict
:
if
isinstance
(
grad_dict
[
key
]
.
type
,
DisconnectedType
):
if
isinstance
(
grad_dict
[
key
]
.
type
,
DisconnectedType
):
if
hasattr
(
key
,
'zeros_like'
):
if
hasattr
(
key
,
'zeros_like'
):
grad_dict
[
key
]
=
key
.
zeros_like
(
)
grad_dict
[
key
]
=
_float_zeros_like
(
key
)
return
grad_dict
return
grad_dict
def
_float_zeros_like
(
x
):
""" Like zeros_like, but forces the object to have a
a floating point dtype """
rval
=
x
.
zeros_like
()
if
rval
.
type
.
dtype
.
find
(
'float'
)
!=
-
1
:
return
rval
return
rval
.
astype
(
theano
.
config
.
floatX
)
def
_float_ones_like
(
x
):
""" Like ones_like, but forces the object to have a
floating point dtype """
rval
=
tensor
.
ones_like
(
x
)
if
rval
.
type
.
dtype
.
find
(
'float'
)
!=
-
1
:
return
rval
return
rval
.
astype
(
theano
.
config
.
floatX
)
class
numeric_grad
(
object
):
class
numeric_grad
(
object
):
"""
"""
...
...
theano/tensor/basic.py
浏览文件 @
90aefc28
...
@@ -1910,6 +1910,7 @@ class TensorFromScalar(Op):
...
@@ -1910,6 +1910,7 @@ class TensorFromScalar(Op):
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
s
,
=
inp
s
,
=
inp
dt
,
=
grads
dt
,
=
grads
assert
dt
.
type
.
dtype
.
find
(
'float'
)
!=
-
1
return
[
scalar_from_tensor
(
dt
)]
return
[
scalar_from_tensor
(
dt
)]
def
__str__
(
self
):
def
__str__
(
self
):
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论