Skip to content

Commit d105682

Browse files
kc611ricardoV94
authored andcommitted
Refactor Bound distribution
1 parent 6a75744 commit d105682

File tree

7 files changed

+382
-344
lines changed

7 files changed

+382
-344
lines changed

RELEASE-NOTES.md

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- The `Distribution` keyword argument `testval` has been deprecated in favor of `initval`. Furthermore `initval` no longer assigns a `tag.test_value` on tensors since the initial values are now kept track of by the model object ([see #4913](https://github.com/pymc-devs/pymc3/pull/4913)).
1010
- `pm.sample` now returns results as `InferenceData` instead of `MultiTrace` by default (see [#4744](https://github.com/pymc-devs/pymc3/pull/4744)).
1111
- `pm.sample_prior_predictive` no longer returns transformed variable values by default. Pass them by name in `var_names` if you want to obtain these draws (see [4769](https://github.com/pymc-devs/pymc3/pull/4769)).
12+
-`pm.Bound` interface no longer accepts a callable class as argument, instead it requires an instantiated distribution (created via the `.dist()` API) to be passed as an argument. In addition, Bound no longer returns a class instance but works as a normal PyMC3 distribution. Finally, it is no longer possible to do predictive random sampling from Bounded variables. Please, consult the new documentation for details on how to use Bounded variables (see [4815](https://github.com/pymc-devs/pymc3/pull/4815)).
1213
- ...
1314

1415
### New Features

docs/source/api/bounds.rst

+2-26
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ PyMC3 includes the construct :class:`~pymc3.distributions.bound.Bound` for
66
placing constraints on existing probability distributions. It modifies a given
77
distribution to take values only within a specified interval.
88

9-
Note that the `Bound` class does *not* directly create a bounded
10-
distribution: instead it creates a Callable class that can be
11-
*invoked* to create a bounded distribution, as the example below illustrates.
12-
139
Some types of variables require constraints. For instance, it doesn't make
1410
sense for a standard deviation to have a negative value, so something like a
1511
Normal prior on a parameter that represents a standard deviation would be
@@ -38,28 +34,8 @@ specification of a bounded distribution should go within the model block::
3834
import pymc3 as pm
3935

4036
with pm.Model() as model:
41-
BoundedNormal = pm.Bound(pm.Normal, lower=0.0)
42-
x = BoundedNormal('x', mu=1.0, sigma=3.0)
43-
44-
If the bound will be applied to a single variable in the model, it may be
45-
cleaner notationally to define both the bound and variable together. ::
46-
47-
with model:
48-
x = pm.Bound(pm.Normal, lower=0.0)('x', mu=1.0, sigma=3.0)
49-
50-
However, it is possible to create multiple different random variables
51-
that have the same bound applied to them::
52-
53-
with model:
54-
BoundNormal = pm.Bound(pm.Normal, lower=0.0)
55-
hyper_mu = BoundNormal("hyper_mu", mu=1, sigma=0.5)
56-
mu = BoundNormal("mu", mu=hyper_mu, sigma=1)
57-
58-
Bounds can also be applied to a vector of random variables. With the same
59-
``BoundedNormal`` object we created previously we can write::
60-
61-
with model:
62-
x_vector = BoundedNormal('x_vector', mu=1.0, sigma=3.0, shape=3)
37+
norm = Normal.dist(mu=1.0, sigma=3.0)
38+
x = Bound('x', norm, lower=0.0)
6339

6440
Caveats
6541
#######

0 commit comments

Comments
 (0)