lfxai.utils.math module

log_density_gaussian(x, mu, logvar)

Calculates log density of a Gaussian.

Parameters:

x: torch.Tensor or np.ndarray or float

Value at which to compute the density.

mu: torch.Tensor or np.ndarray or float

Mean.

logvar: torch.Tensor or np.ndarray or float

Log variance.

log_importance_weight_matrix(batch_size, dataset_size)

Calculates a log importance weight matrix

Parameters:

batch_size: int

number of training images in the batch

dataset_size: int

number of training images in the dataset

matrix_log_density_gaussian(x, mu, logvar)

Calculates log density of a Gaussian for all combination of bacth pairs of x and mu. I.e. return tensor of shape (batch_size, batch_size, dim) instead of (batch_size, dim) in the usual log density.

Parameters:

x: torch.Tensor

Value at which to compute the density. Shape: (batch_size, dim).

mu: torch.Tensor

Mean. Shape: (batch_size, dim).

logvar: torch.Tensor

Log variance. Shape: (batch_size, dim).

batch_size: int

number of training images in the batch