Skip to content

add operator overloading to RandomVariable #445

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 2 commits into from
Feb 8, 2017

Conversation

dustinvtran
Copy link
Member

@dustinvtran dustinvtran commented Feb 8, 2017

Many operators are overloaded for RandomVariable, following those available in tf.Tensor. The output is always a tf.Tensor. It operates on the sample tensor associated to the RandomVariable.

For example, this lets us do

from edward.models import Normal

x = Normal(mu=0.0, sigma=1.0)
y = Normal(mu=0.0, sigma=1.0)

x + y, x * y, x / y, x // y
x == y
hash(x)
-x
x ** y

Remarks

  • An open question is what to do with the __getitem__ method. That is, should we also return indexing from the sample tensor? Or should __getitem__ be the only method that returns a subset of the random variable? (If so, how do we do so efficiently?)
  • Should eval() be a method? E.g., calling x.eval() would be easier than x.value().eval() which is almost always what the user intended. I think it should only be a method if we can also do sess.run(x) somehow, and not require sess.run(x.value()).

todo

  • unit test

@dustinvtran dustinvtran merged commit de28dea into master Feb 8, 2017
@dustinvtran dustinvtran deleted the feature/operator-overload branch February 8, 2017 22:02
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

Successfully merging this pull request may close these issues.

1 participant