Skip to content

Rename disable_bounds_check to check_bounds #4378

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Dec 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ It also brings some dreadfully awaited fixes, so be sure to go through the chang
- Removed `theanof.set_theano_config` because it illegally changed Theano's internal state (see [#4329](https://github.com/pymc-devs/pymc3/pull/4329)).

### New Features
- Option to `disable_bounds_check=True` when instantiating `pymc3.Model()` for faster sampling for models that cannot violate boundary constraints (which are most of them; see [#4377](https://github.com/pymc-devs/pymc3/pull/4377)).
- Option to set `check_bounds=False` when instantiating `pymc3.Model()`. This turns off bounds checks that ensure that input parameters of distributions are valid. For correctly specified models, this is unneccessary as all parameters get automatically transformed so that all values are valid. Turning this off should lead to faster sampling (see [#4377](https://github.com/pymc-devs/pymc3/pull/4377)).
- `OrderedProbit` distribution added (see [#4232](https://github.com/pymc-devs/pymc3/pull/4232)).
- `plot_posterior_predictive_glm` now works with `arviz.InferenceData` as well (see [#4234](https://github.com/pymc-devs/pymc3/pull/4234))

Expand Down
2 changes: 1 addition & 1 deletion pymc3/distributions/dist_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def bound(logp, *conditions, **kwargs):
# If called inside a model context, see if bounds check is disabled
try:
model = modelcontext(kwargs.get("model"))
if model.disable_bounds_check:
if not model.check_bounds:
return logp
except TypeError: # No model found
pass
Expand Down
16 changes: 7 additions & 9 deletions pymc3/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,11 @@ class Model(Factor, WithMemoization, metaclass=ContextMeta):
temporarily in the model context. See the documentation
of theano for a complete list. Set config key
``compute_test_value`` to `raise` if it is None.
disable_bounds_check: bool
Disable checks that ensure that input parameters to distributions
are in a valid range. If your model is built in a way where you
know your parameters can only take on valid values you can disable
this for increased speed.
check_bounds: bool
Ensure that input parameters to distributions are in a valid
range. If your model is built in a way where you know your
parameters can only take on valid values you can set this to
False for increased speed.

Examples
--------
Expand Down Expand Up @@ -900,14 +900,12 @@ def __new__(cls, *args, **kwargs):
instance._theano_config = theano_config
return instance

def __init__(
self, name="", model=None, theano_config=None, coords=None, disable_bounds_check=False
):
def __init__(self, name="", model=None, theano_config=None, coords=None, check_bounds=True):
self.name = name
self.coords = {}
self.RV_dims = {}
self.add_coords(coords)
self.disable_bounds_check = disable_bounds_check
self.check_bounds = check_bounds

if self.parent is not None:
self.named_vars = treedict(parent=self.parent.named_vars)
Expand Down
4 changes: 2 additions & 2 deletions pymc3/tests/test_dist_math.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ def test_bound():
assert np.prod(bound(logp, cond).eval()) == -np.inf


def test_bound_disabled():
with pm.Model(disable_bounds_check=True):
def test_check_bounds_false():
with pm.Model(check_bounds=False):
logp = tt.ones(3)
cond = np.array([1, 0, 1])
assert np.all(bound(logp, cond).eval() == logp.eval())
Expand Down