h0rton.losses.gaussian_nll_cpu
¶
Module Contents¶
Classes¶
BaseGaussianNLLCPU |
Abstract base class to represent the Gaussian negative log likelihood (NLL). |
DiagonalGaussianNLLCPU |
The negative log likelihood (NLL) for a single Gaussian with diagonal covariance matrix |
FullRankGaussianNLLCPU |
The negative log likelihood (NLL) for a single Gaussian with a full-rank covariance matrix |
DoubleGaussianNLLCPU |
The negative log likelihood (NLL) for a mixture of two Gaussians, each with a full but constrained as low-rank plus diagonal covariance |
-
class
h0rton.losses.gaussian_nll_cpu.
BaseGaussianNLLCPU
(Y_dim)[source]¶ Bases:
abc.ABC
Abstract base class to represent the Gaussian negative log likelihood (NLL).
Gaussian NLLs 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 : np.Tensor of shape [batch_size, self.Y_dim]
- the network prediction
-
__call__
(self, pred, target)[source]¶ Evaluate the NLL. Must be overridden by subclasses.
- pred : np.Tensor
- raw network output for the predictions
- target : np.Tensor
- Y labels
-
nll_diagonal
(self, target, mu, logvar)[source]¶ Evaluate the NLL for single Gaussian with diagonal covariance matrix
- target : np.Tensor of shape [batch_size, Y_dim]
- Y labels
- mu : np.Tensor of shape [batch_size, Y_dim]
- network prediction of the mu (mean parameter) of the BNN posterior
- logvar : np.Tensor of shape [batch_size, Y_dim]
- network prediction of the log of the diagonal elements of the covariance matrix
- np.Tensor of shape
- NLL values
-
nll_full_rank
(self, target, mu, tril_elements, reduce=True)[source]¶ Evaluate the NLL for a single Gaussian with a full-rank covariance matrix
- target : np.Tensor of shape [batch_size, Y_dim]
- Y labels
- mu : np.Tensor of shape [batch_size, Y_dim]
- network prediction of the mu (mean parameter) of the BNN posterior
tril_elements : np.Tensor of shape [batch_size, Y_dim*(Y_dim + 1)//2] reduce : bool
whether to take the mean across the batch- np.Tensor of shape [batch_size,]
- NLL values
-
nll_mixture
(self, target, mu, tril_elements, mu2, tril_elements2, alpha)[source]¶ Evaluate the NLL for a single Gaussian with a full but low-rank plus diagonal covariance matrix
- target : np.Tensor of shape [batch_size, Y_dim]
- Y labels
- mu : np.Tensor of shape [batch_size, Y_dim]
- network prediction of the mu (mean parameter) of the BNN posterior for the first Gaussian
- tril_elements : np.Tensor of shape [batch_size, self.tril_len]
- network prediction of the elements in the precision matrix
- mu2 : np.Tensor of shape [batch_size, Y_dim]
- network prediction of the mu (mean parameter) of the BNN posterior for the second Gaussian
- tril_elements2 : np.Tensor of shape [batch_size, self.tril_len]
- network prediction of the elements in the precision matrix for the second Gaussian
- alpha : np.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.
- np.Tensor of shape [batch_size,]
- NLL values
-
-
class
h0rton.losses.gaussian_nll_cpu.
DiagonalGaussianNLLCPU
(Y_dim)[source]¶ Bases:
h0rton.losses.gaussian_nll_cpu.BaseGaussianNLLCPU
The negative log likelihood (NLL) for a single Gaussian with diagonal covariance matrix
BaseGaussianNLLCPU.__init__ docstring for the parameter description.
-
class
h0rton.losses.gaussian_nll_cpu.
FullRankGaussianNLLCPU
(Y_dim)[source]¶ Bases:
h0rton.losses.gaussian_nll_cpu.BaseGaussianNLLCPU
The negative log likelihood (NLL) for a single Gaussian with a full-rank covariance matrix
See BaseGaussianNLLCPU.__init__ docstring for the parameter description.
-
class
h0rton.losses.gaussian_nll_cpu.
DoubleGaussianNLLCPU
(Y_dim)[source]¶ Bases:
h0rton.losses.gaussian_nll_cpu.BaseGaussianNLLCPU
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. BaseGaussianNLLCPU.__init__ docstring for the parameter description.