code: def _fit(
      indexed_params,
      penalization,
      lam,
      lam_perturb,
      lam_scale_,
      estimator,
      penalty_name,
      subsample,
      bootstrap,
      prng,
      X=None,
  ):
      """Wrapper function outside of instance for fitting a single model average
      trial.
  
      If X is None, then we assume we are using a broadcast spark object. Else,
      we expect X to get passed into this function.
      """
      index = indexed_params
  
      if isinstance(X, np.ndarray):
          local_X = X
      else:
          local_X = X.value
  
      n_samples, n_features = local_X.shape
  
      prec_is_real = False
      while not prec_is_real:
          boot_lam = None
          if penalization == "subsampling":
              pass
          elif penalization == "random":
              boot_lam = _fix_weights(
                  _random_weights, n_features, lam, lam_perturb, prng
              )
          elif penalization == "fully-random":
              boot_lam = _fix_weights(
                  _fully_random_weights, n_features, lam_scale_, prng
              )
          else:
              raise NotImplementedError(
                  (
                      "Only penalization = 'subsampling', "
                      "'random', and 'fully-random' have "
                      "been implemented. Found {}.".format(penalization)
                  )
              )
  
          # new instance of estimator
          new_estimator = clone(estimator)
          if boot_lam is not None:
              new_estimator.set_params(**{penalty_name: boot_lam})
  
          # fit estimator
          num_subsamples = int(subsample * n_samples)
          rp = bootstrap(n_samples, num_subsamples, prng)
          new_estimator.fit(local_X[rp, :])
  
          # check that new_estimator.precision_ is real
          # if not, skip this boot_lam and try again
          if isinstance(new_estimator.precision_, list):
              prec_real_bools = []
              for prec in new_estimator.precision_:
                  prec_real_bools.append(np.all(np.isreal(prec)))
  
              prec_is_real = np.all(np.array(prec_real_bools) is True)
  
          elif isinstance(new_estimator.precision_, np.ndarray):
              prec_is_real = np.all(np.isreal(new_estimator.precision_))
  
          else:
              raise ValueError("Estimator returned invalid precision_.")
  
      return index, (boot_lam, rp, new_estimator)
  
imports: from __future__ import absolute_import
  import numpy
  from sklearn.base import BaseEstimator, clone
  from sklearn.utils import check_array, as_float_array
  from joblib import Parallel, delayed
  from functools import partial
  from .inverse_covariance import _init_coefs
  from .None import QuicGraphicalLasso
label_desc: Use image node_id 6 for calling a global function with example usage: _fit(indexed_params, penalization, lam, lam_perturb, lam_scale_, estimator, penalty_name, subsample, bootstrap, prng, X) and returns: index,  boot_lam,  rp,  new_estimator