edward2 icon indicating copy to clipboard operation
edward2 copied to clipboard

Cannot pass a random variable to TransformedDistribution

Open AdrienCorenflos opened this issue 4 years ago • 2 comments

Hi,

I am using edward2==0.0.1 in combination with tensorflow_probability==0.9.0 and tensorflow==2.1.0, all installed from pip.

I am facing an issue with ed.TransformedDistribution that feel like a regression to me.

import edward2 as ed
import tensorflow_probability as tfp
tfb = tfp.bijectors

normal = ed.Normal(0., 1.)
shifted_normal = ed.TransformedDistribution(normal, tfb.Shift(0.5))
# This raises with AttributeError: 'RandomVariable' object has no attribute 'name'

I can patch the case 1 by passing normal.distribution to ed.TransformedDistribution but I don't think this is desirable.

AdrienCorenflos avatar May 12 '20 12:05 AdrienCorenflos

Thanks for raising this! In the code, we minimally wrap all distributions as ed2 rvs, and the input types are the same as distributions (this is why ed.TransformedDistribution still takes a distribution as input).

One way to resolve this is to augment all higher-order distributions that take a distribution as input to take a RandomVariable as input (that is, raising all tfp.Distribution types to ed.RandomVariable types). It's easy to do this on a one-off basis, but we haven't quite figured out how to automate this which would be better for maintenance.

dustinvtran avatar May 13 '20 17:05 dustinvtran

Ah yes that sounds tricky if you don't want to break the open close principles.

Also even doing it on a case by case basis may prove complicated. For example, someone coded a distribution by subclassing the Transformed Distribution instead of composing it (I might send a PR for that one...), so you wouldn't be able to check the bases of the classes not their attributes either...

AdrienCorenflos avatar May 13 '20 18:05 AdrienCorenflos