Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
e7ce9fc8
提交
e7ce9fc8
authored
4月 23, 2024
作者:
Ricardo Vieira
提交者:
Ricardo Vieira
5月 29, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
StandandardNormalRV is now just a helper function
上级
aa89e44b
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
11 行增加
和
28 行删除
+11
-28
random.py
pytensor/link/jax/dispatch/random.py
+0
-1
basic.py
pytensor/tensor/random/basic.py
+2
-16
utils.py
pytensor/tensor/random/utils.py
+8
-10
test_utils.py
tests/tensor/random/test_utils.py
+1
-1
没有找到文件。
pytensor/link/jax/dispatch/random.py
浏览文件 @
e7ce9fc8
...
@@ -162,7 +162,6 @@ def jax_sample_fn_generic(op, node):
...
@@ -162,7 +162,6 @@ def jax_sample_fn_generic(op, node):
@jax_sample_fn.register
(
ptr
.
LaplaceRV
)
@jax_sample_fn.register
(
ptr
.
LaplaceRV
)
@jax_sample_fn.register
(
ptr
.
LogisticRV
)
@jax_sample_fn.register
(
ptr
.
LogisticRV
)
@jax_sample_fn.register
(
ptr
.
NormalRV
)
@jax_sample_fn.register
(
ptr
.
NormalRV
)
@jax_sample_fn.register
(
ptr
.
StandardNormalRV
)
def
jax_sample_fn_loc_scale
(
op
,
node
):
def
jax_sample_fn_loc_scale
(
op
,
node
):
"""JAX implementation of random variables in the loc-scale families.
"""JAX implementation of random variables in the loc-scale families.
...
...
pytensor/tensor/random/basic.py
浏览文件 @
e7ce9fc8
...
@@ -281,18 +281,7 @@ class NormalRV(RandomVariable):
...
@@ -281,18 +281,7 @@ class NormalRV(RandomVariable):
normal
=
NormalRV
()
normal
=
NormalRV
()
class
StandardNormalRV
(
NormalRV
):
def
standard_normal
(
*
,
size
=
None
,
rng
=
None
,
dtype
=
None
):
r"""A standard normal continuous random variable.
The probability density function for `standard_normal` is:
.. math::
f(x) = \frac{1}{\sqrt{2 \pi}} e^{-\frac{x^2}{2}}
"""
def
__call__
(
self
,
size
=
None
,
**
kwargs
):
"""Draw samples from a standard normal distribution.
"""Draw samples from a standard normal distribution.
Signature
Signature
...
@@ -309,10 +298,7 @@ class StandardNormalRV(NormalRV):
...
@@ -309,10 +298,7 @@ class StandardNormalRV(NormalRV):
is returned.
is returned.
"""
"""
return
super
()
.
__call__
(
loc
=
0.0
,
scale
=
1.0
,
size
=
size
,
**
kwargs
)
return
normal
(
0.0
,
1.0
,
size
=
size
,
rng
=
rng
,
dtype
=
dtype
)
standard_normal
=
StandardNormalRV
()
class
HalfNormalRV
(
ScipyRandomVariable
):
class
HalfNormalRV
(
ScipyRandomVariable
):
...
...
pytensor/tensor/random/utils.py
浏览文件 @
e7ce9fc8
...
@@ -218,9 +218,9 @@ class RandomStream:
...
@@ -218,9 +218,9 @@ class RandomStream:
if
namespace
is
None
:
if
namespace
is
None
:
from
pytensor.tensor.random
import
basic
# pylint: disable=import-self
from
pytensor.tensor.random
import
basic
# pylint: disable=import-self
self
.
namespaces
=
[
basic
]
self
.
namespaces
=
[
(
basic
,
set
(
basic
.
__all__
))
]
else
:
else
:
self
.
namespaces
=
[
namespace
]
self
.
namespaces
=
[
(
namespace
,
set
(
namespace
.
__all__
))
]
self
.
default_instance_seed
=
seed
self
.
default_instance_seed
=
seed
self
.
state_updates
=
[]
self
.
state_updates
=
[]
...
@@ -235,23 +235,21 @@ class RandomStream:
...
@@ -235,23 +235,21 @@ class RandomStream:
def
__getattr__
(
self
,
obj
):
def
__getattr__
(
self
,
obj
):
ns_obj
=
next
(
ns_obj
=
next
(
(
getattr
(
ns
,
obj
)
for
ns
in
self
.
namespaces
if
hasattr
(
ns
,
obj
)),
None
(
getattr
(
ns
,
obj
)
for
ns
,
all_
in
self
.
namespaces
if
obj
in
all_
and
hasattr
(
ns
,
obj
)
),
None
,
)
)
if
ns_obj
is
None
:
if
ns_obj
is
None
:
raise
AttributeError
(
f
"No attribute {obj}."
)
raise
AttributeError
(
f
"No attribute {obj}."
)
from
pytensor.tensor.random.op
import
RandomVariable
if
isinstance
(
ns_obj
,
RandomVariable
):
@wraps
(
ns_obj
)
@wraps
(
ns_obj
)
def
meta_obj
(
*
args
,
**
kwargs
):
def
meta_obj
(
*
args
,
**
kwargs
):
return
self
.
gen
(
ns_obj
,
*
args
,
**
kwargs
)
return
self
.
gen
(
ns_obj
,
*
args
,
**
kwargs
)
else
:
raise
AttributeError
(
f
"No attribute {obj}."
)
setattr
(
self
,
obj
,
meta_obj
)
setattr
(
self
,
obj
,
meta_obj
)
return
getattr
(
self
,
obj
)
return
getattr
(
self
,
obj
)
...
...
tests/tensor/random/test_utils.py
浏览文件 @
e7ce9fc8
...
@@ -114,7 +114,7 @@ class TestSharedRandomStream:
...
@@ -114,7 +114,7 @@ class TestSharedRandomStream:
assert
hasattr
(
random
,
"standard_normal"
)
assert
hasattr
(
random
,
"standard_normal"
)
with
pytest
.
raises
(
AttributeError
):
with
pytest
.
raises
(
AttributeError
):
np_random
=
RandomStream
(
namespace
=
np
,
rng_ctor
=
rng_ctor
)
np_random
=
RandomStream
(
namespace
=
np
.
random
,
rng_ctor
=
rng_ctor
)
np_random
.
ndarray
np_random
.
ndarray
fn
=
function
([],
random
.
uniform
(
0
,
1
,
size
=
(
2
,
2
)),
updates
=
random
.
updates
())
fn
=
function
([],
random
.
uniform
(
0
,
1
,
size
=
(
2
,
2
)),
updates
=
random
.
updates
())
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论