Skip to content

Commit 8146a5d

Browse files
authored
Add HalfStudent icdf
1 parent f4c82c1 commit 8146a5d

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

pymc/distributions/continuous.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2834,6 +2834,13 @@ def logp(value, nu, sigma):
28342834
msg="sigma > 0, nu > 0",
28352835
)
28362836

2837+
def icdf(value, nu, sigma):
2838+
# Map half-t quantiles to full StudentT quantiles:
2839+
# F_half^{-1}(u) = F_t^{-1}((u + 1)/2; nu, mu=0, sigma)
2840+
res = icdf(StudentT.dist(nu, sigma=sigma), (value + 1.0) / 2.0)
2841+
res = check_icdf_value(res, value)
2842+
return res
2843+
28372844

28382845
class ExGaussianRV(SymbolicRandomVariable):
28392846
name = "exgaussian"

tests/distributions/test_continuous.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -575,6 +575,13 @@ def test_studentt_icdf(self):
575575
lambda q, nu, mu, sigma: st.t.ppf(q, nu, mu, sigma),
576576
)
577577

578+
def test_halfstudentt_icdf(self):
579+
check_icdf(
580+
pm.HalfStudentT,
581+
{"nu": Rplusbig, "sigma": Rplusbig},
582+
lambda q, nu, sigma: st.t.ppf(0.5 * (q + 1.0), nu, 0.0, sigma),
583+
)
584+
578585
@pytest.mark.skipif(
579586
condition=(pytensor.config.floatX == "float32"),
580587
reason="Fails on float32 due to numerical issues",

0 commit comments

Comments
 (0)