:py:mod:`n2j.losses.gaussian_nll` ================================= .. py:module:: n2j.losses.gaussian_nll .. autoapi-nested-parse:: 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 ~~~~~~~ .. autoapisummary:: n2j.losses.gaussian_nll.DiagonalGaussianNLL n2j.losses.gaussian_nll.FullRankGaussianNLL n2j.losses.gaussian_nll.DoubleGaussianNLL .. py:class:: DiagonalGaussianNLL(Y_dim) Bases: :py:obj:`BaseGaussianNLL` The negative log likelihood (NLL) for a single Gaussian with diagonal covariance matrix `BaseGaussianNLL.__init__` docstring for the parameter description. .. py:attribute:: posterior_name :value: 'DiagonalGaussianBNNPosterior' .. py:method:: __call__(pred, target) Evaluate the NLL. Must be overridden by subclasses. Parameters ---------- pred : torch.Tensor raw network output for the predictions target : torch.Tensor Y labels .. py:method:: slice(pred) Slice the raw network prediction into meaningful Gaussian parameters Parameters ---------- pred : torch.Tensor of shape `[batch_size, self.Y_dim]` the network prediction .. py:method:: set_trained_pred(pred) .. py:method:: sample(mean, std, n_samples) Sample from a Gaussian posterior with diagonal covariance matrix Parameters ---------- n_samples : int how many samples to obtain sample_seed : int seed for the samples. Default: None Returns ------- np.array of shape `[batch_size, n_samples, self.Y_dim]` samples .. py:class:: FullRankGaussianNLL(Y_dim) Bases: :py:obj:`BaseGaussianNLL` The negative log likelihood (NLL) for a single Gaussian with a full-rank covariance matrix See `BaseGaussianNLL.__init__` docstring for the parameter description. .. py:attribute:: posterior_name :value: 'FullRankGaussianBNNPosterior' .. py:method:: __call__(pred, target) Evaluate the NLL. Must be overridden by subclasses. Parameters ---------- pred : torch.Tensor raw network output for the predictions target : torch.Tensor Y labels .. py:method:: slice(pred) Slice the raw network prediction into meaningful Gaussian parameters Parameters ---------- pred : torch.Tensor of shape `[batch_size, self.Y_dim]` the network prediction .. py:method:: set_trained_pred(pred) .. py:method:: sample(mean, std, n_samples) .. py:class:: DoubleGaussianNLL(Y_dim) Bases: :py:obj:`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. .. py:attribute:: posterior_name :value: 'DoubleGaussianBNNPosterior' .. py:method:: __call__(pred, target) Evaluate the NLL. Must be overridden by subclasses. Parameters ---------- pred : torch.Tensor raw network output for the predictions target : torch.Tensor Y labels .. py:method:: slice(pred) Slice the raw network prediction into meaningful Gaussian parameters Parameters ---------- pred : torch.Tensor of shape `[batch_size, self.Y_dim]` the network prediction .. py:method:: set_trained_pred(pred) .. py:method:: sample(mean, std, n_samples) Sample from a mixture of two Gaussians, each with a full covariance Parameters ---------- n_samples : int how many samples to obtain sample_seed : int seed for the samples. Default: None Returns ------- np.array of shape `[self.batch_size, n_samples, self.Y_dim]` samples