code: def test_early_stopping_callback_object(
      rng, n_samples=10, n_features=30
  ):
      # This test evolves w so that every line of th _EarlyStoppingCallback
      # code is executed a some point. This a kind of code fuzzing.
      X_test = rng.standard_normal((n_samples, n_features))
      y_test = np.dot(X_test, np.ones(n_features))
      w = np.zeros(n_features)
      escb = _EarlyStoppingCallback(X_test, y_test, False)
      for counter in range(50):
          k = min(counter, n_features - 1)
          w[k] = 1
  
          # jitter
          if k > 0 and rng.random() > 0.9:
              w[k - 1] = 1 - w[k - 1]
  
          escb(dict(w=w, counter=counter))
          assert len(escb.test_scores) == counter + 1
  
          # restart
          if counter > 20:
              w *= 0.0
  
imports: from functools import partial
  import numpy
  import pytest
  from numpy.testing import assert_almost_equal, assert_array_equal
  from scipy import linalg
  from sklearn.datasets import load_iris
  from sklearn.linear_model import Lasso, LogisticRegression
  from sklearn.linear_model._coordinate_descent import _alpha_grid
  from sklearn.metrics import accuracy_score
  from nilearn._utils.param_validation import adjust_screening_percentile
  from nilearn.decoding.space_net import BaseSpaceNet, SpaceNetClassifier, SpaceNetRegressor, _crop_mask, _EarlyStoppingCallback, _space_net_alpha_grid, _univariate_feature_screening, path_scores
  from nilearn.decoding.space_net_solvers import graph_net_logistic, graph_net_squared_loss
  from nilearn.decoding.tests._testing import create_graph_net_simulation_data
  from nilearn.image import get_data
  from .test_same_api import to_niimgs
label_desc: Use image node_id 3 for calling a global function with example usage: test_early_stopping_callback_object(rng, n_samples, n_features) without return types