code: def robust_statistics(x, mask, dim=-1, eps=1e-6):
      """Robust Median Scaler
  
      Standardizes features by removing the median and scaling
      with the mean absolute deviation (mad) a robust estimator of variance.
      This scaler is particularly useful with noisy data where outliers can
      heavily influence the sample mean / variance in a negative way.
      In these scenarios the median and amd give better results.
  
      For example, for `base_windows` models, the scaled features are obtained as (with dim=1):
  
      $$\mathbf{z} = (\mathbf{x}_{[B,T,C]}-\\textrm{median}(\mathbf{x})_{[B,1,C]})/\\textrm{mad}(\mathbf{x})_{[B,1,C]}$$
  
      $$\\textrm{mad}(\mathbf{x}) = \\frac{1}{N} \sum_{}|\mathbf{x} - \mathrm{median}(x)|$$
  
      **Parameters:**<br>
      `x`: torch.Tensor input tensor.<br>
      `mask`: torch Tensor bool, same dimension as `x`, indicates where `x` is valid and False
              where `x` should be masked. Mask should not be all False in any column of
              dimension dim to avoid NaNs from zero division.<br>
      `eps` (float, optional): Small value to avoid division by zero. Defaults to 1e-6.<br>
      `dim` (int, optional): Dimension over to compute median and mad. Defaults to -1.<br>
  
      **Returns:**<br>
      `z`: torch.Tensor same shape as `x`, except scaled.
      """
      x_median = masked_median(x=x, mask=mask, dim=dim)
      x_mad = masked_median(
          x=torch.abs(x - x_median), mask=mask, dim=dim
      )
  
      # Protect x_mad=0 values
      # Assuming normality and relationship between mad and std
      x_means = masked_mean(x=x, mask=mask, dim=dim)
      x_stds = torch.sqrt(
          masked_mean(x=(x - x_means) ** 2, mask=mask, dim=dim)
      )
      x_mad_aux = x_stds * 0.6744897501960817
      x_mad = x_mad * (x_mad > 0) + x_mad_aux * (x_mad == 0)
  
      # Protect against division by zero
      x_mad[x_mad == 0] = 1.0
      x_mad = x_mad + eps
      return x_median, x_mad
  
imports: import torch
  import torch.nn
label_desc: Use image node_id 12 for calling a global function with example usage: robust_statistics(x, mask, dim, eps) and returns: x_median,  x_mad