code: def multiscale_structural_similarity(
      preds: Tensor,
      target: Tensor,
      data_range: float = 1.0,
      window_size: int = 11,
      k1: float = 0.01,
      k2: float = 0.03,
      gaussian_std: float = 1.5,
      power_factors: Sequence[float] = MS_SSIM_FACTORS,
      reduction: str = "mean",
  ) -> Tensor:
      """
      Computes the multi-scale structural similarity index measure.
  
      Follows the algorithm in the paper: Wang, Zhou, Eero P. Simoncelli,
      and Alan C. Bovik. "Multiscale structural similarity for image
      quality assessment." Signals, Systems and Computers, 2004.
      https://www.cns.nyu.edu/pub/eero/wang03b.pdf
  
      Args:
          preds: a batch of target image approximations.
          target: a batch of images to compare preds against.
          data_range: dynamic range of the input tensors.
          window_size: window size for SSIM calculation.
          k1: k1 parameter for SSIM calculation.
          k2: k2 parameter for SSIM calculation.
          gaussian_std: standard deviation of Gaussian filter to use in SSIM
              calculations.
          power_factors: relative importance of each scale; defaults to
              the values proposed in the paper; the length of
              power_factors determines how many scales to consider.
          reduction: specifies the reduction to apply across batches:
              ``'none'`` | ``'mean'`` | ``'sum'``. ``'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.
  
      Returns:
          The MS-SSIM score between ``preds`` and ``target``, reduced across
          batches as specified by the ``reduction`` argument.
      """
  
      num_scales = len(power_factors)
  
      scale_outputs = []
      for scale in range(num_scales):
          if scale != 0:
              preds = _pad_and_downsample(preds)
              target = _pad_and_downsample(target)
  
          if (
              preds.shape[2] < window_size
              or preds.shape[3] < window_size
          ):
              raise RuntimeError(
                  f"After {scale} rounds of downsampling, the "
                  f"images to compare have a shape of {preds.shape}, which is "
                  f"smaller than the window size of {window_size}. Please "
                  "use larger images or a smaller window size."
              )
  
          # relu improves numerical stability, cs cannot be negative
          # but might be very close to zero
          scale_outputs.append(
              F.relu(
                  _ssim_multichannel(
                      x=preds,
                      y=target,
                      data_range=data_range,
                      window_size=window_size,
                      k1=k1,
                      k2=k2,
                      gaussian_std=gaussian_std,
                  )
              ).pow(power_factors[scale])
          )
  
      # shape is [num_scales, num_channels, 2 (ssim, cs), batch size]
      weighted_outputs = torch.stack(scale_outputs)
  
      # shape is [num_channels, batch_size]
      ms_ssim = weighted_outputs[-1, :, 0] * torch.prod(
          weighted_outputs[:-1, :, 1], dim=0
      )
  
      # mean over channels, reduction across batches
      reduction_op = _get_reduction_op(reduction)
      return reduction_op(ms_ssim.mean(dim=0))
  
file_path: NeuralCompression/neuralcompression/functional/_multiscale_structural_similarity.py
imports: from typing import Callable, Optional, Sequence
  import torch
  from torch import Tensor
  from torch.nn import functional
label_desc: Use image node_id 6 for calling a global function with example usage: multiscale_structural_similarity(preds, target, data_range, window_size, k1, k2, gaussian_std, power_factors, reduction) and returns: reduction_op