Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c2247cd1
提交
c2247cd1
authored
3月 17, 2014
作者:
Nicholas Leonard
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rerenamed hypograph -> subgraph_grad
上级
c1124b59
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
12 行增加
和
12 行删除
+12
-12
basic.txt
doc/library/tensor/basic.txt
+5
-5
__init__.py
theano/__init__.py
+1
-1
gradient.py
theano/gradient.py
+3
-3
test_gradient.py
theano/tests/test_gradient.py
+3
-3
没有找到文件。
doc/library/tensor/basic.txt
浏览文件 @
c2247cd1
...
@@ -1564,7 +1564,7 @@ Gradient / Differentiation
...
@@ -1564,7 +1564,7 @@ Gradient / Differentiation
:rtype: variable or list of variables (matching `wrt`)
:rtype: variable or list of variables (matching `wrt`)
:returns: gradients of the cost with respect to each of the `wrt` terms
:returns: gradients of the cost with respect to each of the `wrt` terms
.. function::
hypo
grad(wrt, end, start=None, cost=None, details=False)
.. function::
subgraph_
grad(wrt, end, start=None, cost=None, details=False)
With respect to `wrt`, computes gradients of cost and/or from existing
With respect to `wrt`, computes gradients of cost and/or from existing
`start` gradients, up to the `end` variables of a symbolic digraph.
`start` gradients, up to the `end` variables of a symbolic digraph.
...
@@ -1578,13 +1578,13 @@ Gradient / Differentiation
...
@@ -1578,13 +1578,13 @@ Gradient / Differentiation
non-differentiable process could be approximated by user-defined
non-differentiable process could be approximated by user-defined
formula, which could be calculated using the gradients of a cost
formula, which could be calculated using the gradients of a cost
with respect to samples (0s and 1s). These gradients are obtained
with respect to samples (0s and 1s). These gradients are obtained
by performing a
hypo
grad from the `cost` or previously known gradients
by performing a
subgraph_
grad from the `cost` or previously known gradients
(`start`) up to the outputs of the stochastic process (`end`).
(`start`) up to the outputs of the stochastic process (`end`).
A dictionary mapping gradients obtained from the user-defined
A dictionary mapping gradients obtained from the user-defined
differentiation of the process, to variables, could then be fed into
differentiation of the process, to variables, could then be fed into
another
hypo
grad as `start` with any other `cost` (e.g. weight decay).
another
subgraph_
grad as `start` with any other `cost` (e.g. weight decay).
In an MLP, we could use
hypo
grad to iteratively backpropagate:
In an MLP, we could use
subgraph_
grad to iteratively backpropagate:
>>> x, t = theano.tensor.fvector('x'), theano.tensor.fvector('t')
>>> x, t = theano.tensor.fvector('x'), theano.tensor.fvector('t')
>>> w1 = theano.shared(np.random.randn(3,4))
>>> w1 = theano.shared(np.random.randn(3,4))
>>> w2 = theano.shared(np.random.randn(4,2))
>>> w2 = theano.shared(np.random.randn(4,2))
...
@@ -1601,7 +1601,7 @@ Gradient / Differentiation
...
@@ -1601,7 +1601,7 @@ Gradient / Differentiation
>>> next_grad = None
>>> next_grad = None
>>> param_grads = []
>>> param_grads = []
>>> for i in xrange(2):
>>> for i in xrange(2):
>>> param_grad, next_grad = theano.
hypo
grad(
>>> param_grad, next_grad = theano.
subgraph_
grad(
>>> wrt=params[i], end=grad_ends[i],
>>> wrt=params[i], end=grad_ends[i],
>>> start=next_grad, cost=costs[i]
>>> start=next_grad, cost=costs[i]
>>> )
>>> )
...
...
theano/__init__.py
浏览文件 @
c2247cd1
...
@@ -79,7 +79,7 @@ from theano.updates import Updates, OrderedUpdates
...
@@ -79,7 +79,7 @@ from theano.updates import Updates, OrderedUpdates
#we don't import by default as we don't want to force having scipy installed.
#we don't import by default as we don't want to force having scipy installed.
#import sparse
#import sparse
from
theano.gradient
import
Rop
,
Lop
,
grad
,
hypo
grad
from
theano.gradient
import
Rop
,
Lop
,
grad
,
subgraph_
grad
if
config
.
device
.
startswith
(
'gpu'
)
or
config
.
init_gpu_device
.
startswith
(
'gpu'
):
if
config
.
device
.
startswith
(
'gpu'
)
or
config
.
init_gpu_device
.
startswith
(
'gpu'
):
import
theano.sandbox.cuda
import
theano.sandbox.cuda
...
...
theano/gradient.py
浏览文件 @
c2247cd1
...
@@ -544,7 +544,7 @@ def grad(cost, wrt, consider_constant=None,
...
@@ -544,7 +544,7 @@ def grad(cost, wrt, consider_constant=None,
rval
,
=
rval
rval
,
=
rval
return
rval
return
rval
def
hypo
grad
(
wrt
,
end
,
start
=
None
,
cost
=
None
,
details
=
False
):
def
subgraph_
grad
(
wrt
,
end
,
start
=
None
,
cost
=
None
,
details
=
False
):
'''
'''
With respect to `wrt`, computes gradients of cost and/or from existing
With respect to `wrt`, computes gradients of cost and/or from existing
`start` gradients, up to the `end` variables of a symbolic digraph.
`start` gradients, up to the `end` variables of a symbolic digraph.
...
@@ -558,11 +558,11 @@ def hypograd(wrt, end, start=None, cost=None, details=False):
...
@@ -558,11 +558,11 @@ def hypograd(wrt, end, start=None, cost=None, details=False):
non-differentiable process could be approximated by user-defined
non-differentiable process could be approximated by user-defined
formula, which could be calculated using the gradients of a cost
formula, which could be calculated using the gradients of a cost
with respect to samples (0s and 1s). These gradients are obtained
with respect to samples (0s and 1s). These gradients are obtained
by performing a
hypo
grad from the `cost` or previously known gradients
by performing a
subgraph_
grad from the `cost` or previously known gradients
(`start`) up to the outputs of the stochastic process (`end`).
(`start`) up to the outputs of the stochastic process (`end`).
A dictionary mapping gradients obtained from the user-defined
A dictionary mapping gradients obtained from the user-defined
differentiation of the process, to variables, could then be fed into
differentiation of the process, to variables, could then be fed into
another
hypo
grad as `start` with any other `cost` (e.g. weight decay).
another
subgraph_
grad as `start` with any other `cost` (e.g. weight decay).
:type wrt : List of Variables.
:type wrt : List of Variables.
Gradients are computed with respect to `wrt`.
Gradients are computed with respect to `wrt`.
...
...
theano/tests/test_gradient.py
浏览文件 @
c2247cd1
...
@@ -555,10 +555,10 @@ def test_disconnected_cost_grad():
...
@@ -555,10 +555,10 @@ def test_disconnected_cost_grad():
return
return
raise
AssertionError
(
"A disconnected gradient has been ignored."
)
raise
AssertionError
(
"A disconnected gradient has been ignored."
)
def
test_
hypo
grad
():
def
test_
subgraph_
grad
():
# Tests that the grad method with no known_grads
# Tests that the grad method with no known_grads
# matches what happens if you use successive
hypo
grads
# matches what happens if you use successive
subgraph_
grads
x
=
theano
.
tensor
.
fvector
(
'x'
)
x
=
theano
.
tensor
.
fvector
(
'x'
)
t
=
theano
.
tensor
.
fvector
(
't'
)
t
=
theano
.
tensor
.
fvector
(
't'
)
...
@@ -588,7 +588,7 @@ def test_hypograd():
...
@@ -588,7 +588,7 @@ def test_hypograd():
next_grad
=
None
next_grad
=
None
param_grads
=
[]
param_grads
=
[]
for
i
in
xrange
(
2
):
for
i
in
xrange
(
2
):
param_grad
,
next_grad
=
theano
.
hypo
grad
(
param_grad
,
next_grad
=
theano
.
subgraph_
grad
(
wrt
=
params
[
i
],
end
=
grad_ends
[
i
],
wrt
=
params
[
i
],
end
=
grad_ends
[
i
],
start
=
next_grad
,
cost
=
costs
[
i
]
start
=
next_grad
,
cost
=
costs
[
i
]
)
)
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论