Skip to content

Commit fa82fef

Browse files
Fix bug in random function of HalfStudent (#6658)
Co-authored-by: Ricardo Vieira <[email protected]>
1 parent 2a324bc commit fa82fef

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

pymc/distributions/continuous.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2502,7 +2502,7 @@ class HalfStudentTRV(RandomVariable):
25022502

25032503
@classmethod
25042504
def rng_fn(cls, rng, nu, sigma, size=None) -> np.ndarray:
2505-
return np.asarray(np.abs(stats.t.rvs(nu, sigma, size=size, random_state=rng)))
2505+
return np.asarray(np.abs(stats.t.rvs(nu, scale=sigma, size=size, random_state=rng)))
25062506

25072507

25082508
halfstudentt = HalfStudentTRV()

tests/distributions/test_continuous.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,22 @@ class TestStudentT(BaseTestDistributionRandom):
17491749
]
17501750

17511751

1752+
class TestHalfStudentT(BaseTestDistributionRandom):
1753+
def halfstudentt_rng_fn(self, df, loc, scale, size, rng):
1754+
return np.abs(st.t.rvs(df=df, loc=loc, scale=scale, size=size))
1755+
1756+
pymc_dist = pm.HalfStudentT
1757+
pymc_dist_params = {"nu": 5.0, "sigma": 2.0}
1758+
expected_rv_op_params = {"nu": 5.0, "sigma": 2.0}
1759+
reference_dist_params = {"df": 5.0, "loc": 0, "scale": 2.0}
1760+
reference_dist = lambda self: ft.partial(self.halfstudentt_rng_fn, rng=self.get_random_state())
1761+
checks_to_run = [
1762+
"check_pymc_params_match_rv_op",
1763+
"check_pymc_draws_match_reference",
1764+
"check_rv_size",
1765+
]
1766+
1767+
17521768
class TestMoyal(BaseTestDistributionRandom):
17531769
pymc_dist = pm.Moyal
17541770
pymc_dist_params = {"mu": 0.0, "sigma": 1.0}

0 commit comments

Comments
 (0)