n2j.losses#

Submodules#

Package 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

MSELoss

class n2j.losses.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'#
__call__(pred, target)#

Evaluate the NLL. Must be overridden by subclasses.

Parameters#

predtorch.Tensor

raw network output for the predictions

targettorch.Tensor

Y labels

slice(pred)#

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)#
sample(mean, std, n_samples, sample_seed)#

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.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'#
__call__(pred, target)#

Evaluate the NLL. Must be overridden by subclasses.

Parameters#

predtorch.Tensor

raw network output for the predictions

targettorch.Tensor

Y labels

slice(pred)#

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)#
sample(mean, std, n_samples, sample_seed)#
class n2j.losses.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'#
__call__(pred, target)#

Evaluate the NLL. Must be overridden by subclasses.

Parameters#

predtorch.Tensor

raw network output for the predictions

targettorch.Tensor

Y labels

slice(pred)#

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)#
sample(mean, std, n_samples, sample_seed)#

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

class n2j.losses.MSELoss[source]#
__call__(pred, target)#