n2j.losses.nll#

Gaussian mixture negative log likelihoods that can be evaluated, for use as loss functions, but also generate samples when parameters are given

Module Contents#

Classes#

DiagonalGaussianNLL

The negative log likelihood (NLL) for a single Gaussian with diagonal

FullRankGaussianNLL

The negative log likelihood (NLL) for a single Gaussian with a full-rank

DoubleGaussianNLL

The negative log likelihood (NLL) for a mixture of two Gaussians, each

class n2j.losses.nll.DiagonalGaussianNLL(Y_dim, device)[source]#

Bases: BaseGaussianNLL

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

BaseGaussianNLL.__init__ docstring for the parameter description.

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

Evaluate the NLL. Must be overridden by subclasses.

Parameters#

predtorch.Tensor

raw network output for the predictions

targettorch.Tensor

Y labels

slice(pred)[source]#

Slice the raw network prediction into meaningful Gaussian parameters

Parameters#

predtorch.Tensor of shape [batch_size, self.Y_dim]

the network prediction

set_trained_pred(pred)[source]#
sample(mean, std, n_samples, sample_seed)[source]#

Sample from a Gaussian posterior with diagonal covariance matrix Parameters ———- n_samples : int

how many samples to obtain

sample_seedint

seed for the samples. Default: None

Returns#

np.array of shape [batch_size, n_samples, self.Y_dim]

samples

class n2j.losses.nll.FullRankGaussianNLL(Y_dim, device)[source]#

Bases: BaseGaussianNLL

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

See BaseGaussianNLL.__init__ docstring for the parameter description.

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

Evaluate the NLL. Must be overridden by subclasses.

Parameters#

predtorch.Tensor

raw network output for the predictions

targettorch.Tensor

Y labels

slice(pred)[source]#

Slice the raw network prediction into meaningful Gaussian parameters

Parameters#

predtorch.Tensor of shape [batch_size, self.Y_dim]

the network prediction

set_trained_pred(pred)[source]#
sample(mean, std, n_samples, sample_seed)[source]#
class n2j.losses.nll.DoubleGaussianNLL(Y_dim, device)[source]#

Bases: BaseGaussianNLL

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

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

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

Evaluate the NLL. Must be overridden by subclasses.

Parameters#

predtorch.Tensor

raw network output for the predictions

targettorch.Tensor

Y labels

slice(pred)[source]#

Slice the raw network prediction into meaningful Gaussian parameters

Parameters#

predtorch.Tensor of shape [batch_size, self.Y_dim]

the network prediction

set_trained_pred(pred)[source]#
sample(mean, std, n_samples, sample_seed)[source]#

Sample from a mixture of two Gaussians, each with a full covariance

Parameters#

n_samplesint

how many samples to obtain

sample_seedint

seed for the samples. Default: None

Returns#

np.array of shape [self.batch_size, n_samples, self.Y_dim]

samples