code: def _kmeans_plus_plus(
      X: np.ndarray,
      n_clusters: int,
      random_state: np.random.RandomState,
      distance_metric: str = "euclidean",
      n_local_trials: int = None,
      distance_params: dict = None,
      **kwargs,
  ):
      """Compute initial centroids using kmeans++ method.
  
      This works by choosing one point at random. Next compute the distance between the
      center and each point. Sample these with a probability proportional to the square
      of the distance of the points from its nearest center.
  
      NOTE: This is adapted from sklearns implementation:
      https://
      github.com/scikit-learn/scikit-learn/blob/7e1e6d09b/sklearn/cluster/_kmeans.py
  
      Parameters
      ----------
      X : np.ndarray (3d array of shape (n_instances,n_dimensions,series_length))
          Time series instances to cluster.
      n_clusters: int, defaults = 8
          The number of clusters to form as well as the number of
          centroids to generate.
      random_state: np.random.RandomState
          Determines random number generation for centroid initialization.
      distance_metric: str, defaults = 'euclidean'
          String that is the distance metric.
      n_local_trials: integer, optional
          The number of seeding trials for each center (except the first),
          of which the one reducing inertia the most is greedily chosen.
          Set to None to make the number of trials depend logarithmically
          on the number of seeds (2+log(k)); this is the default.
      distance_params: dict, defaults = None
          Dictionary containing distance parameter kwargs.
  
      Returns
      -------
      np.ndarray (3d array of shape (n_clusters, n_dimensions, series_length))
          Indexes of the cluster centers.
      """
      n_samples, n_timestamps, n_features = X.shape
  
      centers = np.empty(
          (n_clusters, n_timestamps, n_features), dtype=X.dtype
      )
      n_samples, n_timestamps, n_features = X.shape
  
      if n_local_trials is None:
          n_local_trials = 2 + int(np.log(n_clusters))
  
      if distance_params is None:
          distance_params = {}
  
      center_id = random_state.randint(n_samples)
      centers[0] = X[center_id]
      closest_dist_sq = (
          pairwise_distance(
              centers[0, np.newaxis], X, metric=distance_metric
          )
          ** 2
      )
      current_pot = closest_dist_sq.sum()
  
      for c in range(1, n_clusters):
          rand_vals = (
              random_state.random_sample(n_local_trials) * current_pot
          )
          candidate_ids = np.searchsorted(
              stable_cumsum(closest_dist_sq), rand_vals
          )
          np.clip(
              candidate_ids,
              None,
              closest_dist_sq.size - 1,
              out=candidate_ids,
          )
  
          distance_to_candidates = (
              pairwise_distance(
                  X[candidate_ids], X, metric=distance_metric
              )
              ** 2
          )
  
          np.minimum(
              closest_dist_sq,
              distance_to_candidates,
              out=distance_to_candidates,
          )
          candidates_pot = distance_to_candidates.sum(axis=1)
  
          best_candidate = np.argmin(candidates_pot)
          current_pot = candidates_pot[best_candidate]
          closest_dist_sq = distance_to_candidates[best_candidate]
          best_candidate = candidate_ids[best_candidate]
  
          centers[c] = X[best_candidate]
  
      return centers
  
imports: from abc import ABC, abstractmethod
  from typing import Callable, Tuple, Union
  import numpy
  from numpy.random import RandomState
  from sklearn.utils import check_random_state
  from sklearn.utils.extmath import stable_cumsum
  from sktime.clustering.base import BaseClusterer
  from sktime.clustering.metrics.averaging import mean_average
  from sktime.distances import distance_factory, pairwise_distance
  from sktime.distances._ddtw import average_of_slope_transform
label_desc: Use image node_id 3 for calling a global function with example usage: _kmeans_plus_plus(X, n_clusters, random_state, distance_metric, n_local_trials, distance_params) and returns: centers