提交 95ce102d authored 作者: Aarsh-Wankar's avatar Aarsh-Wankar 提交者: Ricardo Vieira

Add kn function as helper for modified Bessel function of the second kind and corresponding tests

上级 b75c18fe
...@@ -2453,6 +2453,11 @@ def kv(v, x): ...@@ -2453,6 +2453,11 @@ def kv(v, x):
return kve(v, x) * exp(-x) return kve(v, x) * exp(-x)
def kn(n, x):
"""Modified Bessel function of the second kind of integer order v."""
return kv(n, x)
@scalar_elemwise @scalar_elemwise
def sigmoid(x): def sigmoid(x):
"""Logistic sigmoid function (1 / (1 + exp(-x)), also known as expit or inverse logit""" """Logistic sigmoid function (1 / (1 + exp(-x)), also known as expit or inverse logit"""
...@@ -4337,6 +4342,7 @@ __all__ = [ ...@@ -4337,6 +4342,7 @@ __all__ = [
"i1", "i1",
"iv", "iv",
"ive", "ive",
"kn",
"kv", "kv",
"kve", "kve",
"sigmoid", "sigmoid",
......
...@@ -18,7 +18,7 @@ from pytensor import function, grad ...@@ -18,7 +18,7 @@ from pytensor import function, grad
from pytensor import tensor as pt from pytensor import tensor as pt
from pytensor.compile.mode import get_default_mode from pytensor.compile.mode import get_default_mode
from pytensor.configdefaults import config from pytensor.configdefaults import config
from pytensor.tensor import gammaincc, inplace, kv, kve, vector from pytensor.tensor import gammaincc, inplace, kn, kv, kve, vector
from tests import unittest_tools as utt from tests import unittest_tools as utt
from tests.tensor.utils import ( from tests.tensor.utils import (
_good_broadcast_unary_chi2sf, _good_broadcast_unary_chi2sf,
...@@ -1220,3 +1220,17 @@ def test_kv(): ...@@ -1220,3 +1220,17 @@ def test_kv():
out.eval({v: test_v, x: test_x}), out.eval({v: test_v, x: test_x}),
scipy.special.kv(test_v[:, None], test_x[None, :]), scipy.special.kv(test_v[:, None], test_x[None, :]),
) )
def test_kn():
n = vector("n")
x = vector("x")
out = kn(n[:, None], x[None, :])
test_n = np.array([-3, 4, 0, 5], dtype=n.type.dtype)
test_x = np.linspace(0, 512, 10, dtype=x.type.dtype)
np.testing.assert_allclose(
out.eval({n: test_n, x: test_x}),
scipy.special.kn(test_n[:, None], test_x[None, :]),
)
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论