How does Pyro perform operations with Random Variables?

250 Views Asked by At

In Pyro there is a new experimental container class: Random Variables

Using Random Variables you can write something like this:

from pyro.distributions.torch import Normal

X = Normal(5, 1).rv
Y = Normal(20, 3).rv

Z = 3*X + Y

where X,Y,Z are distributions.

What is the mathematical foundation behind the '+' operation between Random Variables? I can imagine that multiplying with a constant number is pretty trivial, but what about performing operations with an RV? For example, in Probability Theory we have the Circular Convolution.

I searched the documentation but I got lost in the Pyro-pyTorch connection.

1

There are 1 best solutions below

0
Dilara Gokay On

The relevant section for addition is here https://github.com/pyro-ppl/pyro/blob/53cfeaa5f6a3a92231bf8ad60a9ea69e5f10aad6/pyro/contrib/randomvariable/random_variable.py#L24-L27

def __add__(self, x: Union[float, Tensor]):
    return RandomVariable(
        TransformedDistribution(self.distribution, AffineTransform(x, 1))
    )

Other arithmetic operations are also in this file.