Skip to content
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

Beta logcdf method fails with array of values #4342

Closed
ricardoV94 opened this issue Dec 14, 2020 · 2 comments
Closed

Beta logcdf method fails with array of values #4342

ricardoV94 opened this issue Dec 14, 2020 · 2 comments

Comments

@ricardoV94
Copy link
Member

ricardoV94 commented Dec 14, 2020

The pm.distributions.dist_math function incomplete_beta fails when arrays/tensors are used.

This function is used by the logcdf method of the Beta distribution (and after #4331, in the logcdf of the Binomial distribution), which fails when multiple values are passed in.

Should we be concerned about this? From the docstrings, it seems that all logcdf methods are intended to work with both scalars and arrays/tensors values.

pm.Beta.dist(1, 1).logcdf(.5)  # Works fine
pm.Beta.dist(1, 1).logcdf(np.array([.5]))  # raises TypeError
pm.Beta.dist(1, 1).logcdf(np.array([.5, .5]))  # raises TypeError

Error message:

Traceback (most recent call last):
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 192, in as_tensor_variable
    x = [extract_constants(i) for i in x]
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 192, in <listcomp>
    x = [extract_constants(i) for i in x]
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 187, in extract_constants
    raise TypeError
TypeError
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/IPython/core/interactiveshell.py", line 3418, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-48-3fcd0330d059>", line 1, in <module>
    pm.Beta.dist(1, 1).logcdf(np.array([.5, .5]))
  File "/home/ricardo/Documents/Projects/pymc3/pymc3/distributions/continuous.py", line 1317, in logcdf
    tt.switch(tt.ge(value, 1), 0, tt.log(incomplete_beta(a, b, value))),
  File "/home/ricardo/Documents/Projects/pymc3/pymc3/distributions/dist_math.py", line 511, in incomplete_beta
    ps = incomplete_beta_ps(a, b, value)
  File "/home/ricardo/Documents/Projects/pymc3/pymc3/distributions/dist_math.py", line 493, in incomplete_beta_ps
    _step, sequences=[tt.arange(2, 302)], outputs_info=[e for e in tt.cast((t, s), "float64")]
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 1326, in cast
    _x = as_tensor_variable(x)
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 194, in as_tensor_variable
    return stack(x)
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 4899, in stack
    return join(axis, *[shape_padaxis(t, axis) for t in tensors])
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 4668, in join
    return join_(axis, *tensors_list)
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/gof/op.py", line 642, in __call__
    node = self.make_node(*inputs, **kwargs)
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 4389, in make_node
    return self._make_node_internal(
  File "/home/ricardo/Documents/Projects/pymc3-venv/lib/python3.8/site-packages/theano/tensor/basic.py", line 4459, in _make_node_internal
    raise TypeError(
TypeError: Join() can only join tensors with the same number of dimensions.
@ricardoV94
Copy link
Member Author

Same issue arises with StudentT logcdf method, as it also uses the incomplete_beta function

@ricardoV94
Copy link
Member Author

This is partially addressed by #4393 and it now raises an informative TypeError when given multiple values.

Unless someone wants to vectorize the incomplete_beta function there is nothing else that can be done. Feel free to close this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants