code: def _mini_batch_convergence(
      model,
      iteration_idx,
      n_iter,
      tol,
      n_samples,
      centers_squared_diff,
      batch_inertia,
      context,
      verbose=0,
  ):
      """Helper function to encapsulate the early stopping logic"""
      # Normalize inertia to be able to compare values when
      # batch_size changes
      batch_inertia /= model.batch_size
      centers_squared_diff /= model.batch_size
  
      # Compute an Exponentially Weighted Average of the squared
      # diff to monitor the convergence while discarding
      # minibatch-local stochastic variability:
      # https://en.wikipedia.org/wiki/Moving_average
      ewa_diff = context.get("ewa_diff")
      ewa_inertia = context.get("ewa_inertia")
      if ewa_diff is None:
          ewa_diff = centers_squared_diff
          ewa_inertia = batch_inertia
      else:
          alpha = float(model.batch_size) * 2.0 / (n_samples + 1)
          alpha = 1.0 if alpha > 1.0 else alpha
          ewa_diff = (
              ewa_diff * (1 - alpha) + centers_squared_diff * alpha
          )
          ewa_inertia = (
              ewa_inertia * (1 - alpha) + batch_inertia * alpha
          )
  
      # Log progress to be able to monitor convergence
      if verbose:
          progress_msg = (
              "Minibatch iteration %d/%d:"
              " mean batch inertia: %f, ewa inertia: %f "
              % (iteration_idx + 1, n_iter, batch_inertia, ewa_inertia)
          )
          print(progress_msg)
  
      # Early stopping based on absolute tolerance on squared change of
      # centers position (using EWA smoothing)
      if tol > 0.0 and ewa_diff <= tol:
          if verbose:
              print(
                  "Converged (small centers change) at iteration %d/%d"
                  % (iteration_idx + 1, n_iter)
              )
          return True
  
      # Early stopping heuristic due to lack of improvement on smoothed inertia
      ewa_inertia_min = context.get("ewa_inertia_min")
      no_improvement = context.get("no_improvement", 0)
      if ewa_inertia_min is None or ewa_inertia < ewa_inertia_min:
          no_improvement = 0
          ewa_inertia_min = ewa_inertia
      else:
          no_improvement += 1
  
      if (
          model.max_no_improvement is not None
          and no_improvement >= model.max_no_improvement
      ):
          if verbose:
              print(
                  "Converged (lack of improvement in inertia)"
                  " at iteration %d/%d" % (iteration_idx + 1, n_iter)
              )
          return True
  
      # update the convergence context to maintain state across successive calls:
      context["ewa_diff"] = ewa_diff
      context["ewa_inertia"] = ewa_inertia
      context["ewa_inertia_min"] = ewa_inertia_min
      context["no_improvement"] = no_improvement
      return False
  
imports: import warnings
  import numpy
  import scipy.sparse
  from ..base import BaseEstimator, ClusterMixin, TransformerMixin
  from ..metrics.pairwise import euclidean_distances
  from ..metrics.pairwise import pairwise_distances_argmin_min
  from ..utils.extmath import row_norms, squared_norm
  from ..utils.sparsefuncs_fast import assign_rows_csr
  from ..utils.sparsefuncs import mean_variance_axis
  from ..utils.fixes import astype
  from ..utils import check_array
  from ..utils import check_random_state
  from ..utils import as_float_array
  from ..utils import gen_batches
  from ..utils.validation import check_is_fitted
  from ..utils.validation import FLOAT_DTYPES
  from ..utils.random import choice
  from ..externals.joblib import Parallel
  from ..externals.joblib import delayed
  from ..externals.six import string_types
  from .None import _k_means
  from ._k_means_elkan import k_means_elkan
label_desc: Use image node_id 11 for calling a global function with example usage: _mini_batch_convergence(model, iteration_idx, n_iter, tol, n_samples, centers_squared_diff, batch_inertia, context, verbose) and returns: False, True, True