code: def generate_statistics(samples):
      E_x = 0
      E_x_2 = 0
      N = 0
  
      for idx, sample in enumerate(samples):
          mel_spec = spectrogram_transform(
              sample[0].squeeze()
          ).transpose(1, 0)
          scaled_mel_spec = piecewise_linear_log(mel_spec)
          sum = scaled_mel_spec.sum(0)
          sq_sum = scaled_mel_spec.pow(2).sum(0)
          M = scaled_mel_spec.size(0)
  
          E_x = E_x * (N / (N + M)) + sum / (N + M)
          E_x_2 = E_x_2 * (N / (N + M)) + sq_sum / (N + M)
          N += M
  
          if idx % 100 == 0:
              logger.info(f"Processed {idx}")
  
      return E_x, (E_x_2 - E_x**2) ** 0.5
  
file_path: audio/examples/asr/emformer_rnnt/global_stats.py
imports: import json
  import logging
  import pathlib
  from argparse import ArgumentParser, RawTextHelpFormatter
  import torch
  import torchaudio
  from common import MODEL_TYPE_LIBRISPEECH, MODEL_TYPE_MUSTC, MODEL_TYPE_TEDLIUM3, piecewise_linear_log, spectrogram_transform
  from mustc.dataset import MUSTC
label_desc: Use image node_id 2 for calling a global function with example usage: generate_statistics(samples) and returns: E_x,  unknown