Skip to content

Commit 592171a

Browse files
committed
Rename DensityDist to CustomDist
Old DensityDist alias is kept
1 parent ddc6b65 commit 592171a

File tree

8 files changed

+96
-87
lines changed

8 files changed

+96
-87
lines changed

docs/source/api/distributions/utilities.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ Distribution utilities
99
Distribution
1010
Discrete
1111
Continuous
12-
DensityDist
12+
CustomDist
1313
SymbolicRandomVariable

pymc/distributions/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@
7676
)
7777
from pymc.distributions.distribution import (
7878
Continuous,
79+
CustomDist,
7980
DensityDist,
8081
Discrete,
8182
Distribution,
@@ -154,6 +155,7 @@
154155
"OrderedLogistic",
155156
"OrderedProbit",
156157
"DensityDist",
158+
"CustomDist",
157159
"Distribution",
158160
"SymbolicRandomVariable",
159161
"Continuous",

pymc/distributions/distribution.py

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
from pymc.vartypes import string_types
5959

6060
__all__ = [
61-
"DensityDistRV",
61+
"CustomDist",
6262
"DensityDist",
6363
"Distribution",
6464
"Continuous",
@@ -456,15 +456,15 @@ class Continuous(Distribution):
456456
"""Base class for continuous distributions"""
457457

458458

459-
class DensityDistRV(RandomVariable):
459+
class CustomDistRV(RandomVariable):
460460
"""
461-
Base class for DensityDistRV
461+
Base class for CustomDistRV
462462
463-
This should be subclassed when defining custom DensityDist objects.
463+
This should be subclassed when defining CustomDist objects.
464464
"""
465465

466-
name = "DensityDistRV"
467-
_print_name = ("DensityDist", "\\operatorname{DensityDist}")
466+
name = "CustomDistRV"
467+
_print_name = ("CustomDist", "\\operatorname{CustomDist}")
468468

469469
@classmethod
470470
def rng_fn(cls, rng, *args):
@@ -473,7 +473,7 @@ def rng_fn(cls, rng, *args):
473473
return cls._random_fn(*args, rng=rng, size=size)
474474

475475

476-
class DensityDist(Distribution):
476+
class CustomDist(Distribution):
477477
"""A distribution that can be used to wrap black-box log density functions.
478478
479479
Creates a Distribution and registers the supplied log density function to be used
@@ -489,11 +489,11 @@ class DensityDist(Distribution):
489489
PyTensor tensors internally. These parameters could be other ``TensorVariable``
490490
instances created from , optionally created via ``RandomVariable`` ``Op``s.
491491
class_name : str
492-
Name for the RandomVariable class which will wrap the DensityDist methods.
492+
Name for the RandomVariable class which will wrap the CustomDist methods.
493493
When not specified, it will be given the name of the variable.
494494
495-
.. warning:: New DensityDists created with the same class_name will override the
496-
methods dispatched onto the previous classes. If using DensityDists with
495+
.. warning:: New CustomDists created with the same class_name will override the
496+
methods dispatched onto the previous classes. If using CustomDists with
497497
different methods across separate models, be sure to use distinct
498498
class_names.
499499
@@ -517,7 +517,7 @@ class DensityDist(Distribution):
517517
A callable that can be used to generate random draws from the distribution.
518518
It must have the following signature: ``random(*dist_params, rng=None, size=None)``.
519519
The distribution parameters are passed as positional arguments in the
520-
same order as they are supplied when the ``DensityDist`` is constructed.
520+
same order as they are supplied when the ``CustomDist`` is constructed.
521521
The keyword arguments are ``rnd``, which will provide the random variable's
522522
associated :py:class:`~numpy.random.Generator`, and ``size``, that will represent
523523
the desired size of the random draw. If ``None``, a ``NotImplemented``
@@ -530,7 +530,7 @@ class DensityDist(Distribution):
530530
as the first argument ``rv``. ``size`` is the random variable's size implied
531531
by the ``dims``, ``size`` and parameters supplied to the distribution. Finally,
532532
``rv_inputs`` is the sequence of the distribution parameters, in the same order
533-
as they were supplied when the DensityDist was created. If ``None``, a default
533+
as they were supplied when the CustomDist was created. If ``None``, a default
534534
``moment`` function will be assigned that will always return 0, or an array
535535
of zeros.
536536
ndim_supp : int
@@ -555,8 +555,8 @@ def logp(value, mu):
555555
556556
with pm.Model():
557557
mu = pm.Normal('mu',0,1)
558-
pm.DensityDist(
559-
'density_dist',
558+
pm.CustomDist(
559+
'custom_dist',
560560
mu,
561561
logp=logp,
562562
observed=np.random.randn(100),
@@ -573,20 +573,19 @@ def random(mu, rng=None, size=None):
573573
574574
with pm.Model():
575575
mu = pm.Normal('mu', 0 , 1)
576-
dens = pm.DensityDist(
577-
'density_dist',
576+
pm.CustomDist(
577+
'custom_dist',
578578
mu,
579579
logp=logp,
580580
random=random,
581581
observed=np.random.randn(100, 3),
582582
size=(100, 3),
583583
)
584-
prior = pm.sample_prior_predictive(10).prior_predictive['density_dist']
585-
assert prior.shape == (1, 10, 100, 3)
584+
prior = pm.sample_prior_predictive(10)
586585
587586
"""
588587

589-
rv_type = DensityDistRV
588+
rv_type = CustomDistRV
590589

591590
def __new__(cls, name, *args, **kwargs):
592591
kwargs.setdefault("class_name", name)
@@ -676,15 +675,15 @@ def rv_op(
676675
**kwargs,
677676
):
678677
rv_op = type(
679-
f"DensityDist_{class_name}",
680-
(DensityDistRV,),
678+
f"CustomDist_{class_name}",
679+
(CustomDistRV,),
681680
dict(
682-
name=f"DensityDist_{class_name}",
681+
name=f"CustomDist_{class_name}",
683682
inplace=False,
684683
ndim_supp=ndim_supp,
685684
ndims_params=ndims_params,
686685
dtype=dtype,
687-
# Specifc to DensityDist
686+
# Specifc to CustomDist
688687
_random_fn=random,
689688
),
690689
)()
@@ -710,9 +709,12 @@ def density_dist_get_moment(op, rv, rng, size, dtype, *dist_params):
710709
return rv_op(*dist_params, **kwargs)
711710

712711

712+
DensityDist = CustomDist
713+
714+
713715
def default_not_implemented(rv_name, method_name):
714716
message = (
715-
f"Attempted to run {method_name} on the DensityDist '{rv_name}', "
717+
f"Attempted to run {method_name} on the CustomDist '{rv_name}', "
716718
f"but this method had not been provided when the distribution was "
717719
f"constructed. Please re-build your model and provide a callable "
718720
f"to '{rv_name}'s {method_name} keyword argument.\n"

0 commit comments

Comments
 (0)