Skip to content
项目
群组
代码片段
帮助
当前项目
正在载入...
登录 / 注册
切换导航面板
P
pytensor
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
图表
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
图像
聊天
创建新问题
作业
提交
问题看板
Open sidebar
testgroup
pytensor
Commits
902eeb6f
Unverified
提交
902eeb6f
authored
11月 15, 2023
作者:
Will Dean
提交者:
GitHub
11月 15, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Implement ChiSquare via Gamma (#490)
上级
9653ade1
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
3 行增加
和
39 行删除
+3
-39
basic.rst
doc/library/tensor/random/basic.rst
+0
-3
random.py
pytensor/link/numba/dispatch/random.py
+0
-1
basic.py
pytensor/tensor/random/basic.py
+3
-22
jax.py
pytensor/tensor/random/rewriting/jax.py
+0
-13
没有找到文件。
doc/library/tensor/random/basic.rst
浏览文件 @
902eeb6f
...
@@ -82,9 +82,6 @@ PyTensor can produce :class:`RandomVariable`\s that draw samples from many diffe
...
@@ -82,9 +82,6 @@ PyTensor can produce :class:`RandomVariable`\s that draw samples from many diffe
.. autoclass:: pytensor.tensor.random.basic.CategoricalRV
.. autoclass:: pytensor.tensor.random.basic.CategoricalRV
:members: __call__
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.ChiSquareRV
:members: __call__
.. autoclass:: pytensor.tensor.random.basic.DirichletRV
.. autoclass:: pytensor.tensor.random.basic.DirichletRV
:members: __call__
:members: __call__
...
...
pytensor/link/numba/dispatch/random.py
浏览文件 @
902eeb6f
...
@@ -195,7 +195,6 @@ def {sized_fn_name}({random_fn_input_names}):
...
@@ -195,7 +195,6 @@ def {sized_fn_name}({random_fn_input_names}):
@numba_funcify.register
(
aer
.
NormalRV
)
@numba_funcify.register
(
aer
.
NormalRV
)
@numba_funcify.register
(
aer
.
LogNormalRV
)
@numba_funcify.register
(
aer
.
LogNormalRV
)
@numba_funcify.register
(
aer
.
GammaRV
)
@numba_funcify.register
(
aer
.
GammaRV
)
@numba_funcify.register
(
aer
.
ChiSquareRV
)
@numba_funcify.register
(
aer
.
ParetoRV
)
@numba_funcify.register
(
aer
.
ParetoRV
)
@numba_funcify.register
(
aer
.
GumbelRV
)
@numba_funcify.register
(
aer
.
GumbelRV
)
@numba_funcify.register
(
aer
.
ExponentialRV
)
@numba_funcify.register
(
aer
.
ExponentialRV
)
...
...
pytensor/tensor/random/basic.py
浏览文件 @
902eeb6f
...
@@ -487,39 +487,24 @@ def gamma(shape, rate=None, scale=None, **kwargs):
...
@@ -487,39 +487,24 @@ def gamma(shape, rate=None, scale=None, **kwargs):
return
_gamma
(
shape
,
scale
,
**
kwargs
)
return
_gamma
(
shape
,
scale
,
**
kwargs
)
class
ChiSquareRV
(
RandomVariable
):
def
chisquare
(
df
,
size
=
None
,
**
kwargs
):
r"""
A chi square continuous random variable
.
r"""
Draw samples from a chisquare distribution
.
The probability density function for `chisquare` in terms of the number of degrees of
The probability density function for `chisquare` in terms of the number of degrees of
freedom :math:`k` is:
freedom :math:`k` is:
.. math::
.. math::
f(x; k) = \frac{(1/2)^{k/2}}{\Gamma(k/2)} x^{k/2-1} e^{-x/2}
f(x; k) = \frac{(1/2)^{k/2}}{\Gamma(k/2)} x^{k/2-1} e^{-x/2}
for :math:`k > 2`. :math:`\Gamma` is the gamma function:
for :math:`k > 2`. :math:`\Gamma` is the gamma function:
.. math::
.. math::
\Gamma(x) = \int_0^{\infty} t^{x-1} e^{-t} \mathrm{d}t
\Gamma(x) = \int_0^{\infty} t^{x-1} e^{-t} \mathrm{d}t
This variable is obtained by summing the squares :math:`k` independent, standard normally
This variable is obtained by summing the squares :math:`k` independent, standard normally
distributed random variables.
distributed random variables.
"""
name
=
"chisquare"
ndim_supp
=
0
ndims_params
=
[
0
]
dtype
=
"floatX"
_print_name
=
(
"ChiSquare"
,
"
\\
operatorname{ChiSquare}"
)
def
__call__
(
self
,
df
,
size
=
None
,
**
kwargs
):
r"""Draw samples from a chisquare distribution.
Signature
Signature
---------
---------
`() -> ()`
`() -> ()`
Parameters
Parameters
...
@@ -531,12 +516,8 @@ class ChiSquareRV(RandomVariable):
...
@@ -531,12 +516,8 @@ class ChiSquareRV(RandomVariable):
independent, identically distributed random variables are
independent, identically distributed random variables are
returned. Default is `None` in which case a single random variable
returned. Default is `None` in which case a single random variable
is returned.
is returned.
"""
"""
return
super
()
.
__call__
(
df
,
size
=
size
,
**
kwargs
)
return
gamma
(
shape
=
df
/
2.0
,
scale
=
2.0
,
size
=
size
,
**
kwargs
)
chisquare
=
ChiSquareRV
()
class
ParetoRV
(
ScipyRandomVariable
):
class
ParetoRV
(
ScipyRandomVariable
):
...
...
pytensor/tensor/random/rewriting/jax.py
浏览文件 @
902eeb6f
...
@@ -7,7 +7,6 @@ from pytensor.tensor.basic import MakeVector, cast, ones_like, switch, zeros_lik
...
@@ -7,7 +7,6 @@ from pytensor.tensor.basic import MakeVector, cast, ones_like, switch, zeros_lik
from
pytensor.tensor.elemwise
import
DimShuffle
from
pytensor.tensor.elemwise
import
DimShuffle
from
pytensor.tensor.random.basic
import
(
from
pytensor.tensor.random.basic
import
(
BetaBinomialRV
,
BetaBinomialRV
,
ChiSquareRV
,
GenGammaRV
,
GenGammaRV
,
GeometricRV
,
GeometricRV
,
HalfNormalRV
,
HalfNormalRV
,
...
@@ -104,13 +103,6 @@ def inverse_gamma_from_gamma(fgraph, node):
...
@@ -104,13 +103,6 @@ def inverse_gamma_from_gamma(fgraph, node):
return
[
next_rng
,
reciprocal
(
g
)]
return
[
next_rng
,
reciprocal
(
g
)]
@node_rewriter
([
ChiSquareRV
])
def
chi_square_from_gamma
(
fgraph
,
node
):
*
other_inputs
,
df
=
node
.
inputs
next_rng
,
g
=
_gamma
.
make_node
(
*
other_inputs
,
df
/
2
,
2
)
.
outputs
return
[
next_rng
,
g
]
@node_rewriter
([
GenGammaRV
])
@node_rewriter
([
GenGammaRV
])
def
generalized_gamma_from_gamma
(
fgraph
,
node
):
def
generalized_gamma_from_gamma
(
fgraph
,
node
):
*
other_inputs
,
alpha
,
p
,
lambd
=
node
.
inputs
*
other_inputs
,
alpha
,
p
,
lambd
=
node
.
inputs
...
@@ -171,11 +163,6 @@ random_vars_opt.register(
...
@@ -171,11 +163,6 @@ random_vars_opt.register(
in2out
(
inverse_gamma_from_gamma
),
in2out
(
inverse_gamma_from_gamma
),
"jax"
,
"jax"
,
)
)
random_vars_opt
.
register
(
"chi_square_from_gamma"
,
in2out
(
chi_square_from_gamma
),
"jax"
,
)
random_vars_opt
.
register
(
random_vars_opt
.
register
(
"generalized_gamma_from_gamma"
,
"generalized_gamma_from_gamma"
,
in2out
(
generalized_gamma_from_gamma
),
in2out
(
generalized_gamma_from_gamma
),
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论