Skip to content

Beta logcdf method fails with array of values #4342

Closed
@ricardoV94

Description

@ricardoV94

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions