@@ -211,7 +211,6 @@ def __init__(
211
211
random = None ,
212
212
wrap_random_with_dist_shape = True ,
213
213
check_shape_in_random = True ,
214
- pymc3_size_interpretation = True ,
215
214
* args ,
216
215
** kwargs
217
216
):
@@ -251,29 +250,6 @@ def __init__(
251
250
If ``True``, the shape of the random samples generate in the
252
251
``random`` method is checked with the expected return shape. This
253
252
test is only performed if ``wrap_random_with_dist_shape is False``.
254
- pymc3_size_interpretation: bool (Optional)
255
- This flag affects how the ``size`` parameter supplied to the
256
- passed ``random`` function is interpreted. If no ``random``
257
- callable is supplied, this flag is ignored. Furthermore, this flag
258
- is only used if ``wrap_random_with_dist_shape`` is `True``.
259
- If ``True``, the ``size`` parameter of ``random`` is interpreted
260
- as the number of IID draws to take from a given distribution,
261
- which is how every pymc3 distribution interprets the ``size``
262
- parameter.
263
- If it is ``False``, the ``size`` parameter is used just like in
264
- any scipy random variate generator, i.e. the shape of the returned
265
- array of samples.
266
- The difference is subtle and is only relevant in multidimensional
267
- distributions. Consider that a multivariate normal of rank 3 is
268
- used as the random number generator. With the pymc3 interpretation
269
- of ``size``, a call like ``random(size=10)`` will return an array
270
- with shape ``(10, 3)``. With the scipy interpretation, to get a
271
- similarly shaped result, the call must be changed to
272
- ``random(size=(10, 3))``.
273
- A quick rule of thumb is that if the supplied ``random`` callable
274
- is a pymc3 distribution's random method, you should set this flag
275
- to ``True``. If you use a scipy rvs, you should set this flag to
276
- ``False``. Refer to the examples for more information.
277
253
args, kwargs: (Optional)
278
254
These are passed to the parent class' ``__init__``.
279
255
@@ -371,52 +347,12 @@ def __init__(
371
347
# We get samples with an incorrect shape
372
348
assert prior.shape != (10, 100, 3)
373
349
374
- The default catching can be disabled with the
375
- ``check_shape_in_random`` parameter.
376
-
377
-
378
- .. code-block:: python
379
-
380
- with pm.Model():
381
- mu = pm.Normal('mu', 0 , 1)
382
- normal_dist = pm.Normal.dist(mu, 1, shape=3)
383
- dens = pm.DensityDist(
384
- 'density_dist',
385
- normal_dist.logp,
386
- observed=np.random.randn(100, 3),
387
- shape=3,
388
- random=normal_dist.random,
389
- wrap_random_with_dist_shape=False, # Is True by default
390
- check_shape_in_random=False, # Is True by default
391
- )
392
- prior = pm.sample_prior_predictive(10)['density_dist']
393
- # We get samples with an incorrect shape
394
- assert prior.shape != (10, 100, 3)
395
-
396
- One final word of caution. If you use a pymc3 distribution's random
397
- method, you should stick with ``pymc3_size_interpretation=True``, or
398
- you will get incorrectly shaped samples.
399
-
400
-
401
- .. code-block:: python
402
-
403
- with pm.Model():
404
- mu = pm.Normal('mu', 0 , 1)
405
- normal_dist = pm.Normal.dist(mu, 1, shape=3)
406
- dens = pm.DensityDist(
407
- 'density_dist',
408
- normal_dist.logp,
409
- observed=np.random.randn(100, 3),
410
- shape=3,
411
- random=normal_dist.random,
412
- pymc3_size_interpretation=False, # Is True by default
413
- )
414
- prior = pm.sample_prior_predictive(10)['density_dist']
415
- assert prior.shape != (10, 100, 3)
416
- assert prior.shape == (10, 100, 3, 3)
417
-
418
- If you use callables that work with ``scipy.stats`` rvs, you should
419
- set ``pymc3_size_interpretation=False``.
350
+ If you use callables that work with ``scipy.stats`` rvs, you must
351
+ be aware that their ``size`` parameter is not the number of IID
352
+ samples to draw from a distribution, but the desired ``shape`` of
353
+ the returned array of samples. It is the user's responsibility to
354
+ wrap the callable to make it comply with PyMC3's interpretation
355
+ of ``size``.
420
356
421
357
422
358
.. code-block:: python
@@ -443,7 +379,6 @@ def __init__(
443
379
self .rand = random
444
380
self .wrap_random_with_dist_shape = wrap_random_with_dist_shape
445
381
self .check_shape_in_random = check_shape_in_random
446
- self .pymc3_size_interpretation = pymc3_size_interpretation
447
382
448
383
def random (self , point = None , size = None , ** kwargs ):
449
384
if self .rand is not None :
@@ -464,11 +399,9 @@ def random(self, point=None, size=None, **kwargs):
464
399
[dist_shape , test_shape ],
465
400
size = size
466
401
)
467
- if self .pymc3_size_interpretation :
468
- len (broadcast_shape ) - len (test_shape )
469
- broadcast_shape = broadcast_shape [
470
- :len (broadcast_shape ) - len (test_shape )
471
- ]
402
+ broadcast_shape = broadcast_shape [
403
+ :len (broadcast_shape ) - len (test_shape )
404
+ ]
472
405
samples = generate_samples (
473
406
self .rand ,
474
407
broadcast_shape = broadcast_shape ,
0 commit comments