code: def _compute_shapelet_grad(
      X,
      n_samples,
      n_timestamps,
      weights,
      shapelets,
      lengths,
      alpha,
      proba_minus_y,
      weight_idx,
      sample_weight,
  ):
      gradients = []
  
      for i in range(len(lengths)):
          X_window = _windowed_view(
              X,
              n_samples,
              n_timestamps,
              window_size=lengths[i][0],
              window_step=1,
          )
          n_windows = X_window.shape[1]
          size = shapelets[i][0].size
          for j in range(shapelets[i].shape[0]):
              # Get the current shapelet
              shapelet = shapelets[i][j]
  
              # Derive the difference and the distance
              diff = shapelet - X_window
              dist = np.empty((n_samples, n_windows))
              for k in prange(n_samples):
                  for m in prange(n_windows):
                      dist[k, m] = np.mean(diff[k, m] ** 2)
  
              # Derive the softmin gradient
              softmin_gradient = np.empty((n_samples, n_windows))
              for k in prange(n_samples):
                  softmin_gradient[k] = _softmin_grad(dist[k], alpha)
  
              # Normalize the difference for actual gradient
              diff *= 2 / size
  
              # Compute the gradient
              grad = np.empty(size)
              if weights.ndim == 1:
                  for k in prange(size):
                      grad[k] = np.mean(
                          np.sum(
                              diff[:, :, k] * softmin_gradient, axis=1
                          )
                          * weights[weight_idx]
                          * proba_minus_y
                          * sample_weight
                      )
              else:
                  for k in prange(size):
                      grad[k] = np.mean(
                          np.sum(
                              diff[:, :, k] * softmin_gradient, axis=1
                          )
                          * np.sum(
                              weights[weight_idx] * proba_minus_y,
                              axis=1,
                          )
                          * sample_weight
                      )
              gradients.append(grad)
  
              # Update the weight index
              weight_idx += 1
  
      return gradients
  
imports: from itertools import chain
  from math import ceil
  from numba import njit, prange
  import numpy
  from sklearn.base import BaseEstimator
  from sklearn.cluster import KMeans
  from sklearn.exceptions import ConvergenceWarning
  from sklearn.multiclass import OneVsOneClassifier, OneVsRestClassifier
  from sklearn.multiclass import _ovr_decision_function
  from sklearn.preprocessing import LabelBinarizer, LabelEncoder
  from sklearn.utils import compute_class_weight, check_array
  from sklearn.utils.validation import check_is_fitted, check_random_state, check_X_y, _check_sample_weight
  from sklearn.utils.multiclass import check_classification_targets
  import warnings
  from ..utils.utils import _windowed_view
  from ..base import UnivariateClassifierMixin
label_desc: Use image node_id 12 for calling a global function with example usage: _compute_shapelet_grad(X, n_samples, n_timestamps, weights, shapelets, lengths, alpha, proba_minus_y, weight_idx, sample_weight) and returns: gradients