code: def _online_shapelet_distance(
      series, shapelet, sorted_indices, position, length
  ):
      subseq = series[position : position + length]
  
      sum = 0.0
      sum2 = 0.0
      for i in subseq:
          sum += i
          sum2 += i * i
  
      mean = sum / length
      std = (sum2 - mean * mean * length) / length
      if std > 0:
          subseq = (subseq - mean) / std
      else:
          subseq = np.zeros(length)
  
      best_dist = 0
      for i, n in zip(shapelet, subseq):
          temp = i - n
          best_dist += temp * temp
  
      i = 1
      traverse = [True, True]
      sums = [sum, sum]
      sums2 = [sum2, sum2]
  
      while traverse[0] or traverse[1]:
          for n in range(2):
              mod = -1 if n == 0 else 1
              pos = position + mod * i
              traverse[n] = (
                  pos >= 0 if n == 0 else pos <= len(series) - length
              )
  
              if not traverse[n]:
                  continue
  
              start = series[pos - n]
              end = series[pos - n + length]
  
              sums[n] += mod * end - mod * start
              sums2[n] += mod * end * end - mod * start * start
  
              mean = sums[n] / length
              std = math.sqrt(
                  (sums2[n] - mean * mean * length) / length
              )
  
              dist = 0
              use_std = std != 0
              for j in range(length):
                  val = (
                      (series[pos + sorted_indices[j]] - mean) / std
                      if use_std
                      else 0
                  )
                  temp = shapelet[sorted_indices[j]] - val
                  dist += temp * temp
  
                  if dist > best_dist:
                      break
  
              if dist < best_dist:
                  best_dist = dist
  
          i += 1
  
      return best_dist if best_dist == 0 else 1 / length * best_dist
  
file_path: sktime/sktime/transformations/panel/_shapelet_transform_numba.py
imports: import heapq
  import math
  import numpy
  from sktime.utils.numba.njit import njit
label_desc: Use image node_id 1 for calling a global function with example usage: _online_shapelet_distance(series, shapelet, sorted_indices, position, length) and returns: unknown