def forward(hidden_variables: list[Tensor], jacobians: list[Tensor]) -> Tensor:
        """Calculate the UFlow loss.

        Args:
            hidden_variables (list[Tensor]): List of hidden variable tensors from the
                normalizing flow transformation f: X -> Z. Each tensor has shape
                ``(batch_size, channels, height, width)``.
            jacobians (list[Tensor]): List of log Jacobian determinant tensors from the
                flow transformation. Each tensor has shape ``(batch_size,)``.

        Returns:
            Tensor: Scalar loss value combining the likelihood of hidden variables and
                the log Jacobian determinants.
        """
        lpz = torch.sum(torch.stack([0.5 * torch.sum(z_i**2, dim=(1, 2, 3)) for z_i in hidden_variables], dim=0))
        return torch.mean(lpz - jacobians)
Calculate the UFlow loss.

        Args:
            hidden_variables (list[Tensor]): List of hidden variable tensors from the
                normalizing flow transformation f: X -> Z. Each tensor has shape
                ``(batch_size, channels, height, width)``.
            jacobians (list[Tensor]): List of log Jacobian determinant tensors from the
                flow transformation. Each tensor has shape ``(batch_size,)``.

        Returns:
            Tensor: Scalar loss value combining the likelihood of hidden variables and
                the log Jacobian determinants.
        
src/anomalib/models/image/uflow/loss.py