Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
c40d6924
提交
c40d6924
authored
5月 06, 2024
作者:
Dhruvanshu-Joshi
提交者:
Thomas Wiecki
5月 10, 2024
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement Rayleigh distribution in Pytensor
上级
82a57574
显示空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
53 行增加
和
0 行删除
+53
-0
basic.py
pytensor/tensor/random/basic.py
+38
-0
test_basic.py
tests/tensor/random/test_basic.py
+15
-0
没有找到文件。
pytensor/tensor/random/basic.py
浏览文件 @
c40d6924
...
@@ -6,6 +6,7 @@ import scipy.stats as stats
...
@@ -6,6 +6,7 @@ import scipy.stats as stats
import
pytensor
import
pytensor
from
pytensor.tensor.basic
import
arange
,
as_tensor_variable
from
pytensor.tensor.basic
import
arange
,
as_tensor_variable
from
pytensor.tensor.math
import
sqrt
from
pytensor.tensor.random.op
import
RandomVariable
from
pytensor.tensor.random.op
import
RandomVariable
from
pytensor.tensor.random.type
import
RandomGeneratorType
,
RandomStateType
from
pytensor.tensor.random.type
import
RandomGeneratorType
,
RandomStateType
from
pytensor.tensor.random.utils
import
(
from
pytensor.tensor.random.utils
import
(
...
@@ -526,6 +527,43 @@ def chisquare(df, size=None, **kwargs):
...
@@ -526,6 +527,43 @@ def chisquare(df, size=None, **kwargs):
return
gamma
(
shape
=
df
/
2.0
,
scale
=
2.0
,
size
=
size
,
**
kwargs
)
return
gamma
(
shape
=
df
/
2.0
,
scale
=
2.0
,
size
=
size
,
**
kwargs
)
def
rayleigh
(
scale
=
1.0
,
*
,
size
=
None
,
**
kwargs
):
r"""Draw samples from a Rayleigh distribution.
The probability density function for `rayleigh` with parameter `scale` is given by:
.. math::
f(x; s) = \frac{x}{s^2} e^{-x^2/(2 s^2)}
where :math:`s` is the scale parameter.
This variable is obtained by taking the square root of the sum of the squares of
two independent, standard normally distributed random variables.
Signature
---------
`() -> ()`
Parameters
----------
scale : float or array_like of floats, optional
Scale parameter of the distribution (positive). Default is 1.0.
size : int or tuple of ints, optional
Output shape. If the given shape is, e.g., `(m, n, k)`, then `m * n * k` samples
are drawn. Default is None, in which case the output shape is determined by the
shape of `scale`.
Notes
-----
`Rayleigh` is a special case of `chisquare` with ``df=2``.
"""
scale
=
as_tensor_variable
(
scale
)
if
size
is
None
:
size
=
scale
.
shape
return
sqrt
(
chisquare
(
df
=
2
,
size
=
size
,
**
kwargs
))
*
scale
class
ParetoRV
(
ScipyRandomVariable
):
class
ParetoRV
(
ScipyRandomVariable
):
r"""A pareto continuous random variable.
r"""A pareto continuous random variable.
...
...
tests/tensor/random/test_basic.py
浏览文件 @
c40d6924
...
@@ -50,6 +50,7 @@ from pytensor.tensor.random.basic import (
...
@@ -50,6 +50,7 @@ from pytensor.tensor.random.basic import (
permutation
,
permutation
,
poisson
,
poisson
,
randint
,
randint
,
rayleigh
,
standard_normal
,
standard_normal
,
t
,
t
,
triangular
,
triangular
,
...
@@ -390,6 +391,20 @@ def test_chisquare_samples(df, size):
...
@@ -390,6 +391,20 @@ def test_chisquare_samples(df, size):
compare_sample_values
(
chisquare
,
df
,
size
=
size
,
test_fn
=
fixed_scipy_rvs
(
"chi2"
))
compare_sample_values
(
chisquare
,
df
,
size
=
size
,
test_fn
=
fixed_scipy_rvs
(
"chi2"
))
@pytest.mark.parametrize
(
"scale, size"
,
[
(
1
,
None
),
(
2
,
[]),
(
4
,
100
),
],
)
def
test_rayleigh_samples
(
scale
,
size
):
compare_sample_values
(
rayleigh
,
scale
=
scale
,
size
=
size
,
test_fn
=
fixed_scipy_rvs
(
"rayleigh"
)
)
@pytest.mark.parametrize
(
@pytest.mark.parametrize
(
"mu, beta, size"
,
"mu, beta, size"
,
[
[
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论