rvar

rvs

Module for random variable classes.

class quinn.rvar.rvs.RV[source]

Bases: Module

Parent class for random variables.

__init__()[source]

Initialization.

sample(num_samples=1)[source]

Sampling function.

Raises:

NotImplementedError – Expected to be implemented in children classes

log_prob(x)[source]

Evaluate log-probability.

Raises:

NotImplementedError – Expected to be implemented in children classes

class quinn.rvar.rvs.MVN(mean, cov)[source]

Bases: RV

sample(num_samples)[source]

Sampling function.

Raises:

NotImplementedError – Expected to be implemented in children classes

log_prob(x)[source]

Evaluate log-probability.

Raises:

NotImplementedError – Expected to be implemented in children classes

class quinn.rvar.rvs.Gaussian_1d(mu, rho=None, logsigma=None)[source]

Bases: RV

One dimensional gaussian random variable.

mu

Mean tensor.

Type:

torch.Tensor

rho

\(\rho\) tensor, where \(\rho=\log{(e^\sigma-1)}\) or, equivalently, \(\sigma=\log{(1+e^\rho)}\). This is the parameterization used in Blundell et al. [1].

Type:

torch.Tensor

logsigma

A more typical parameterization of the gaussian standard deviation \(\sigma\) via its natural logarithm \(\log{\sigma}\).

Type:

torch.Tensor

normal

The underlying torch-based normal random variable.

Type:

torch.distributions.Normal

__init__(mu, rho=None, logsigma=None)[source]

Instantiate the random variable.

Parameters:
  • mu (torch.Tensor) – Mean tensor.

  • rho (torch.Tensor, optional) – Parameterization that relates to standard deviation as \(\sigma=\log{(1+e^\rho)}\).

  • logsigma (torch.Tensor, optional) – Parameterization that relates to standard deviation as \(\log{\sigma}\).

Note

Exactly one of rho or logsigma should be not None.

Note

rho and logsigma, if not None, should have same shape as mu.

sample()[source]

Sampling function.

Returns:

A torch tensor of the same shape as \(\mu\) and \(\rho\) (or log{sigma}).

Return type:

torch.Tensor

log_prob(x)[source]

Evaluate the natural logarithm of the probability density function.

Parameters:

x (torch.Tensor) – An input tensor of same shape (or broadcastable to) as mu and rho (logsigma).

Returns:

scalar torch.Tensor.

Return type:

float

class quinn.rvar.rvs.GMM2_1d(pi, sigma1, sigma2)[source]

Bases: RV

One dimensional gaussian mixture random variable with two gaussians that have zero mean and user-defined standard deviations.

pi

Weight of the first gaussian. The second weight is 1-pi.

Type:

float

sigma1

Standard deviation of the first gaussian. Can also be a scalar torch.Tensor.

Type:

float

sigma2

Standard deviation of the second gaussian. Can also be a scalar torch.Tensor.

Type:

float

normal1

The underlying torch-based normal random variable for the first gaussian.

Type:

torch.distributions.Normal

normal2

The underlying torch-based normal random variable for the second gaussian.

Type:

torch.distributions.Normal

__init__(pi, sigma1, sigma2)[source]

Instantiation of the GMM2 object.

Parameters:
  • pi (float) – Weight of the first gaussian. The second weight is 1-pi.

  • sigma1 (float) – Standard deviation of the first gaussian. Can also be a scalar torch.Tensor.

  • sigma2 (float) – Standard deviation of the second gaussian. Can also be a scalar torch.Tensor.

log_prob(x)[source]

Evaluate the natural logarithm of the probability density function.

Parameters:

x (torch.Tensor) – An input tensor.

Returns:

scalar torch.Tensor.

Return type:

float