class_docstr: The ``MeanScaler`` computes a per-item scale according to the average
  absolute value over time of each item. The average is computed only among
  the observed values in the data tensor, as indicated by the second
  argument. Items with no observed data are assigned a scale based on the
  global average.
  
  Parameters
  ----------
  minimum_scale
      default scale that is used if the time series has only zeros.
class_docstr_tok: ["The","``","MeanScaler","``","computes","a","per-item","scale","according","to","the","average","absolute","value","over","time","of","each","item",".","The","average","is","computed","only","among","the","observed","values","in","the","data","tensor",",","as","indicated","by","the","second","argument",".","Items","with","no","observed","data","are","assigned","a","scale","based","on","the","global","average",".","Parameters","--","--","--","--","--","minimum_scale","default","scale","that","is","used","if","the","time","series","has","only","zeros","."]
code: def compute_scale(
      self, data: torch.Tensor, observed_indicator: torch.Tensor
  ) -> torch.Tensor:
      if self.time_first:
          dim = 1
      else:
          dim = 2
  
      # these will have shape (N, C)
      num_observed = observed_indicator.sum(dim=dim)
      sum_observed = (data.abs() * observed_indicator).sum(dim=dim)
  
      # first compute a global scale per-dimension
      total_observed = num_observed.sum(dim=0)
      denominator = torch.max(
          total_observed, torch.ones_like(total_observed)
      )
      default_scale = sum_observed.sum(dim=0) / denominator
  
      # then compute a per-item, per-dimension scale
      denominator = torch.max(
          num_observed, torch.ones_like(num_observed)
      )
      scale = sum_observed / denominator
  
      # use per-batch scale when no element is observed
      # or when the sequence contains only zeros
      scale = torch.where(
          sum_observed > torch.zeros_like(sum_observed),
          scale,
          default_scale * torch.ones_like(num_observed),
      )
  
      return torch.max(scale, self.minimum_scale).detach()
  
file_path: gluonts/src/gluonts/nursery/robust-mts-attack/pts/modules/scaler.py
imports: from abc import ABC, abstractmethod
  from typing import Tuple
  import torch
  import torch.nn
  from gluonts.core.component import validated
label_desc: Use image node_id 2 for calling the MeanScaler obj's underlying member method code with example usage: obj.compute_scale(data, observed_indicator) and returns: torch