Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
a931005f
提交
a931005f
authored
11月 16, 2012
作者:
Ian Goodfellow
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
remove g_cost
上级
40bbb7da
显示空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
11 行增加
和
20 行删除
+11
-20
gradient.py
theano/gradient.py
+11
-20
没有找到文件。
theano/gradient.py
浏览文件 @
a931005f
...
...
@@ -349,16 +349,13 @@ def Lop(f, wrt, eval_points, consider_constant=None,
# Gradient
#########################
def
grad
(
cost
,
wrt
,
g_cost
=
None
,
consider_constant
=
None
,
def
grad
(
cost
,
wrt
,
consider_constant
=
None
,
disconnected_inputs
=
'raise'
,
add_names
=
True
,
known_grads
=
None
,
return_disconnected
=
'zero'
):
"""
:type cost: Scalar (0-dimensional) Variable.
May optionally be None if known_grads is provided.
:type wrt: Variable or list of Variables.
:type g_cost: Scalar Variable, or None.
:param g_cost: an expression for the gradient through cost. The default is
``ones_like(cost)``.
:param consider_constant: a list of expressions not to backpropagate
through
...
...
@@ -441,11 +438,11 @@ def grad(cost, wrt, g_cost=None, consider_constant=None,
# build a dict mapping var to the gradient of cost with respect to var
grad_dict
=
{}
# The gradient of the cost should default to 1 if the cost is of a
# continuous dtype (float, for the moment, as complex are unsupported),
# and should always be 0 if the cost is of discrete (integer) dtype.
# The gradient of the cost is 1 unless specified otherwise by known_grads.
if
cost
is
not
None
:
if
g_cost
is
None
:
if
cost
in
known_grads
:
g_cost
=
known_grads
[
cost
]
else
:
g_cost
=
_float_ones_like
(
cost
)
# g_cost may be Disconnected or NullType. A creative use of the function,
# sure, but nonetheless one we can and should support. So before we try
...
...
@@ -459,10 +456,6 @@ def grad(cost, wrt, g_cost=None, consider_constant=None,
assert
g_cost
not
in
tensor
.
discrete_dtypes
grad_dict
[
cost
]
=
g_cost
else
:
if
g_cost
is
not
None
:
raise
ValueError
(
"No cost node was specified, but a gradient"
" on it was."
)
if
known_grads
is
not
None
:
for
var
in
known_grads
:
...
...
@@ -737,14 +730,12 @@ def _populate_grad_dict(var_to_node_to_idx,
this variable to the variable's index in the apply
node's input list
grad_dict: a dictionary mapping variables to their gradients
should be populated by grad function.
grad should set gradients to DisconnectedType()() for
variables to be considered constant, set the
gradient for the cost variable to g_cost, etc.
both should set the gradient for disconnected
grad_dict: A dictionary mapping variables to their gradients.
Should be populated by grad function, which should:
-Set the gradient with respect to the cost to 1
-Load all gradients from known_grads, possibly overriding
the cost
-Set the gradient for disconnected
inputs to a variable with type DisconnectedType()
wrt: the minimal set of variables that must be included in grad_dict
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论