h0rton.h0_inference.gaussian_bnn_posterior

Module Contents

Classes

BaseGaussianBNNPosterior Abstract base class to represent the Gaussian BNN posterior
DiagonalGaussianBNNPosterior The negative log likelihood (NLL) for a single Gaussian with diagonal covariance matrix
LowRankGaussianBNNPosterior The negative log likelihood (NLL) for a single Gaussian with diagonal covariance matrix
DoubleLowRankGaussianBNNPosterior The negative log likelihood (NLL) for a single Gaussian with diagonal covariance matrix
FullRankGaussianBNNPosterior The negative log likelihood (NLL) for a single Gaussian with diagonal covariance matrix
DoubleGaussianBNNPosterior The negative log likelihood (NLL) for a single Gaussian with diagonal covariance matrix
class h0rton.h0_inference.gaussian_bnn_posterior.BaseGaussianBNNPosterior(Y_dim, device, Y_mean=None, Y_std=None)[source]

Bases: abc.ABC

Abstract base class to represent the Gaussian BNN posterior

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

seed_samples(self, sample_seed)[source]

Seed the sampling for reproducibility

sample_seed : int

sample(self, n_samples, sample_seed=None)[source]

Sample from the Gaussian posterior. Must be overridden by subclasses.

n_samples : int
how many samples to obtain
sample_seed : int
seed for the samples. Default: None
np.array of shape [n_samples, self.Y_dim]
samples
get_hpd_interval(self)[source]

Get the highest posterior density (HPD) interval

transform_back_mu(self, tensor)[source]

Transform back, i.e. unwhiten, the tensor of central values

tensor : torch.Tensor of shape [batch_size, Y_dim]

torch.tensor of shape [batch_size, Y_dim]
the original tensor
transform_back_logvar(self, logvar)[source]

Transform back, i.e. unwhiten, the tensor of predicted log of the diagonal entries of the cov mat

tensor : torch.Tensor of shape [batch_size, Y_dim]

torch.tensor of shape [batch_size, Y_dim]
the original tensor
transform_back_cov_mat(self, cov_mat)[source]

Transform back, i.e. unwhiten, the tensor of predicted covariance matrix

tensor : torch.Tensor of shape [batch_size, Y_dim, Y_dim]

torch.tensor of shape [batch_size, Y_dim]
the original tensor
unwhiten_back(self, sample)[source]

Scale and shift back to the unwhitened state

pred : torch.Tensor
network prediction of shape [batch_size, n_samples, self.Y_dim]
torch.Tensor
the unwhitened pred
sample_low_rank(self, n_samples, mu, logvar, F)[source]

Sample from a single Gaussian posterior with a full but low-rank plus diagonal covariance matrix

n_samples : int
how many samples to obtain
mu : torch.Tensor of shape [self.batch_size, self.Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior
logvar : torch.Tensor of shape [self.batch_size, self.Y_dim]
network prediction of the log of the diagonal elements of the covariance matrix
F : torch.Tensor of shape [self.batch_size, self.Y_dim, self.rank]
network prediction of the low rank portion of the covariance matrix
np.array of shape [self.batch_size, n_samples, self.Y_dim]
samples
sample_full_rank(self, n_samples, mu, tril_elements, as_numpy=True)[source]

Sample from a single Gaussian posterior with a full-rank covariance matrix

n_samples : int
how many samples to obtain
mu : torch.Tensor of shape [self.batch_size, self.Y_dim]
network prediction of the mu (mean parameter) of the BNN posterior
tril_elements : torch.Tensor of shape [self.batch_size, tril_len]
network prediction of lower-triangular matrix in the log-Cholesky decomposition of the precision matrix
np.array of shape [self.batch_size, n_samples, self.Y_dim]
samples
class h0rton.h0_inference.gaussian_bnn_posterior.DiagonalGaussianBNNPosterior(Y_dim, device, Y_mean=None, Y_std=None)[source]

Bases: h0rton.h0_inference.gaussian_bnn_posterior.BaseGaussianBNNPosterior

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

BaseGaussianNLL.__init__ docstring for the parameter description.

set_sliced_pred(self, pred)[source]
sample(self, n_samples, sample_seed)[source]

Sample from a Gaussian posterior with diagonal covariance matrix

n_samples : int
how many samples to obtain
sample_seed : int
seed for the samples. Default: None
np.array of shape [n_samples, self.Y_dim]
samples
get_hpd_interval(self)[source]

Get the highest posterior density (HPD) interval

class h0rton.h0_inference.gaussian_bnn_posterior.LowRankGaussianBNNPosterior(Y_dim, device, Y_mean=None, Y_std=None)[source]

Bases: h0rton.h0_inference.gaussian_bnn_posterior.BaseGaussianBNNPosterior

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

BaseGaussianNLL.__init__ docstring for the parameter description.

set_sliced_pred(self, pred)[source]
sample(self, n_samples, sample_seed)[source]

Sample from the Gaussian posterior. Must be overridden by subclasses.

n_samples : int
how many samples to obtain
sample_seed : int
seed for the samples. Default: None
np.array of shape [n_samples, self.Y_dim]
samples
get_hpd_interval(self)[source]

Get the highest posterior density (HPD) interval

class h0rton.h0_inference.gaussian_bnn_posterior.DoubleLowRankGaussianBNNPosterior(Y_dim, device, Y_mean=None, Y_std=None)[source]

Bases: h0rton.h0_inference.gaussian_bnn_posterior.BaseGaussianBNNPosterior

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

BaseGaussianNLL.__init__ docstring for the parameter description.

set_sliced_pred(self, pred)[source]
sample(self, n_samples, sample_seed)[source]

Sample from a mixture of two Gaussians, each with a full but constrained as low-rank plus diagonal covariance

n_samples : int
how many samples to obtain
sample_seed : int
seed for the samples. Default: None
np.array of shape [self.batch_size, n_samples, self.Y_dim]
samples
get_hpd_interval(self)[source]

Get the highest posterior density (HPD) interval

class h0rton.h0_inference.gaussian_bnn_posterior.FullRankGaussianBNNPosterior(Y_dim, device, Y_mean=None, Y_std=None)[source]

Bases: h0rton.h0_inference.gaussian_bnn_posterior.BaseGaussianBNNPosterior

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

BaseGaussianNLL.__init__ docstring for the parameter description.

set_sliced_pred(self, pred)[source]
sample(self, n_samples, sample_seed)[source]

Sample from the Gaussian posterior. Must be overridden by subclasses.

n_samples : int
how many samples to obtain
sample_seed : int
seed for the samples. Default: None
np.array of shape [n_samples, self.Y_dim]
samples
get_hpd_interval(self)[source]

Get the highest posterior density (HPD) interval

class h0rton.h0_inference.gaussian_bnn_posterior.DoubleGaussianBNNPosterior(Y_dim, device, Y_mean=None, Y_std=None)[source]

Bases: h0rton.h0_inference.gaussian_bnn_posterior.BaseGaussianBNNPosterior

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

BaseGaussianNLL.__init__ docstring for the parameter description.

set_sliced_pred(self, pred)[source]
sample(self, n_samples, sample_seed)[source]

Sample from a mixture of two Gaussians, each with a full but constrained as low-rank plus diagonal covariance

n_samples : int
how many samples to obtain
sample_seed : int
seed for the samples. Default: None
np.array of shape [self.batch_size, n_samples, self.Y_dim]
samples
get_hpd_interval(self)[source]

Get the highest posterior density (HPD) interval