Skip to content

Commit 4bc4946

Browse files
committed
implement more robust t cdf
1 parent c547e6b commit 4bc4946

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

scoringrules/core/stats.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -104,14 +104,9 @@ def _t_pdf(x: "ArrayLike", df: "ArrayLike", backend: "Backend" = None) -> "Array
104104
def _t_cdf(x: "ArrayLike", df: "ArrayLike", backend: "Backend" = None) -> "Array":
105105
"""Cumulative distribution function for the standard Student's t distribution."""
106106
B = backends.active if backend is None else backends[backend]
107-
x_minf = x == float("-inf")
108-
x_inf = x == float("inf")
109-
x = B.where(x_inf, B.nan, x)
110-
s = 1 / 2 + x * B.hypergeometric(1 / 2, (df + 1) / 2, 3 / 2, -(x**2) / df) / (
111-
B.sqrt(df) * B.beta(1 / 2, df / 2)
112-
)
113-
s = B.where(x_minf, 0.0, s)
114-
s = B.where(x_inf, 1.0, s)
107+
t = df / (x**2 + df)
108+
ibeta = B.betainc(df / 2.0, 0.5, t)
109+
s = B.where(x >= 0, 1 - 0.5 * ibeta, 0.5 * ibeta)
115110
return s
116111

117112

0 commit comments

Comments
 (0)