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>
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.
◆ GaussianNLLLoss()
| pulsatrix::GaussianNLLLoss::GaussianNLLLoss |
( |
DeviceBackend * |
backend, |
|
|
double |
min_variance = 1e-6 |
|
) |
| |
|
explicit |
- Parameters
-
| backend | Backend to allocate the gradient through. Not owned; must outlive this loss. |
| min_variance | Added to softplus(s); Lakshminarayanan et al. used 1e-6. |
- Exceptions
-
| std::invalid_argument | if min_variance isn't positive. |
◆ backward()
| Tensor pulsatrix::GaussianNLLLoss::backward |
( |
| ) |
const |
The gradient with respect to the prediction, (N, 2).
- Exceptions
-
| std::logic_error | if 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_argument | on 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: