test_discrete_basic.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545
  1. import numpy.testing as npt
  2. from numpy.testing import assert_allclose
  3. import numpy as np
  4. import pytest
  5. from scipy import stats
  6. from .common_tests import (check_normalization, check_moment, check_mean_expect,
  7. check_var_expect, check_skew_expect,
  8. check_kurt_expect, check_entropy,
  9. check_private_entropy, check_edge_support,
  10. check_named_args, check_random_state_property,
  11. check_pickling, check_rvs_broadcast, check_freezing,
  12. check_deprecation_warning_gh5982_moment,
  13. check_deprecation_warning_gh5982_interval)
  14. from scipy.stats._distr_params import distdiscrete, invdistdiscrete
  15. from scipy.stats._distn_infrastructure import rv_discrete_frozen
  16. vals = ([1, 2, 3, 4], [0.1, 0.2, 0.3, 0.4])
  17. distdiscrete += [[stats.rv_discrete(values=vals), ()]]
  18. # For these distributions, test_discrete_basic only runs with test mode full
  19. distslow = {'zipfian', 'nhypergeom'}
  20. def cases_test_discrete_basic():
  21. seen = set()
  22. for distname, arg in distdiscrete:
  23. if distname in distslow:
  24. yield pytest.param(distname, arg, distname, marks=pytest.mark.slow)
  25. else:
  26. yield distname, arg, distname not in seen
  27. seen.add(distname)
  28. @pytest.mark.filterwarnings('ignore::RuntimeWarning')
  29. @pytest.mark.parametrize('distname,arg,first_case', cases_test_discrete_basic())
  30. def test_discrete_basic(distname, arg, first_case):
  31. try:
  32. distfn = getattr(stats, distname)
  33. except TypeError:
  34. distfn = distname
  35. distname = 'sample distribution'
  36. np.random.seed(9765456)
  37. rvs = distfn.rvs(size=2000, *arg)
  38. supp = np.unique(rvs)
  39. m, v = distfn.stats(*arg)
  40. check_cdf_ppf(distfn, arg, supp, distname + ' cdf_ppf')
  41. check_pmf_cdf(distfn, arg, distname)
  42. check_oth(distfn, arg, supp, distname + ' oth')
  43. check_edge_support(distfn, arg)
  44. check_deprecation_warning_gh5982_moment(distfn, arg, distname)
  45. check_deprecation_warning_gh5982_interval(distfn, arg, distname)
  46. alpha = 0.01
  47. check_discrete_chisquare(distfn, arg, rvs, alpha,
  48. distname + ' chisquare')
  49. if first_case:
  50. locscale_defaults = (0,)
  51. meths = [distfn.pmf, distfn.logpmf, distfn.cdf, distfn.logcdf,
  52. distfn.logsf]
  53. # make sure arguments are within support
  54. # for some distributions, this needs to be overridden
  55. spec_k = {'randint': 11, 'hypergeom': 4, 'bernoulli': 0,
  56. 'nchypergeom_wallenius': 6}
  57. k = spec_k.get(distname, 1)
  58. check_named_args(distfn, k, arg, locscale_defaults, meths)
  59. if distname != 'sample distribution':
  60. check_scale_docstring(distfn)
  61. check_random_state_property(distfn, arg)
  62. check_pickling(distfn, arg)
  63. check_freezing(distfn, arg)
  64. # Entropy
  65. check_entropy(distfn, arg, distname)
  66. if distfn.__class__._entropy != stats.rv_discrete._entropy:
  67. check_private_entropy(distfn, arg, stats.rv_discrete)
  68. @pytest.mark.filterwarnings('ignore::RuntimeWarning')
  69. @pytest.mark.parametrize('distname,arg', distdiscrete)
  70. def test_moments(distname, arg):
  71. try:
  72. distfn = getattr(stats, distname)
  73. except TypeError:
  74. distfn = distname
  75. distname = 'sample distribution'
  76. m, v, s, k = distfn.stats(*arg, moments='mvsk')
  77. check_normalization(distfn, arg, distname)
  78. # compare `stats` and `moment` methods
  79. check_moment(distfn, arg, m, v, distname)
  80. check_mean_expect(distfn, arg, m, distname)
  81. check_var_expect(distfn, arg, m, v, distname)
  82. check_skew_expect(distfn, arg, m, v, s, distname)
  83. if distname not in ['zipf', 'yulesimon']:
  84. check_kurt_expect(distfn, arg, m, v, k, distname)
  85. # frozen distr moments
  86. check_moment_frozen(distfn, arg, m, 1)
  87. check_moment_frozen(distfn, arg, v+m*m, 2)
  88. @pytest.mark.parametrize('dist,shape_args', distdiscrete)
  89. def test_rvs_broadcast(dist, shape_args):
  90. # If shape_only is True, it means the _rvs method of the
  91. # distribution uses more than one random number to generate a random
  92. # variate. That means the result of using rvs with broadcasting or
  93. # with a nontrivial size will not necessarily be the same as using the
  94. # numpy.vectorize'd version of rvs(), so we can only compare the shapes
  95. # of the results, not the values.
  96. # Whether or not a distribution is in the following list is an
  97. # implementation detail of the distribution, not a requirement. If
  98. # the implementation the rvs() method of a distribution changes, this
  99. # test might also have to be changed.
  100. shape_only = dist in ['betabinom', 'skellam', 'yulesimon', 'dlaplace',
  101. 'nchypergeom_fisher', 'nchypergeom_wallenius']
  102. try:
  103. distfunc = getattr(stats, dist)
  104. except TypeError:
  105. distfunc = dist
  106. dist = 'rv_discrete(values=(%r, %r))' % (dist.xk, dist.pk)
  107. loc = np.zeros(2)
  108. nargs = distfunc.numargs
  109. allargs = []
  110. bshape = []
  111. # Generate shape parameter arguments...
  112. for k in range(nargs):
  113. shp = (k + 3,) + (1,)*(k + 1)
  114. param_val = shape_args[k]
  115. allargs.append(np.full(shp, param_val))
  116. bshape.insert(0, shp[0])
  117. allargs.append(loc)
  118. bshape.append(loc.size)
  119. # bshape holds the expected shape when loc, scale, and the shape
  120. # parameters are all broadcast together.
  121. check_rvs_broadcast(distfunc, dist, allargs, bshape, shape_only, [np.int_])
  122. @pytest.mark.parametrize('dist,args', distdiscrete)
  123. def test_ppf_with_loc(dist, args):
  124. try:
  125. distfn = getattr(stats, dist)
  126. except TypeError:
  127. distfn = dist
  128. #check with a negative, no and positive relocation.
  129. np.random.seed(1942349)
  130. re_locs = [np.random.randint(-10, -1), 0, np.random.randint(1, 10)]
  131. _a, _b = distfn.support(*args)
  132. for loc in re_locs:
  133. npt.assert_array_equal(
  134. [_a-1+loc, _b+loc],
  135. [distfn.ppf(0.0, *args, loc=loc), distfn.ppf(1.0, *args, loc=loc)]
  136. )
  137. @pytest.mark.parametrize('dist, args', distdiscrete)
  138. def test_isf_with_loc(dist, args):
  139. try:
  140. distfn = getattr(stats, dist)
  141. except TypeError:
  142. distfn = dist
  143. # check with a negative, no and positive relocation.
  144. np.random.seed(1942349)
  145. re_locs = [np.random.randint(-10, -1), 0, np.random.randint(1, 10)]
  146. _a, _b = distfn.support(*args)
  147. for loc in re_locs:
  148. expected = _b + loc, _a - 1 + loc
  149. res = distfn.isf(0., *args, loc=loc), distfn.isf(1., *args, loc=loc)
  150. npt.assert_array_equal(expected, res)
  151. # test broadcasting behaviour
  152. re_locs = [np.random.randint(-10, -1, size=(5, 3)),
  153. np.zeros((5, 3)),
  154. np.random.randint(1, 10, size=(5, 3))]
  155. _a, _b = distfn.support(*args)
  156. for loc in re_locs:
  157. expected = _b + loc, _a - 1 + loc
  158. res = distfn.isf(0., *args, loc=loc), distfn.isf(1., *args, loc=loc)
  159. npt.assert_array_equal(expected, res)
  160. def check_cdf_ppf(distfn, arg, supp, msg):
  161. # supp is assumed to be an array of integers in the support of distfn
  162. # (but not necessarily all the integers in the support).
  163. # This test assumes that the PMF of any value in the support of the
  164. # distribution is greater than 1e-8.
  165. # cdf is a step function, and ppf(q) = min{k : cdf(k) >= q, k integer}
  166. cdf_supp = distfn.cdf(supp, *arg)
  167. # In very rare cases, the finite precision calculation of ppf(cdf(supp))
  168. # can produce an array in which an element is off by one. We nudge the
  169. # CDF values down by 10 ULPs help to avoid this.
  170. cdf_supp0 = cdf_supp - 10*np.spacing(cdf_supp)
  171. npt.assert_array_equal(distfn.ppf(cdf_supp0, *arg),
  172. supp, msg + '-roundtrip')
  173. # Repeat the same calculation, but with the CDF values decreased by 1e-8.
  174. npt.assert_array_equal(distfn.ppf(distfn.cdf(supp, *arg) - 1e-8, *arg),
  175. supp, msg + '-roundtrip')
  176. if not hasattr(distfn, 'xk'):
  177. _a, _b = distfn.support(*arg)
  178. supp1 = supp[supp < _b]
  179. npt.assert_array_equal(distfn.ppf(distfn.cdf(supp1, *arg) + 1e-8, *arg),
  180. supp1 + distfn.inc, msg + ' ppf-cdf-next')
  181. def check_pmf_cdf(distfn, arg, distname):
  182. if hasattr(distfn, 'xk'):
  183. index = distfn.xk
  184. else:
  185. startind = int(distfn.ppf(0.01, *arg) - 1)
  186. index = list(range(startind, startind + 10))
  187. cdfs = distfn.cdf(index, *arg)
  188. pmfs_cum = distfn.pmf(index, *arg).cumsum()
  189. atol, rtol = 1e-10, 1e-10
  190. if distname == 'skellam': # ncx2 accuracy
  191. atol, rtol = 1e-5, 1e-5
  192. npt.assert_allclose(cdfs - cdfs[0], pmfs_cum - pmfs_cum[0],
  193. atol=atol, rtol=rtol)
  194. # also check that pmf at non-integral k is zero
  195. k = np.asarray(index)
  196. k_shifted = k[:-1] + np.diff(k)/2
  197. npt.assert_equal(distfn.pmf(k_shifted, *arg), 0)
  198. # better check frozen distributions, and also when loc != 0
  199. loc = 0.5
  200. dist = distfn(loc=loc, *arg)
  201. npt.assert_allclose(dist.pmf(k[1:] + loc), np.diff(dist.cdf(k + loc)))
  202. npt.assert_equal(dist.pmf(k_shifted + loc), 0)
  203. def check_moment_frozen(distfn, arg, m, k):
  204. npt.assert_allclose(distfn(*arg).moment(k), m,
  205. atol=1e-10, rtol=1e-10)
  206. def check_oth(distfn, arg, supp, msg):
  207. # checking other methods of distfn
  208. npt.assert_allclose(distfn.sf(supp, *arg), 1. - distfn.cdf(supp, *arg),
  209. atol=1e-10, rtol=1e-10)
  210. q = np.linspace(0.01, 0.99, 20)
  211. npt.assert_allclose(distfn.isf(q, *arg), distfn.ppf(1. - q, *arg),
  212. atol=1e-10, rtol=1e-10)
  213. median_sf = distfn.isf(0.5, *arg)
  214. npt.assert_(distfn.sf(median_sf - 1, *arg) > 0.5)
  215. npt.assert_(distfn.cdf(median_sf + 1, *arg) > 0.5)
  216. def check_discrete_chisquare(distfn, arg, rvs, alpha, msg):
  217. """Perform chisquare test for random sample of a discrete distribution
  218. Parameters
  219. ----------
  220. distname : string
  221. name of distribution function
  222. arg : sequence
  223. parameters of distribution
  224. alpha : float
  225. significance level, threshold for p-value
  226. Returns
  227. -------
  228. result : bool
  229. 0 if test passes, 1 if test fails
  230. """
  231. wsupp = 0.05
  232. # construct intervals with minimum mass `wsupp`.
  233. # intervals are left-half-open as in a cdf difference
  234. _a, _b = distfn.support(*arg)
  235. lo = int(max(_a, -1000))
  236. high = int(min(_b, 1000)) + 1
  237. distsupport = range(lo, high)
  238. last = 0
  239. distsupp = [lo]
  240. distmass = []
  241. for ii in distsupport:
  242. current = distfn.cdf(ii, *arg)
  243. if current - last >= wsupp - 1e-14:
  244. distsupp.append(ii)
  245. distmass.append(current - last)
  246. last = current
  247. if current > (1 - wsupp):
  248. break
  249. if distsupp[-1] < _b:
  250. distsupp.append(_b)
  251. distmass.append(1 - last)
  252. distsupp = np.array(distsupp)
  253. distmass = np.array(distmass)
  254. # convert intervals to right-half-open as required by histogram
  255. histsupp = distsupp + 1e-8
  256. histsupp[0] = _a
  257. # find sample frequencies and perform chisquare test
  258. freq, hsupp = np.histogram(rvs, histsupp)
  259. chis, pval = stats.chisquare(np.array(freq), len(rvs)*distmass)
  260. npt.assert_(pval > alpha,
  261. 'chisquare - test for %s at arg = %s with pval = %s' %
  262. (msg, str(arg), str(pval)))
  263. def check_scale_docstring(distfn):
  264. if distfn.__doc__ is not None:
  265. # Docstrings can be stripped if interpreter is run with -OO
  266. npt.assert_('scale' not in distfn.__doc__)
  267. @pytest.mark.parametrize('method', ['pmf', 'logpmf', 'cdf', 'logcdf',
  268. 'sf', 'logsf', 'ppf', 'isf'])
  269. @pytest.mark.parametrize('distname, args', distdiscrete)
  270. def test_methods_with_lists(method, distname, args):
  271. # Test that the discrete distributions can accept Python lists
  272. # as arguments.
  273. try:
  274. dist = getattr(stats, distname)
  275. except TypeError:
  276. return
  277. if method in ['ppf', 'isf']:
  278. z = [0.1, 0.2]
  279. else:
  280. z = [0, 1]
  281. p2 = [[p]*2 for p in args]
  282. loc = [0, 1]
  283. result = dist.pmf(z, *p2, loc=loc)
  284. npt.assert_allclose(result,
  285. [dist.pmf(*v) for v in zip(z, *p2, loc)],
  286. rtol=1e-15, atol=1e-15)
  287. @pytest.mark.parametrize('distname, args', invdistdiscrete)
  288. def test_cdf_gh13280_regression(distname, args):
  289. # Test for nan output when shape parameters are invalid
  290. dist = getattr(stats, distname)
  291. x = np.arange(-2, 15)
  292. vals = dist.cdf(x, *args)
  293. expected = np.nan
  294. npt.assert_equal(vals, expected)
  295. def cases_test_discrete_integer_shapes():
  296. # distributions parameters that are only allowed to be integral when
  297. # fitting, but are allowed to be real as input to PDF, etc.
  298. integrality_exceptions = {'nbinom': {'n'}}
  299. seen = set()
  300. for distname, shapes in distdiscrete:
  301. if distname in seen:
  302. continue
  303. seen.add(distname)
  304. try:
  305. dist = getattr(stats, distname)
  306. except TypeError:
  307. continue
  308. shape_info = dist._shape_info()
  309. for i, shape in enumerate(shape_info):
  310. if (shape.name in integrality_exceptions.get(distname, set()) or
  311. not shape.integrality):
  312. continue
  313. yield distname, shape.name, shapes
  314. @pytest.mark.parametrize('distname, shapename, shapes',
  315. cases_test_discrete_integer_shapes())
  316. def test_integer_shapes(distname, shapename, shapes):
  317. dist = getattr(stats, distname)
  318. shape_info = dist._shape_info()
  319. shape_names = [shape.name for shape in shape_info]
  320. i = shape_names.index(shapename) # this element of params must be integral
  321. shapes_copy = list(shapes)
  322. valid_shape = shapes[i]
  323. invalid_shape = valid_shape - 0.5 # arbitrary non-integral value
  324. new_valid_shape = valid_shape - 1
  325. shapes_copy[i] = [[valid_shape], [invalid_shape], [new_valid_shape]]
  326. a, b = dist.support(*shapes)
  327. x = np.round(np.linspace(a, b, 5))
  328. pmf = dist.pmf(x, *shapes_copy)
  329. assert not np.any(np.isnan(pmf[0, :]))
  330. assert np.all(np.isnan(pmf[1, :]))
  331. assert not np.any(np.isnan(pmf[2, :]))
  332. def test_frozen_attributes():
  333. # gh-14827 reported that all frozen distributions had both pmf and pdf
  334. # attributes; continuous should have pdf and discrete should have pmf.
  335. message = "'rv_discrete_frozen' object has no attribute"
  336. with pytest.raises(AttributeError, match=message):
  337. stats.binom(10, 0.5).pdf
  338. with pytest.raises(AttributeError, match=message):
  339. stats.binom(10, 0.5).logpdf
  340. stats.binom.pdf = "herring"
  341. frozen_binom = stats.binom(10, 0.5)
  342. assert isinstance(frozen_binom, rv_discrete_frozen)
  343. delattr(stats.binom, 'pdf')
  344. @pytest.mark.parametrize('distname, shapes', distdiscrete)
  345. def test_interval(distname, shapes):
  346. # gh-11026 reported that `interval` returns incorrect values when
  347. # `confidence=1`. The values were not incorrect, but it was not intuitive
  348. # that the left end of the interval should extend beyond the support of the
  349. # distribution. Confirm that this is the behavior for all distributions.
  350. if isinstance(distname, str):
  351. dist = getattr(stats, distname)
  352. else:
  353. dist = distname
  354. a, b = dist.support(*shapes)
  355. npt.assert_equal(dist.ppf([0, 1], *shapes), (a-1, b))
  356. npt.assert_equal(dist.isf([1, 0], *shapes), (a-1, b))
  357. npt.assert_equal(dist.interval(1, *shapes), (a-1, b))
  358. def test_rv_sample():
  359. # Thoroughly test rv_sample and check that gh-3758 is resolved
  360. # Generate a random discrete distribution
  361. rng = np.random.default_rng(98430143469)
  362. xk = np.sort(rng.random(10) * 10)
  363. pk = rng.random(10)
  364. pk /= np.sum(pk)
  365. dist = stats.rv_discrete(values=(xk, pk))
  366. # Generate points to the left and right of xk
  367. xk_left = (np.array([0] + xk[:-1].tolist()) + xk)/2
  368. xk_right = (np.array(xk[1:].tolist() + [xk[-1]+1]) + xk)/2
  369. # Generate points to the left and right of cdf
  370. cdf2 = np.cumsum(pk)
  371. cdf2_left = (np.array([0] + cdf2[:-1].tolist()) + cdf2)/2
  372. cdf2_right = (np.array(cdf2[1:].tolist() + [1]) + cdf2)/2
  373. # support - leftmost and rightmost xk
  374. a, b = dist.support()
  375. assert_allclose(a, xk[0])
  376. assert_allclose(b, xk[-1])
  377. # pmf - supported only on the xk
  378. assert_allclose(dist.pmf(xk), pk)
  379. assert_allclose(dist.pmf(xk_right), 0)
  380. assert_allclose(dist.pmf(xk_left), 0)
  381. # logpmf is log of the pmf; log(0) = -np.inf
  382. with np.errstate(divide='ignore'):
  383. assert_allclose(dist.logpmf(xk), np.log(pk))
  384. assert_allclose(dist.logpmf(xk_right), -np.inf)
  385. assert_allclose(dist.logpmf(xk_left), -np.inf)
  386. # cdf - the cumulative sum of the pmf
  387. assert_allclose(dist.cdf(xk), cdf2)
  388. assert_allclose(dist.cdf(xk_right), cdf2)
  389. assert_allclose(dist.cdf(xk_left), [0]+cdf2[:-1].tolist())
  390. with np.errstate(divide='ignore'):
  391. assert_allclose(dist.logcdf(xk), np.log(dist.cdf(xk)),
  392. atol=1e-15)
  393. assert_allclose(dist.logcdf(xk_right), np.log(dist.cdf(xk_right)),
  394. atol=1e-15)
  395. assert_allclose(dist.logcdf(xk_left), np.log(dist.cdf(xk_left)),
  396. atol=1e-15)
  397. # sf is 1-cdf
  398. assert_allclose(dist.sf(xk), 1-dist.cdf(xk))
  399. assert_allclose(dist.sf(xk_right), 1-dist.cdf(xk_right))
  400. assert_allclose(dist.sf(xk_left), 1-dist.cdf(xk_left))
  401. with np.errstate(divide='ignore'):
  402. assert_allclose(dist.logsf(xk), np.log(dist.sf(xk)),
  403. atol=1e-15)
  404. assert_allclose(dist.logsf(xk_right), np.log(dist.sf(xk_right)),
  405. atol=1e-15)
  406. assert_allclose(dist.logsf(xk_left), np.log(dist.sf(xk_left)),
  407. atol=1e-15)
  408. # ppf
  409. assert_allclose(dist.ppf(cdf2), xk)
  410. assert_allclose(dist.ppf(cdf2_left), xk)
  411. assert_allclose(dist.ppf(cdf2_right)[:-1], xk[1:])
  412. assert_allclose(dist.ppf(0), a - 1)
  413. assert_allclose(dist.ppf(1), b)
  414. # isf
  415. sf2 = dist.sf(xk)
  416. assert_allclose(dist.isf(sf2), xk)
  417. assert_allclose(dist.isf(1-cdf2_left), dist.ppf(cdf2_left))
  418. assert_allclose(dist.isf(1-cdf2_right), dist.ppf(cdf2_right))
  419. assert_allclose(dist.isf(0), b)
  420. assert_allclose(dist.isf(1), a - 1)
  421. # interval is (ppf(alpha/2), isf(alpha/2))
  422. ps = np.linspace(0.01, 0.99, 10)
  423. int2 = dist.ppf(ps/2), dist.isf(ps/2)
  424. assert_allclose(dist.interval(1-ps), int2)
  425. assert_allclose(dist.interval(0), dist.median())
  426. assert_allclose(dist.interval(1), (a-1, b))
  427. # median is simply ppf(0.5)
  428. med2 = dist.ppf(0.5)
  429. assert_allclose(dist.median(), med2)
  430. # all four stats (mean, var, skew, and kurtosis) from the definitions
  431. mean2 = np.sum(xk*pk)
  432. var2 = np.sum((xk - mean2)**2 * pk)
  433. skew2 = np.sum((xk - mean2)**3 * pk) / var2**(3/2)
  434. kurt2 = np.sum((xk - mean2)**4 * pk) / var2**2 - 3
  435. assert_allclose(dist.mean(), mean2)
  436. assert_allclose(dist.std(), np.sqrt(var2))
  437. assert_allclose(dist.var(), var2)
  438. assert_allclose(dist.stats(moments='mvsk'), (mean2, var2, skew2, kurt2))
  439. # noncentral moment against definition
  440. mom3 = np.sum((xk**3) * pk)
  441. assert_allclose(dist.moment(3), mom3)
  442. # expect - check against moments
  443. assert_allclose(dist.expect(lambda x: 1), 1)
  444. assert_allclose(dist.expect(), mean2)
  445. assert_allclose(dist.expect(lambda x: x**3), mom3)
  446. # entropy is the negative of the expected value of log(p)
  447. with np.errstate(divide='ignore'):
  448. assert_allclose(-dist.expect(lambda x: dist.logpmf(x)), dist.entropy())
  449. # RVS is just ppf of uniform random variates
  450. rng = np.random.default_rng(98430143469)
  451. rvs = dist.rvs(size=100, random_state=rng)
  452. rng = np.random.default_rng(98430143469)
  453. rvs0 = dist.ppf(rng.random(size=100))
  454. assert_allclose(rvs, rvs0)