Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix finite support bug due to changes in scipy.special.factorial2 #146

Merged
merged 1 commit into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions KDEpy/kernel_funcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,17 @@ def gauss_integral(n):
True
"""
factor = np.sqrt(np.pi * 2)
if n % 2 == 0:

# Special case:
# factorial2(-1) used to return 1
# but now it returns 0
# https://github.com/scipy/scipy/pull/15841
# https://github.com/tommyod/KDEpy/issues/145
if n == 0:
return factor * factorial2(n - 0) / 2

# Normal cases
elif n % 2 == 0:
return factor * factorial2(n - 1) / 2
elif n % 2 == 1:
return factor * norm.pdf(0) * factorial2(n - 1)
Expand Down Expand Up @@ -264,6 +274,14 @@ def practical_support(self, bw, atol=10e-5):
"""
Return the support for practical purposes. Used to find a support value
for computations for kernel functions without finite (bounded) support.

Examples
--------
>>> kernel = Kernel(gaussian, var=1, support=np.inf)
>>> kernel.practical_support(bw=1)
3.8994...
>>> kernel.practical_support(bw=2)
7.4331...
"""
# If the kernel has finite support, return the support accounting for
# the bw
Expand Down Expand Up @@ -353,8 +371,8 @@ def evaluate(self, x, bw=1, norm=2):
}


if __name__ == "__main__" and False:
if __name__ == "__main__":
import pytest

# --durations=10 <- May be used to show potentially slow tests
pytest.main(args=[".", "--doctest-modules", "-v"])
pytest.main(args=[__file__, "--doctest-modules", "-v"])
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[project]
name = "KDEpy"
version = "1.1.3"
version = "1.1.4"
dependencies = [
"numpy>=1.14.2",
"scipy>=1.0.1",
Expand Down
Loading