dgmr¶
Module for various loss functions used with DGMR GAN.
- class mfai.pytorch.losses.dgmr.GridCellLoss(precip_weight_cap)[source]¶
Bases:
ModuleGrid Cell Regularizer loss from Skillful Nowcasting, see equation (3) of the original paper (https://arxiv.org/pdf/2104.00954.pdf).
- Parameters:
precip_weight_cap (float)
- forward(generated_images, targets)[source]¶
Forward function.
Calculates the grid cell regularizer value, assumes generated images are the mean predictions from 6 calls to the generator (Monte Carlo estimation of the expectations for the latent variable).
\[\begin{split}L_R(\Theta) = \frac{1}{HWN} \\| (\mathbb{E}_Z [G_|theta(Z; X_{1:M})] - X_{M+1:M+T}) \circ w(X_{M+1:M+T}) \\|_1\end{split}\]where H, W and T represent height, width and leadtimes.
Note
Instead of apply the formula of the weights describe in the original article (\(w(y) = max(y+1, precip\_weight\_cap)\)), we implement a formula closer to the pseudocode released by Google Deepmind. So our formula is : \(w(y) = clip(y, 1, precip\_weight\_cap)\), which mean that weights are between 1 and precip_weight_cap.