code: def estimate_pattern_th(
      y,
      yhat,
      mode="default",
      ratio=0.01,
      dist_measure=EuclideanDistance(),
  ):
      """
      Estimate the absolute distance threshold based on y and y_hat.
  
      :param y: actual values
      :param yhat: predicted values
      :param mode: types of ways to find threshold
          "default" : fit data to a uniform distribution (the percentile way)
          "gaussian": fit data to a gaussian distribution
      :param ratio: the ratio of anomaly to consider as anomaly.
      :param dist_measure: measure of distance
      :return: the threshold
      """
      invalidInputError(
          y.shape == yhat.shape, "y shape doesn't match yhat shape"
      )
      diff = [dist_measure.abs_dist(m, n) for m, n in zip(y, yhat)]
      if mode == "default":
          threshold = np.percentile(diff, (1 - ratio) * 100)
          return threshold
      elif mode == "gaussian":
          from scipy.stats import norm
  
          mu, sigma = norm.fit(diff)
          t = norm.ppf(1 - ratio)
          return t * sigma + mu
      else:
          invalidInputError(False, f"Does not support ${mode}")
  
imports: import math
  import numpy
  from bigdl.chronos.detector.anomaly.abstract import AnomalyDetector
  from bigdl.nano.utils.common import invalidInputError
  from abc import ABC, abstractmethod
label_desc: Use image node_id 1 for calling a global function with example usage: estimate_pattern_th(y, yhat, mode, ratio, dist_measure) and returns: threshold, unknown