Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
4deacacd
提交
4deacacd
authored
11月 17, 2022
作者:
Sudarsan Mansingh
提交者:
Ricardo Vieira
11月 26, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Removed CholeskyGrad Op
上级
ab13fe09
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
1 行增加
和
74 行删除
+1
-74
slinalg.py
pytensor/tensor/slinalg.py
+0
-67
test_slinalg.py
tests/tensor/test_slinalg.py
+1
-7
没有找到文件。
pytensor/tensor/slinalg.py
浏览文件 @
4deacacd
...
@@ -129,73 +129,6 @@ class Cholesky(Op):
...
@@ -129,73 +129,6 @@ class Cholesky(Op):
cholesky
=
Cholesky
()
cholesky
=
Cholesky
()
class
CholeskyGrad
(
Op
):
""""""
__props__
=
(
"lower"
,
"destructive"
)
def
__init__
(
self
,
lower
=
True
):
self
.
lower
=
lower
self
.
destructive
=
False
def
make_node
(
self
,
x
,
l
,
dz
):
x
=
as_tensor_variable
(
x
)
l
=
as_tensor_variable
(
l
)
dz
=
as_tensor_variable
(
dz
)
assert
x
.
ndim
==
2
assert
l
.
ndim
==
2
assert
dz
.
ndim
==
2
assert
(
l
.
owner
.
op
.
lower
==
self
.
lower
),
"lower/upper mismatch between Cholesky op and CholeskyGrad op"
return
Apply
(
self
,
[
x
,
l
,
dz
],
[
x
.
type
()])
def
perform
(
self
,
node
,
inputs
,
outputs
):
"""
Implements the "reverse-mode" gradient [#]_ for the
Cholesky factorization of a positive-definite matrix.
References
----------
.. [#] S. P. Smith. "Differentiation of the Cholesky Algorithm".
Journal of Computational and Graphical Statistics,
Vol. 4, No. 2 (Jun.,1995), pp. 134-147
http://www.jstor.org/stable/1390762
"""
x
=
inputs
[
0
]
L
=
inputs
[
1
]
dz
=
inputs
[
2
]
dx
=
outputs
[
0
]
N
=
x
.
shape
[
0
]
if
self
.
lower
:
F
=
np
.
tril
(
dz
)
for
k
in
range
(
N
-
1
,
-
1
,
-
1
):
for
j
in
range
(
k
+
1
,
N
):
for
i
in
range
(
j
,
N
):
F
[
i
,
k
]
-=
F
[
i
,
j
]
*
L
[
j
,
k
]
F
[
j
,
k
]
-=
F
[
i
,
j
]
*
L
[
i
,
k
]
for
j
in
range
(
k
+
1
,
N
):
F
[
j
,
k
]
/=
L
[
k
,
k
]
F
[
k
,
k
]
-=
L
[
j
,
k
]
*
F
[
j
,
k
]
F
[
k
,
k
]
/=
2
*
L
[
k
,
k
]
else
:
F
=
np
.
triu
(
dz
)
for
k
in
range
(
N
-
1
,
-
1
,
-
1
):
for
j
in
range
(
k
+
1
,
N
):
for
i
in
range
(
j
,
N
):
F
[
k
,
i
]
-=
F
[
j
,
i
]
*
L
[
k
,
j
]
F
[
k
,
j
]
-=
F
[
j
,
i
]
*
L
[
k
,
i
]
for
j
in
range
(
k
+
1
,
N
):
F
[
k
,
j
]
/=
L
[
k
,
k
]
F
[
k
,
k
]
-=
L
[
k
,
j
]
*
F
[
k
,
j
]
F
[
k
,
k
]
/=
2
*
L
[
k
,
k
]
dx
[
0
]
=
F
def
infer_shape
(
self
,
fgraph
,
node
,
shapes
):
return
[
shapes
[
0
]]
class
CholeskySolve
(
Op
):
class
CholeskySolve
(
Op
):
__props__
=
(
"lower"
,
"check_finite"
)
__props__
=
(
"lower"
,
"check_finite"
)
...
...
tests/tensor/test_slinalg.py
浏览文件 @
4deacacd
...
@@ -11,7 +11,6 @@ from pytensor import tensor as pt
...
@@ -11,7 +11,6 @@ from pytensor import tensor as pt
from
pytensor.configdefaults
import
config
from
pytensor.configdefaults
import
config
from
pytensor.tensor.slinalg
import
(
from
pytensor.tensor.slinalg
import
(
Cholesky
,
Cholesky
,
CholeskyGrad
,
CholeskySolve
,
CholeskySolve
,
Solve
,
Solve
,
SolveBase
,
SolveBase
,
...
@@ -122,22 +121,17 @@ def test_cholesky_grad_indef():
...
@@ -122,22 +121,17 @@ def test_cholesky_grad_indef():
@pytest.mark.slow
@pytest.mark.slow
def
test_cholesky_
and_cholesky_grad_
shape
():
def
test_cholesky_shape
():
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
rng
=
np
.
random
.
default_rng
(
utt
.
fetch_seed
())
x
=
matrix
()
x
=
matrix
()
for
l
in
(
cholesky
(
x
),
Cholesky
(
lower
=
True
)(
x
),
Cholesky
(
lower
=
False
)(
x
)):
for
l
in
(
cholesky
(
x
),
Cholesky
(
lower
=
True
)(
x
),
Cholesky
(
lower
=
False
)(
x
)):
f_chol
=
pytensor
.
function
([
x
],
l
.
shape
)
f_chol
=
pytensor
.
function
([
x
],
l
.
shape
)
g
=
pytensor
.
gradient
.
grad
(
l
.
sum
(),
x
)
f_cholgrad
=
pytensor
.
function
([
x
],
g
.
shape
)
topo_chol
=
f_chol
.
maker
.
fgraph
.
toposort
()
topo_chol
=
f_chol
.
maker
.
fgraph
.
toposort
()
topo_cholgrad
=
f_cholgrad
.
maker
.
fgraph
.
toposort
()
if
config
.
mode
!=
"FAST_COMPILE"
:
if
config
.
mode
!=
"FAST_COMPILE"
:
assert
sum
(
node
.
op
.
__class__
==
Cholesky
for
node
in
topo_chol
)
==
0
assert
sum
(
node
.
op
.
__class__
==
Cholesky
for
node
in
topo_chol
)
==
0
assert
sum
(
node
.
op
.
__class__
==
CholeskyGrad
for
node
in
topo_cholgrad
)
==
0
for
shp
in
[
2
,
3
,
5
]:
for
shp
in
[
2
,
3
,
5
]:
m
=
np
.
cov
(
rng
.
standard_normal
((
shp
,
shp
+
10
)))
.
astype
(
config
.
floatX
)
m
=
np
.
cov
(
rng
.
standard_normal
((
shp
,
shp
+
10
)))
.
astype
(
config
.
floatX
)
np
.
testing
.
assert_equal
(
f_chol
(
m
),
(
shp
,
shp
))
np
.
testing
.
assert_equal
(
f_chol
(
m
),
(
shp
,
shp
))
np
.
testing
.
assert_equal
(
f_cholgrad
(
m
),
(
shp
,
shp
))
def
test_eigvalsh
():
def
test_eigvalsh
():
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论