Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e476ebcd
提交
e476ebcd
authored
1月 05, 2022
作者:
Ricardo
提交者:
Brandon T. Willard
1月 05, 2022
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix limit of `log1mexp` gradient at zero and improve numerical precision
上级
cfa867b3
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
18 行增加
和
1 行删除
+18
-1
math.py
aesara/scalar/math.py
+7
-1
test_math.py
tests/tensor/test_math.py
+11
-0
没有找到文件。
aesara/scalar/math.py
浏览文件 @
e476ebcd
...
@@ -20,10 +20,13 @@ from aesara.scalar.basic import (
...
@@ -20,10 +20,13 @@ from aesara.scalar.basic import (
complex_types
,
complex_types
,
discrete_types
,
discrete_types
,
exp
,
exp
,
expm1
,
float64
,
float64
,
float_types
,
float_types
,
isinf
,
log
,
log
,
log1p
,
log1p
,
switch
,
true_div
,
true_div
,
upcast
,
upcast
,
upgrade_to_float
,
upgrade_to_float
,
...
@@ -1201,7 +1204,10 @@ class Log1mexp(UnaryScalarOp):
...
@@ -1201,7 +1204,10 @@ class Log1mexp(UnaryScalarOp):
def
grad
(
self
,
inp
,
grads
):
def
grad
(
self
,
inp
,
grads
):
(
x
,)
=
inp
(
x
,)
=
inp
(
gz
,)
=
grads
(
gz
,)
=
grads
return
[
gz
*
true_div
(
1.0
,
1.0
-
exp
(
-
x
))]
res
=
true_div
(
-
1.0
,
expm1
(
-
x
))
# Correct gradient at 0.0 to be -inf
res
=
switch
(
isinf
(
res
),
-
np
.
inf
,
res
)
return
[
gz
*
res
]
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
def
c_code
(
self
,
node
,
name
,
inp
,
out
,
sub
):
(
x
,)
=
inp
(
x
,)
=
inp
...
...
tests/tensor/test_math.py
浏览文件 @
e476ebcd
...
@@ -74,6 +74,7 @@ from aesara.tensor.math import (
...
@@ -74,6 +74,7 @@ from aesara.tensor.math import (
isnan
,
isnan
,
isnan_
,
isnan_
,
log
,
log
,
log1mexp
,
log1p
,
log1p
,
log2
,
log2
,
log10
,
log10
,
...
@@ -3343,3 +3344,13 @@ def test_pprint():
...
@@ -3343,3 +3344,13 @@ def test_pprint():
x
=
vector
(
"x"
)
x
=
vector
(
"x"
)
y
=
aet_sum
(
x
,
axis
=
0
)
y
=
aet_sum
(
x
,
axis
=
0
)
assert
pprint
(
y
)
==
"sum(x, axis=(0,))"
assert
pprint
(
y
)
==
"sum(x, axis=(0,))"
def
test_log1mexp_grad_lim
():
x
=
dscalar
(
"x"
)
grad_x
=
grad
(
log1mexp
(
x
),
[
x
])[
0
]
grad_x_fn
=
function
([
x
],
grad_x
)
assert
grad_x_fn
(
0.0
)
==
-
np
.
inf
assert
grad_x_fn
(
-
0.0
)
==
-
np
.
inf
assert
grad_x_fn
(
-
1e-309
)
==
-
np
.
inf
assert
grad_x_fn
(
-
1e-308
)
!=
-
np
.
inf
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论