code: def fit_quantile_transform(loudness_db, mask_on, inv_quantile=None):
      """Fits quantile normalization, given a note_on mask.
  
      Optionally, performs the inverse transformation given a pre-fitted transform.
      Args:
        loudness_db: Decibels, shape [batch, time]
        mask_on: A binary mask for when a note is present, shape [batch, time].
        inv_quantile: Optional pretrained QuantileTransformer to perform the inverse
          transformation.
  
      Returns:
        Trained quantile transform. Also returns the renormalized loudnesses if
          inv_quantile is provided.
      """
      quantile_transform = QuantileTransformer()
      loudness_flat = np.ravel(loudness_db[mask_on])[:, np.newaxis]
      loudness_flat_q = quantile_transform.fit_transform(loudness_flat)
  
      if inv_quantile is None:
          return quantile_transform
      else:
          loudness_flat_norm = inv_quantile.inverse_transform(
              loudness_flat_q
          )
          loudness_norm = np.ravel(loudness_db.copy())[:, np.newaxis]
          loudness_norm[mask_on] = loudness_flat_norm
          return quantile_transform, loudness_norm
  
file_path: ddsp/ddsp/training/postprocessing.py
imports: from ddsp import spectral_ops
  from ddsp.core import hz_to_midi
  import numpy
  from scipy import stats
  import tensorflow.compat.v2
label_desc: Use image node_id 2 for calling a global function with example usage: fit_quantile_transform(loudness_db, mask_on, inv_quantile) and returns: quantile_transform, quantile_transform,  loudness_norm