Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
940bd5a8
提交
940bd5a8
authored
11月 10, 2012
作者:
abalkin
提交者:
Frederic
11月 28, 2012
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implemented linalg.eigh.
上级
7e3caf1e
隐藏空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
28 行增加
和
17 行删除
+28
-17
__init__.py
theano/sandbox/linalg/__init__.py
+1
-1
ops.py
theano/sandbox/linalg/ops.py
+18
-6
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+9
-10
没有找到文件。
theano/sandbox/linalg/__init__.py
浏览文件 @
940bd5a8
from
ops
import
(
cholesky
,
matrix_inverse
,
solve
,
diag
,
extract_diag
,
alloc_diag
,
det
,
psd
,
eig
,
det
,
psd
,
eig
,
eigh
,
trace
,
spectral_radius_bound
)
theano/sandbox/linalg/ops.py
浏览文件 @
940bd5a8
...
...
@@ -882,8 +882,8 @@ class Eig(Op):
"""
def
__init__
(
self
):
pass
def
__init__
(
self
,
numop
):
self
.
_numop
=
numop
def
props
(
self
):
"""Function exposing different properties of each instance of the
...
...
@@ -907,9 +907,10 @@ class Eig(Op):
def
perform
(
self
,
node
,
(
x
,),
(
w
,
v
)):
try
:
w
[
0
],
v
[
0
]
=
[
z
.
astype
(
x
.
dtype
)
for
z
in
numpy
.
linalg
.
eig
(
x
)]
w
[
0
],
v
[
0
]
=
[
z
.
astype
(
x
.
dtype
)
for
z
in
self
.
_numop
(
x
)]
except
numpy
.
linalg
.
LinAlgError
:
logger
.
debug
(
'Failed to find eig of
%
s'
%
str
(
node
.
inputs
[
0
]))
logger
.
debug
(
'Failed to find
%
s of
%
s'
%
(
node
.
inputs
[
0
],
self
.
_numop
.
__name__
))
raise
def
infer_shape
(
self
,
node
,
shapes
):
...
...
@@ -917,7 +918,7 @@ class Eig(Op):
return
[(
n
,),
(
n
,
n
)]
def
__str__
(
self
):
return
"Eig"
return
self
.
_numop
.
__name__
.
capitalize
()
def
grad
(
self
,
inputs
,
g_outputs
):
r"""The gradient function should return
...
...
@@ -943,7 +944,8 @@ class Eig(Op):
gw
,
gv
=
g_outputs
return
[
EigGrad
()(
x
,
w
,
v
,
gw
,
gv
)]
eig
=
Eig
()
eig
=
Eig
(
numpy
.
linalg
.
eig
)
eigh
=
Eig
(
numpy
.
linalg
.
eigh
)
class
EigGrad
(
Op
):
"""Gradient of an eigensystem.
...
...
@@ -968,6 +970,16 @@ class EigGrad(Op):
def
perform
(
self
,
node
,
inputs
,
outputs
):
"""
Implements the "reverse-mode" gradient for the eigensystem of
a square matrix.
Let
.. math:: w, v =
\
mbox{eig}(x).
By definition of the eigensystem,
.. math::
\
sum_j x_{ij}
\
,v_{jn} = w_n
\
,v_{in}.
"""
x
,
w
,
v
,
gw
,
gv
=
inputs
N
=
x
.
shape
[
0
]
...
...
theano/sandbox/linalg/tests/test_linalg.py
浏览文件 @
940bd5a8
...
...
@@ -29,7 +29,7 @@ from theano.sandbox.linalg.ops import (cholesky,
imported_scipy
,
Eig
,
)
from
theano.sandbox.linalg
import
eig
from
theano.sandbox.linalg
import
eig
,
eigh
from
nose.plugins.skip
import
SkipTest
...
...
@@ -471,10 +471,10 @@ class test_Solve(utt.InferShapeTester):
self
.
op_class
)
class
test_Eig
(
utt
.
InferShapeTester
):
op_class
=
Eig
op
=
eig
def
setUp
(
self
):
super
(
test_Eig
,
self
)
.
setUp
()
self
.
op_class
=
Eig
self
.
op
=
Eig
()
self
.
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
self
.
A
=
theano
.
tensor
.
matrix
()
X
=
numpy
.
asarray
(
self
.
rng
.
rand
(
5
,
5
),
...
...
@@ -494,16 +494,15 @@ class test_Eig(utt.InferShapeTester):
A
=
theano
.
tensor
.
matrix
()
self
.
assertEquals
([
e
.
eval
({
A
:
[[
1
]]})
for
e
in
self
.
op
(
A
)],
[[
1.0
],
[[
1.0
]]])
x
=
[[
0
,
1
],
[
1
,
0
]]
w
,
v
=
[
e
.
eval
({
A
:
x
})
for
e
in
self
.
op
(
A
)]
assert_array_almost_equal
(
numpy
.
dot
(
x
,
v
),
w
*
v
)
w
,
v
=
[
e
.
eval
({
A
:
[[
0
,
1
],
[
1
,
0
]]})
for
e
in
self
.
op
(
A
)]
assert_array_almost_equal
(
w
,
[
1
,
-
1
])
x
=
math
.
sqrt
(
2
)
/
2
assert_array_almost_equal
(
v
,
[[
x
,
-
x
],
[
x
,
x
]])
class
test_Eigh
(
test_Eig
):
op
=
eigh
def
test_grad
(
self
):
S
=
self
.
S
def
fun
(
x
):
w
,
v
=
eig
(
x
)
w
,
v
=
self
.
op
(
x
)
return
w
.
sum
()
+
v
.
sum
()
*
0
utt
.
verify_grad
(
fun
,
[
S
],
rng
=
self
.
rng
)
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论