Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
ad55b69f
Unverified
提交
ad55b69f
authored
3月 04, 2024
作者:
Harshvir Sandhu
提交者:
GitHub
3月 04, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement `tensor.special.logit` helper (#645)
上级
d28a5d0a
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
24 行增加
和
1 行删除
+24
-1
special.py
pytensor/tensor/special.py
+10
-1
test_special.py
tests/tensor/test_special.py
+14
-0
没有找到文件。
pytensor/tensor/special.py
浏览文件 @
ad55b69f
...
@@ -8,7 +8,7 @@ from pytensor.graph.replace import _vectorize_node
...
@@ -8,7 +8,7 @@ from pytensor.graph.replace import _vectorize_node
from
pytensor.link.c.op
import
COp
from
pytensor.link.c.op
import
COp
from
pytensor.tensor.basic
import
as_tensor_variable
from
pytensor.tensor.basic
import
as_tensor_variable
from
pytensor.tensor.elemwise
import
get_normalized_batch_axes
from
pytensor.tensor.elemwise
import
get_normalized_batch_axes
from
pytensor.tensor.math
import
gamma
,
gammaln
,
neg
,
sum
from
pytensor.tensor.math
import
gamma
,
gammaln
,
log
,
neg
,
sum
class
SoftmaxGrad
(
COp
):
class
SoftmaxGrad
(
COp
):
...
@@ -780,6 +780,14 @@ def factorial(n):
...
@@ -780,6 +780,14 @@ def factorial(n):
return
gamma
(
n
+
1
)
return
gamma
(
n
+
1
)
def
logit
(
x
):
"""
Logit function.
"""
return
log
(
x
/
(
1
-
x
))
def
beta
(
a
,
b
):
def
beta
(
a
,
b
):
"""
"""
Beta function.
Beta function.
...
@@ -801,6 +809,7 @@ __all__ = [
...
@@ -801,6 +809,7 @@ __all__ = [
"log_softmax"
,
"log_softmax"
,
"poch"
,
"poch"
,
"factorial"
,
"factorial"
,
"logit"
,
"beta"
,
"beta"
,
"betaln"
,
"betaln"
,
]
]
tests/tensor/test_special.py
浏览文件 @
ad55b69f
...
@@ -3,6 +3,7 @@ import pytest
...
@@ -3,6 +3,7 @@ import pytest
from
scipy.special
import
beta
as
scipy_beta
from
scipy.special
import
beta
as
scipy_beta
from
scipy.special
import
factorial
as
scipy_factorial
from
scipy.special
import
factorial
as
scipy_factorial
from
scipy.special
import
log_softmax
as
scipy_log_softmax
from
scipy.special
import
log_softmax
as
scipy_log_softmax
from
scipy.special
import
logit
as
scipy_logit
from
scipy.special
import
poch
as
scipy_poch
from
scipy.special
import
poch
as
scipy_poch
from
scipy.special
import
softmax
as
scipy_softmax
from
scipy.special
import
softmax
as
scipy_softmax
...
@@ -18,6 +19,7 @@ from pytensor.tensor.special import (
...
@@ -18,6 +19,7 @@ from pytensor.tensor.special import (
betaln
,
betaln
,
factorial
,
factorial
,
log_softmax
,
log_softmax
,
logit
,
poch
,
poch
,
softmax
,
softmax
,
)
)
...
@@ -206,6 +208,18 @@ def test_factorial(n):
...
@@ -206,6 +208,18 @@ def test_factorial(n):
)
)
def
test_logit
():
x
=
vector
(
"x"
)
actual_fn
=
function
([
x
],
logit
(
x
),
allow_input_downcast
=
True
)
x_test
=
np
.
linspace
(
0
,
1
)
actual
=
actual_fn
(
x_test
)
expected
=
scipy_logit
(
x_test
)
np
.
testing
.
assert_allclose
(
actual
,
expected
,
rtol
=
1e-7
if
config
.
floatX
==
"float64"
else
1e-5
)
def
test_beta
():
def
test_beta
():
_a
,
_b
=
vectors
(
"a"
,
"b"
)
_a
,
_b
=
vectors
(
"a"
,
"b"
)
actual_fn
=
function
([
_a
,
_b
],
beta
(
_a
,
_b
))
actual_fn
=
function
([
_a
,
_b
],
beta
(
_a
,
_b
))
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论