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

Symbolic shape argument to Distribution #2406

Closed
bwengals opened this issue Jul 10, 2017 · 4 comments
Closed

Symbolic shape argument to Distribution #2406

bwengals opened this issue Jul 10, 2017 · 4 comments

Comments

@bwengals
Copy link
Contributor

For example, the model

with pm.Model() as model:
    a = pm.Normal("a", mu=0.0, sd=1.0, shape=tt.as_tensor_variable(3))

will fail with exception:

----------------------------------------------------------
TypeError                Traceback (most recent call last)
<ipython-input-6-40fdcd9234e8> in <module>()
      1 with pm.Model() as model:
----> 2     a = pm.Normal("a", mu=0.0, sd=1.0, shape=tt.as_tensor_variable(3))

~/pymc3/pymc3/distributions/distribution.py in __new__(cls, name, *args, **kwargs)
     33                 raise TypeError("observed needs to be data but got: {}".format(type(data)))
     34             total_size = kwargs.pop('total_size', None)
---> 35             dist = cls.dist(*args, **kwargs)
     36             return model.Var(name, dist, data, total_size)
     37         else:

~/pymc3/pymc3/distributions/distribution.py in dist(cls, *args, **kwargs)
     44     def dist(cls, *args, **kwargs):
     45         dist = object.__new__(cls)
---> 46         dist.__init__(*args, **kwargs)
     47         return dist
     48 

~/pymc3/pymc3/distributions/continuous.py in __init__(self, mu, sd, tau, **kwargs)
    253         assert_negative_support(tau, 'tau', 'Normal')
    254 
--> 255         super(Normal, self).__init__(**kwargs)
    256 
    257     def random(self, point=None, size=None, repeat=None):

~/pymc3/pymc3/distributions/distribution.py in __init__(self, shape, dtype, defaults, *args, **kwargs)
    145             dtype = theano.config.floatX
    146         super(Continuous, self).__init__(
--> 147             shape, dtype, defaults=defaults, *args, **kwargs)
    148 
    149 

~/pymc3/pymc3/distributions/distribution.py in __init__(self, shape, dtype, testval, defaults, transform, broadcastable)
      51         self.shape = np.atleast_1d(shape)
     52         if False in (np.floor(self.shape) == self.shape):
---> 53             raise TypeError("Expected int elements in shape")
     54         self.dtype = dtype
     55         self.type = TensorType(self.dtype, self.shape, broadcastable)

TypeError: Expected int elements in shape

This situation arises for me when working with GP classes. Would it be a good idea to handle a symbolic shape argument given to a distribution?

@twiecki
Copy link
Member

twiecki commented Jul 10, 2017

Would be a great idea and we have discussed it before but I think it might be quite difficult.

@bwengals
Copy link
Contributor Author

Ah ok, ill look into it

@ferrine
Copy link
Member

ferrine commented Jul 13, 2017

The current idea is not possible. Because we need fixed latent dimensionality for for inference approaches MCMC and VI. Flexibility can be introduced when doing AEVB only.

@aseyboldt
Copy link
Member

I thought about more flexible shape handling a bit, as it came up a couple of times now. I've got a few ideas, and a sketch of an implementation for some of it. I'll push it later, maybe we can mention it in the meeting tomorrow.

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

No branches or pull requests

5 participants