PythiloLesson 5 of 8 · progress kept in this browser

Practice in Lab: Fit a positive heteroscedastic Gaussian likelihood →

Fit a positive heteroscedastic Gaussian likelihood

A regression model can learn both a conditional mean and input-dependent noise. Gaussian likelihood rewards a good mean but also penalizes excessive variance, unlike simply enlarging every interval. An unconstrained raw output is transformed into a positive variance before any logarithm or division. Very negative raw values test the numerical behavior at the floor. The learned quantity is aleatoric uncertainty under this likelihood assumption; it does not include model uncertainty or automatically provide calibrated prediction intervals.

Your task

Use variance=softplus(raw_variance)+floor and return mean(0.5*(log(2*pi)+log(variance)+(target-mean)**2/variance)). Preserve gradients through both mean and raw variance. Require aligned nonempty finite floating tensors and finite floor>0. The floor is part of the declared model; do not clamp a negative variance after taking its logarithm.

This lesson uses torch, which Python in this browser does not include. Read it here, and run and check it in the Pythilo app on iPhone or iPad.