class_docstr: Mean absolute scaled error
  
  Defined as ``(y_pred - target).abs() / all_targets[:, :-1] - all_targets[:, 1:]).mean(1)``.
  ``all_targets`` are here the concatenated encoder and decoder targets
class_docstr_tok: ["Mean","absolute","scaled","error","Defined","as","``","(","y_pred","-","target",")",".abs","(",")","\/","all_targets","[",":",",",":","-1","]","-","all_targets","[",":",",","1",":","]",")",".mean","(","1",")","``",".","``","all_targets","``","are","here","the","concatenated","encoder","and","decoder","targets"]
code: def calculate_scaling(
      self, target, lengths, encoder_target, encoder_lengths
  ):
      # calcualte mean(abs(diff(targets)))
      eps = 1e-6
      batch_size = target.size(0)
      total_lengths = lengths + encoder_lengths
      assert (
          total_lengths > 1
      ).all(), (
          "Need at least 2 target values to be able to calculate MASE"
      )
      max_length = target.size(1) + encoder_target.size(1)
      if (
          total_lengths != max_length
      ).any():  # if decoder or encoder targets have sequences of different lengths
          targets = torch.cat(
              [
                  encoder_target,
                  torch.zeros(
                      batch_size,
                      target.size(1),
                      device=target.device,
                      dtype=encoder_target.dtype,
                  ),
              ],
              dim=1,
          )
          target_index = torch.arange(
              target.size(1), device=target.device, dtype=torch.long
          ).unsqueeze(0).expand(
              batch_size, -1
          ) + encoder_lengths.unsqueeze(
              -1
          )
          targets.scatter_(dim=1, src=target, index=target_index)
      else:
          targets = torch.cat([encoder_target, target], dim=1)
  
      # take absolute difference
      diffs = (targets[:, :-1] - targets[:, 1:]).abs()
  
      # set last difference to 0
      not_maximum_length = total_lengths != max_length
      zero_correction_indices = total_lengths[not_maximum_length] - 1
      if len(zero_correction_indices) > 0:
          diffs[
              torch.arange(
                  batch_size, dtype=torch.long, device=diffs.device
              )[not_maximum_length],
              zero_correction_indices,
          ] = 0.0
  
      # calculate mean over differences
      scaling = diffs.sum(1) / total_lengths + eps
  
      return scaling
  
imports: from typing import Any, Callable, Dict, List, Optional, Tuple, Union
  import scipy.stats
  import torch
  import torch.nn.functional
  from torch.nn.utils import rnn
  from pytorch_forecasting.metrics.base_metrics import MultiHorizonMetric
  from pytorch_forecasting.utils import create_mask, unpack_sequence, unsqueeze_like
label_desc: Use image node_id 3 for calling the MASE obj's underlying member method code with example usage: obj.calculate_scaling(target, lengths, encoder_target, encoder_lengths) and returns: scaling