h0rton.losses.gaussian_nll_native

Module Contents

Classes

BaseGaussianNLLNative Abstract base class to represent the Gaussian negative log likelihood (NLLNative).
DiagonalGaussianNLLNative The negative log likelihood (NLLNative) for a single Gaussian with diagonal covariance matrix
LowRankGaussianNLLNative The negative log likelihood (NLLNative) for a single Gaussian with a full but constrained as low-rank plus diagonal covariance matrix
FullRankGaussianNLLNative The negative log likelihood (NLLNative) for a single Gaussian with a full-rank covariance matrix
DoubleLowRankGaussianNLLNative The negative log likelihood (NLLNative) for a mixture of two Gaussians, each with a full but constrained as low-rank plus diagonal covariance
DoubleGaussianNLLNative The negative log likelihood (NLLNative) for a mixture of two Gaussians, each with a full but constrained as low-rank plus diagonal covariance
class h0rton.losses.gaussian_nll_native.BaseGaussianNLLNative(Y_dim, device)[source]

Bases: abc.ABC

Abstract base class to represent the Gaussian negative log likelihood (NLLNative).

Gaussian NLLNatives or mixtures thereof with various forms of the covariance matrix inherit from this class.

slice(self, pred)[source]

Slice the raw network prediction into meaningful Gaussian parameters

pred : torch.Tensor of shape [batch_size, self.Y_dim]
the network prediction
__call__(self, pred, target)[source]

Evaluate the NLLNative. Must be overridden by subclasses.

pred : torch.Tensor
raw network output for the predictions
target : torch.Tensor
Y labels
nll_diagonal(self, target, mu, logvar)[source]

Evaluate the NLLNative for single Gaussian with diagonal covariance matrix

target : torch.Tensor of shape [batch_size, Y_dim]
Y labels
mu : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior
logvar : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the log of the diagonal elements of the covariance matrix
torch.Tensor of shape
NLL values
nll_low_rank(self, target, mu, logvar, F, reduce=True)[source]

Evaluate the NLLNative for a single Gaussian with a full but low-rank plus diagonal covariance matrix

target : torch.Tensor of shape [batch_size, Y_dim]
Y labels
mu : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior
logvar : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the log of the diagonal elements of the covariance matrix
F : torch.Tensor of shape [batch_size, rank*Y_dim]
network prediction of the low rank portion of the covariance matrix
reduce : bool
whether to take the mean across the batch
torch.Tensor of shape [batch_size,]
NLL values
nll_mixture_low_rank(self, target, mu, logvar, F, mu2, logvar2, F2, alpha)[source]

Evaluate the NLLNative for a single Gaussian with a full but low-rank plus diagonal covariance matrix Parameters ———- target : torch.Tensor of shape [batch_size, Y_dim]

Y labels
mu : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior for the first Gaussian
logvar : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the log of the diagonal elements of the covariance matrix for the first Gaussian
F : torch.Tensor of shape [batch_size, rank*Y_dim]
network prediction of the low rank portion of the covariance matrix for the first Gaussian
mu2 : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior for the second Gaussian
logvar2 : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the log of the diagonal elements of the covariance matrix for the second Gaussian
F2 : torch.Tensor of shape [batch_size, rank*Y_dim]
network prediction of the low rank portion of the covariance matrix for the second Gaussian
alpha : torch.Tensor of shape [batch_size, 1]
network prediction of the logit of twice the weight on the second Gaussian
reduce : bool
whether to take the mean across the batch

The weight on the second Gaussian is required to be less than 0.5, to make the two Gaussians well-defined. Returns ——- torch.Tensor of shape [batch_size,]

NLL values
nll_full_rank(self, target, mu, tril_elements, reduce=True)[source]

Evaluate the NLLNative for a single Gaussian with a full-rank covariance matrix

target : torch.Tensor of shape [batch_size, Y_dim]
Y labels
mu : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior

tril_elements : torch.Tensor of shape [batch_size, Y_dim*(Y_dim + 1)//2] reduce : bool

whether to take the mean across the batch
torch.Tensor of shape [batch_size,]
NLL values
nll_mixture(self, target, mu, tril_elements, mu2, tril_elements2, alpha)[source]

Evaluate the NLLNative for a single Gaussian with a full but low-rank plus diagonal covariance matrix

target : torch.Tensor of shape [batch_size, Y_dim]
Y labels
mu : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior for the first Gaussian
tril_elements : torch.Tensor of shape [batch_size, self.tril_len]
network prediction of the elements in the precision matrix
mu2 : torch.Tensor of shape [batch_size, Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior for the second Gaussian
tril_elements2 : torch.Tensor of shape [batch_size, self.tril_len]
network prediction of the elements in the precision matrix for the second Gaussian
alpha : torch.Tensor of shape [batch_size, 1]
network prediction of the logit of twice the weight on the second Gaussian

The weight on the second Gaussian is required to be less than 0.5, to make the two Gaussians well-defined.

torch.Tensor of shape [batch_size,]
NLL values
class h0rton.losses.gaussian_nll_native.DiagonalGaussianNLLNative(Y_dim, device)[source]

Bases: h0rton.losses.gaussian_nll_native.BaseGaussianNLLNative

The negative log likelihood (NLLNative) for a single Gaussian with diagonal covariance matrix

BaseGaussianNLLNative.__init__ docstring for the parameter description.

posterior_name = DiagonalGaussianBNNPosterior[source]
__call__(self, pred, target)[source]

Evaluate the NLLNative. Must be overridden by subclasses.

pred : torch.Tensor
raw network output for the predictions
target : torch.Tensor
Y labels
slice(self, pred)[source]

Slice the raw network prediction into meaningful Gaussian parameters

pred : torch.Tensor of shape [batch_size, self.Y_dim]
the network prediction
class h0rton.losses.gaussian_nll_native.LowRankGaussianNLLNative(Y_dim, device)[source]

Bases: h0rton.losses.gaussian_nll_native.BaseGaussianNLLNative

The negative log likelihood (NLLNative) for a single Gaussian with a full but constrained as low-rank plus diagonal covariance matrix

Only rank 2 is currently supported. BaseGaussianNLLNative.__init__ docstring for the parameter description.

posterior_name = LowRankGaussianBNNPosterior[source]
__call__(self, pred, target)[source]

Evaluate the NLLNative. Must be overridden by subclasses.

pred : torch.Tensor
raw network output for the predictions
target : torch.Tensor
Y labels
slice(self, pred)[source]

Slice the raw network prediction into meaningful Gaussian parameters

pred : torch.Tensor of shape [batch_size, self.Y_dim]
the network prediction
class h0rton.losses.gaussian_nll_native.FullRankGaussianNLLNative(Y_dim, device)[source]

Bases: h0rton.losses.gaussian_nll_native.BaseGaussianNLLNative

The negative log likelihood (NLLNative) for a single Gaussian with a full-rank covariance matrix

See BaseGaussianNLLNative.__init__ docstring for the parameter description.

posterior_name = FullRankGaussianBNNPosterior[source]
__call__(self, pred, target)[source]

Evaluate the NLLNative. Must be overridden by subclasses.

pred : torch.Tensor
raw network output for the predictions
target : torch.Tensor
Y labels
slice(self, pred)[source]

Slice the raw network prediction into meaningful Gaussian parameters

pred : torch.Tensor of shape [batch_size, self.Y_dim]
the network prediction
class h0rton.losses.gaussian_nll_native.DoubleLowRankGaussianNLLNative(Y_dim, device)[source]

Bases: h0rton.losses.gaussian_nll_native.BaseGaussianNLLNative

The negative log likelihood (NLLNative) for a mixture of two Gaussians, each with a full but constrained as low-rank plus diagonal covariance

Only rank 2 is currently supported. BaseGaussianNLLNative.__init__ docstring for the parameter description.

posterior_name = DoubleLowRankGaussianBNNPosterior[source]
__call__(self, pred, target)[source]

Evaluate the NLLNative. Must be overridden by subclasses.

pred : torch.Tensor
raw network output for the predictions
target : torch.Tensor
Y labels
slice(self, pred)[source]

Slice the raw network prediction into meaningful Gaussian parameters

pred : torch.Tensor of shape [batch_size, self.Y_dim]
the network prediction
class h0rton.losses.gaussian_nll_native.DoubleGaussianNLLNative(Y_dim, device)[source]

Bases: h0rton.losses.gaussian_nll_native.BaseGaussianNLLNative

The negative log likelihood (NLLNative) for a mixture of two Gaussians, each with a full but constrained as low-rank plus diagonal covariance

Only rank 2 is currently supported. BaseGaussianNLLNative.__init__ docstring for the parameter description.

posterior_name = DoubleGaussianBNNPosterior[source]
__call__(self, pred, target)[source]

Evaluate the NLLNative. Must be overridden by subclasses.

pred : torch.Tensor
raw network output for the predictions
target : torch.Tensor
Y labels
slice(self, pred)[source]

Slice the raw network prediction into meaningful Gaussian parameters

pred : torch.Tensor of shape [batch_size, self.Y_dim]
the network prediction