class_docstr: Differentiable global mutual information loss via Parzen windowing method.
  
  Reference:
      https://dspace.mit.edu/handle/1721.1/123142, Section 3.1, equation 3.1-3.5, Algorithm 1
class_docstr_tok: ["Differentiable","global","mutual","information","loss","via","Parzen","windowing","method",".","Reference",":","https",":","\/\/dspace.mit.edu\/handle\/1721.1\/123142",",","Section","3.1",",","equation","3.1-3.5",",","Algorithm","1"]
docstr: Args:
      kernel_type: {``"gaussian"``, ``"b-spline"``}
          ``"gaussian"``: adapted from DeepReg
          Reference: https://dspace.mit.edu/handle/1721.1/123142, Section 3.1, equation 3.1-3.5, Algorithm 1.
          ``"b-spline"``: based on the method of Mattes et al [1,2] and adapted from ITK
          References:
            [1] "Nonrigid multimodality image registration"
                D. Mattes, D. R. Haynor, H. Vesselle, T. Lewellen and W. Eubank
                Medical Imaging 2001: Image Processing, 2001, pp. 1609-1620.
            [2] "PET-CT Image Registration in the Chest Using Free-form Deformations"
                D. Mattes, D. R. Haynor, H. Vesselle, T. Lewellen and W. Eubank
                IEEE Transactions in Medical Imaging. Vol.22, No.1,
                January 2003. pp.120-128.
  
      num_bins: number of bins for intensity
      sigma_ratio: a hyper param for gaussian function
      reduction: {``"none"``, ``"mean"``, ``"sum"``}
          Specifies the reduction to apply to the output. Defaults to ``"mean"``.
  
          - ``"none"``: no reduction will be applied.
          - ``"mean"``: the sum of the output will be divided by the number of elements in the output.
          - ``"sum"``: the output will be summed.
      smooth_nr: a small constant added to the numerator to avoid nan.
      smooth_dr: a small constant added to the denominator to avoid nan.
docstr_tok: ["Args",":","kernel_type",":","{","``","``","gaussian","''","``",",","``","``","b-spline","''","``","}","``","``","gaussian","''","``",":","adapted","from","DeepReg","Reference",":","https",":","\/\/dspace.mit.edu\/handle\/1721.1\/123142",",","Section","3.1",",","equation","3.1-3.5",",","Algorithm","1",".","``","``","b-spline","''","``",":","based","on","the","method","of","Mattes","et","al","[","1,2","]","and","adapted","from","ITK","References",":","[","1","]","``","Nonrigid","multimodality","image","registration","''","D.","Mattes",",","D.","R.","Haynor",",","H.","Vesselle",",","T.","Lewellen","and","W.","Eubank","Medical","Imaging","2001",":","Image","Processing",",","2001",",","pp",".","1609-1620",".","[","2","]","``","PET-CT","Image","Registration","in","the","Chest","Using","Free-form","Deformations","''","D.","Mattes",",","D.","R.","Haynor",",","H.","Vesselle",",","T.","Lewellen","and","W.","Eubank","IEEE","Transactions","in","Medical","Imaging",".","Vol.22",",","No.1",",","January","2003.","pp.120-128",".","num_bins",":","number","of","bins","for","intensity","sigma_ratio",":","a","hyper","param","for","gaussian","function","reduction",":","{","``","``","none","''","``",",","``","``","mean","''","``",",","``","``","sum","''","``","}","Specifies","the","reduction","to","apply","to","the","output",".","Defaults","to","``","``","mean","''","``",".","-","``","``","none","''","``",":","no","reduction","will","be","applied",".","-","``","``","mean","''","``",":","the","sum","of","the","output","will","be","divided","by","the","number","of","elements","in","the","output",".","-","``","``","sum","''","``",":","the","output","will","be","summed",".","smooth_nr",":","a","small","constant","added","to","the","numerator","to","avoid","nan",".","smooth_dr",":","a","small","constant","added","to","the","denominator","to","avoid","nan","."]
code: def __init__(
      self,
      kernel_type: str = "gaussian",
      num_bins: int = 23,
      sigma_ratio: float = 0.5,
      reduction: LossReduction | str = LossReduction.MEAN,
      smooth_nr: float = 1e-7,
      smooth_dr: float = 1e-7,
  ) -> None:
      """
      Args:
          kernel_type: {``"gaussian"``, ``"b-spline"``}
              ``"gaussian"``: adapted from DeepReg
              Reference: https://dspace.mit.edu/handle/1721.1/123142, Section 3.1, equation 3.1-3.5, Algorithm 1.
              ``"b-spline"``: based on the method of Mattes et al [1,2] and adapted from ITK
              References:
                [1] "Nonrigid multimodality image registration"
                    D. Mattes, D. R. Haynor, H. Vesselle, T. Lewellen and W. Eubank
                    Medical Imaging 2001: Image Processing, 2001, pp. 1609-1620.
                [2] "PET-CT Image Registration in the Chest Using Free-form Deformations"
                    D. Mattes, D. R. Haynor, H. Vesselle, T. Lewellen and W. Eubank
                    IEEE Transactions in Medical Imaging. Vol.22, No.1,
                    January 2003. pp.120-128.
  
          num_bins: number of bins for intensity
          sigma_ratio: a hyper param for gaussian function
          reduction: {``"none"``, ``"mean"``, ``"sum"``}
              Specifies the reduction to apply to the output. Defaults to ``"mean"``.
  
              - ``"none"``: no reduction will be applied.
              - ``"mean"``: the sum of the output will be divided by the number of elements in the output.
              - ``"sum"``: the output will be summed.
          smooth_nr: a small constant added to the numerator to avoid nan.
          smooth_dr: a small constant added to the denominator to avoid nan.
      """
      super().__init__(reduction=LossReduction(reduction).value)
      if num_bins <= 0:
          raise ValueError("num_bins must > 0, got {num_bins}")
      bin_centers = torch.linspace(0.0, 1.0, num_bins)  # (num_bins,)
      sigma = (
          torch.mean(bin_centers[1:] - bin_centers[:-1]) * sigma_ratio
      )
      self.kernel_type = look_up_option(
          kernel_type, ["gaussian", "b-spline"]
      )
      self.num_bins = num_bins
      self.kernel_type = kernel_type
      if self.kernel_type == "gaussian":
          self.preterm = 1 / (2 * sigma**2)
          self.bin_centers = bin_centers[None, None, ...]
      self.smooth_nr = float(smooth_nr)
      self.smooth_dr = float(smooth_dr)
  
imports: from __future__ import annotations
  import torch
  from torch.nn import functional
  from torch.nn.modules.loss import _Loss
  from monai.networks.layers import gaussian_1d, separable_filtering
  from monai.utils import LossReduction
  from monai.utils.module import look_up_option
label_desc: Use image node_id 1 to create a new GlobalMutualInformationLoss object from inherited base classes: _Loss with example: obj = GlobalMutualInformationLoss(kernel_type, num_bins, sigma_ratio, reduction, smooth_nr, smooth_dr)