Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
bdee7c76
提交
bdee7c76
authored
11月 11, 2011
作者:
nouiz
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #201 from hamelphi/det_test_and_doc/master
det OP
上级
dba5815e
8c270d71
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
26 行增加
和
16 行删除
+26
-16
ops.py
theano/sandbox/linalg/ops.py
+9
-4
test_linalg.py
theano/sandbox/linalg/tests/test_linalg.py
+17
-12
没有找到文件。
theano/sandbox/linalg/ops.py
浏览文件 @
bdee7c76
...
@@ -548,24 +548,29 @@ def diag(x):
...
@@ -548,24 +548,29 @@ def diag(x):
raise
TypeError
(
'diag requires vector or matrix argument'
,
x
)
raise
TypeError
(
'diag requires vector or matrix argument'
,
x
)
class
Det
(
Op
):
class
Det
(
Op
):
"""matrix determinant
"""Matrix determinant
Input should be a square matrix
TODO: move this op to another file that request scipy.
"""
"""
def
make_node
(
self
,
x
):
def
make_node
(
self
,
x
):
x
=
as_tensor_variable
(
x
)
x
=
as_tensor_variable
(
x
)
o
=
theano
.
tensor
.
scalar
(
dtype
=
x
.
dtype
)
o
=
theano
.
tensor
.
scalar
(
dtype
=
x
.
dtype
)
return
Apply
(
self
,
[
x
],
[
o
])
return
Apply
(
self
,
[
x
],
[
o
])
def
perform
(
self
,
node
,
(
x
,),
(
z
,
)):
def
perform
(
self
,
node
,
(
x
,),
(
z
,
)):
try
:
try
:
z
[
0
]
=
numpy
.
asarray
(
sci
py
.
linalg
.
det
(
x
),
dtype
=
x
.
dtype
)
z
[
0
]
=
numpy
.
asarray
(
num
py
.
linalg
.
det
(
x
),
dtype
=
x
.
dtype
)
except
Exception
:
except
Exception
:
print
'Failed to compute determinant'
,
x
print
'Failed to compute determinant'
,
x
raise
raise
def
grad
(
self
,
inputs
,
g_outputs
):
def
grad
(
self
,
inputs
,
g_outputs
):
gz
,
=
g_outputs
gz
,
=
g_outputs
x
,
=
inputs
x
,
=
inputs
return
[
gz
*
self
(
x
)
*
matrix_inverse
(
x
)
.
T
]
return
[
gz
*
self
(
x
)
*
matrix_inverse
(
x
)
.
T
]
def
infer_shape
(
self
,
node
,
shapes
):
return
[()]
def
__str__
(
self
):
def
__str__
(
self
):
return
"Det"
return
"Det"
det
=
Det
()
det
=
Det
()
...
...
theano/sandbox/linalg/tests/test_linalg.py
浏览文件 @
bdee7c76
...
@@ -9,14 +9,6 @@ from theano.tensor.tests.test_rop import break_op
...
@@ -9,14 +9,6 @@ from theano.tensor.tests.test_rop import break_op
from
theano.tests
import
unittest_tools
as
utt
from
theano.tests
import
unittest_tools
as
utt
from
theano
import
config
from
theano
import
config
try
:
import
scipy
if
V
(
scipy
.
__version__
)
<
V
(
'0.7'
):
raise
ImportError
()
use_scipy
=
True
except
ImportError
:
use_scipy
=
False
# The one in comment are not tested...
# The one in comment are not tested...
from
theano.sandbox.linalg.ops
import
(
cholesky
,
from
theano.sandbox.linalg.ops
import
(
cholesky
,
matrix_inverse
,
matrix_inverse
,
...
@@ -166,15 +158,28 @@ def test_rop_lop():
...
@@ -166,15 +158,28 @@ def test_rop_lop():
assert
_allclose
(
v1
,
v2
),
(
'LOP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
assert
_allclose
(
v1
,
v2
),
(
'LOP mismatch:
%
s
%
s'
%
(
v1
,
v2
))
def
test_det
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
5
,
5
)
x
=
tensor
.
matrix
()
f
=
theano
.
function
([
x
],
det
(
x
))
assert
numpy
.
linalg
.
det
(
r
)
==
f
(
r
)
def
test_det_grad
():
def
test_det_grad
():
# If scipy is not available, this test will fail, thus we skip it.
if
not
use_scipy
:
raise
SkipTest
(
'Scipy is not available'
)
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
5
,
5
)
r
=
rng
.
randn
(
5
,
5
)
tensor
.
verify_grad
(
det
,
[
r
],
rng
=
numpy
.
random
)
tensor
.
verify_grad
(
det
,
[
r
],
rng
=
numpy
.
random
)
def
test_det_shape
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
r
=
rng
.
randn
(
5
,
5
)
x
=
tensor
.
matrix
()
f
=
theano
.
function
([
x
],
det
(
x
))
f_shape
=
theano
.
function
([
x
],
det
(
x
)
.
shape
)
assert
numpy
.
all
(
f
(
r
)
.
shape
==
f_shape
(
r
))
def
test_extract_diag
():
def
test_extract_diag
():
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
rng
=
numpy
.
random
.
RandomState
(
utt
.
fetch_seed
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论