# Random Variables¶

## Random Variable¶

class RandomVariable(distribution)[source]

Bases: pyro.contrib.randomvariable.random_variable.RVMagicOps, pyro.contrib.randomvariable.random_variable.RVChainOps

EXPERIMENTAL random variable container class around a distribution

Representation of a distribution interpreted as a random variable. Rather than directly manipulating a probability density by applying pointwise transformations to it, this allows for simple arithmetic transformations of the random variable the distribution represents. For more flexibility, consider using the transform method. Note that if you perform a non-invertible transform (like abs(X) or X**2), certain things might not work properly.

Can switch between RandomVariable and Distribution objects with the convenient Distribution.rv and RandomVariable.dist properties.

Example usage:

# This should be equivalent to an Exponential distribution.
RandomVariable(Uniform(0, 1)).log().neg().dist

# These two distributions Y1, Y2 should be the same
X = Uniform(0, 1).rv
Y1 = X.mul(4).pow(0.5).sub(1).abs().neg().dist
Y2 = (-abs((4*X)**(0.5) - 1)).dist

dist

Convenience property for exposing the distribution underlying the random variable.

Returns: The Distribution object underlying the random variable Distribution
transform(t: torch.distributions.transforms.Transform)[source]

Performs a transformation on the distribution underlying the RV.

Parameters: t (Transform) – The transformation (or sequence of transformations) to be applied to the distribution. There are many examples to be found in torch.distributions.transforms and pyro.distributions.transforms, or you can subclass directly from Transform. The transformed RandomVariable RandomVariable