pulsatrix 1.1.0
Loading...
Searching...
No Matches
pulsatrix::GaussianNLLLoss Class Reference

The Gaussian negative log likelihood, for regressors that predict their own noise (Nix and Weigend, 1994; Lakshminarayanan et al., 2017): the network outputs two values per input, a mean mu and s, and its variance is softplus(s) + min_variance, which keeps it positive. More...

#include <uncertainty.hpp>

Public Member Functions

 GaussianNLLLoss (DeviceBackend *backend, double min_variance=1e-6)
 
float forward (const Tensor &prediction, const Tensor &target)
 
Tensor backward () const
 The gradient with respect to the prediction, (N, 2).
 
double variance (double s) const
 The variance a prediction's s gives: softplus(s) + min_variance.
 

Detailed Description

The Gaussian negative log likelihood, for regressors that predict their own noise (Nix and Weigend, 1994; Lakshminarayanan et al., 2017): the network outputs two values per input, a mean mu and s, and its variance is softplus(s) + min_variance, which keeps it positive.

loss = mean_n 0.5 (log var_n + (y_n - mu_n)^2 / var_n), PyTorch's GaussianNLLLoss with full=False on that variance.

Note
Not a Module, like the other losses. It computes on the host and returns the gradient on the prediction's device.

Constructor & Destructor Documentation

◆ GaussianNLLLoss()

pulsatrix::GaussianNLLLoss::GaussianNLLLoss ( DeviceBackend *  backend,
double  min_variance = 1e-6 
)
explicit
Parameters
backendBackend to allocate the gradient through. Not owned; must outlive this loss.
min_varianceAdded to softplus(s); Lakshminarayanan et al. used 1e-6.
Exceptions
std::invalid_argumentif min_variance isn't positive.

Member Function Documentation

◆ backward()

Tensor pulsatrix::GaussianNLLLoss::backward ( ) const

The gradient with respect to the prediction, (N, 2).

Exceptions
std::logic_errorif forward() hasn't been called.

◆ forward()

float pulsatrix::GaussianNLLLoss::forward ( const Tensor &  prediction,
const Tensor &  target 
)
Parameters
prediction(N, 2): the mean, then s, for each input.
target(N, 1) or (N).
Returns
The loss.
Exceptions
std::invalid_argumenton other shapes or a value that isn't finite.

◆ variance()

double pulsatrix::GaussianNLLLoss::variance ( double  s) const

The variance a prediction's s gives: softplus(s) + min_variance.


The documentation for this class was generated from the following file: