code: def test_laplacian_regularization(radial_order=6, rng=None):
      gtab = get_gtab_taiwan_dsi()
      l1, l2, l3 = [0.0015, 0.0003, 0.0003]
      S, _ = generate_signal_crossing(gtab, l1, l2, l3, angle2=60)
      S_noise = add_noise(S, snr=20, S0=100.0, rng=rng)
  
      weight_array = np.linspace(0, 0.3, 301)
      mapmod_unreg = MapmriModel(
          gtab,
          radial_order=radial_order,
          laplacian_regularization=False,
          laplacian_weighting=weight_array,
      )
      mapmod_laplacian_array = MapmriModel(
          gtab,
          radial_order=radial_order,
          laplacian_regularization=True,
          laplacian_weighting=weight_array,
      )
      mapmod_laplacian_gcv = MapmriModel(
          gtab,
          radial_order=radial_order,
          laplacian_regularization=True,
          laplacian_weighting="GCV",
      )
  
      # test the Generalized Cross Validation
      # test if GCV gives very low if there is no noise
      mapfit_laplacian_array = mapmod_laplacian_array.fit(S)
      assert_equal(mapfit_laplacian_array.lopt < 0.01, True)
  
      # test if GCV gives higher values if there is noise
      mapfit_laplacian_array = mapmod_laplacian_array.fit(S_noise)
      lopt_array = mapfit_laplacian_array.lopt
      assert_equal(lopt_array > 0.01, True)
  
      # test if continuous GCV gives the same the one based on an array
      mapfit_laplacian_gcv = mapmod_laplacian_gcv.fit(S_noise)
      lopt_gcv = mapfit_laplacian_gcv.lopt
      assert_almost_equal(lopt_array, lopt_gcv, 2)
  
      # test if laplacian reduced the norm of the laplacian in the reconstruction
      mu = mapfit_laplacian_gcv.mu
      laplacian_matrix = mapmri.mapmri_laplacian_reg_matrix(
          mapmod_laplacian_gcv.ind_mat,
          mu,
          mapmod_laplacian_gcv.S_mat,
          mapmod_laplacian_gcv.T_mat,
          mapmod_laplacian_gcv.U_mat,
      )
  
      coef_unreg = mapmod_unreg.fit(S_noise)._mapmri_coef
      coef_laplacian = mapfit_laplacian_gcv._mapmri_coef
  
      laplacian_norm_unreg = np.dot(
          coef_unreg, np.dot(coef_unreg, laplacian_matrix)
      )
      laplacian_norm_laplacian = np.dot(
          coef_laplacian, np.dot(coef_laplacian, laplacian_matrix)
      )
  
      assert_equal(
          laplacian_norm_laplacian < laplacian_norm_unreg, True
      )
  
      # the same for isotropic scaling
      with warnings.catch_warnings():
          warnings.filterwarnings(
              "ignore",
              message=descoteaux07_legacy_msg,
              category=PendingDeprecationWarning,
          )
          mapmod_unreg = MapmriModel(
              gtab,
              radial_order=radial_order,
              laplacian_regularization=False,
              laplacian_weighting=weight_array,
              anisotropic_scaling=False,
          )
          mapmod_laplacian_array = MapmriModel(
              gtab,
              radial_order=radial_order,
              laplacian_regularization=True,
              laplacian_weighting=weight_array,
              anisotropic_scaling=False,
          )
          mapmod_laplacian_gcv = MapmriModel(
              gtab,
              radial_order=radial_order,
              laplacian_regularization=True,
              laplacian_weighting="GCV",
              anisotropic_scaling=False,
          )
  
      # test the Generalized Cross Validation
      # test if GCV gives zero if there is no noise
      mapfit_laplacian_array = mapmod_laplacian_array.fit(S)
      assert_equal(mapfit_laplacian_array.lopt < 0.01, True)
  
      # test if GCV gives higher values if there is noise
      mapfit_laplacian_array = mapmod_laplacian_array.fit(S_noise)
      lopt_array = mapfit_laplacian_array.lopt
      assert_equal(lopt_array > 0.01, True)
  
      # test if continuous GCV gives the same the one based on an array
      mapfit_laplacian_gcv = mapmod_laplacian_gcv.fit(S_noise)
      lopt_gcv = mapfit_laplacian_gcv.lopt
      assert_almost_equal(lopt_array, lopt_gcv, 2)
  
      # test if laplacian reduced the norm of the laplacian in the reconstruction
      mu = mapfit_laplacian_gcv.mu
      laplacian_matrix = mapmri.mapmri_isotropic_laplacian_reg_matrix(
          radial_order, mu[0]
      )
  
      coef_unreg = mapmod_unreg.fit(S_noise)._mapmri_coef
      coef_laplacian = mapfit_laplacian_gcv._mapmri_coef
  
      laplacian_norm_unreg = np.dot(
          coef_unreg, np.dot(coef_unreg, laplacian_matrix)
      )
      laplacian_norm_laplacian = np.dot(
          coef_laplacian, np.dot(coef_laplacian, laplacian_matrix)
      )
  
      assert_equal(
          laplacian_norm_laplacian < laplacian_norm_unreg, True
      )
  
imports: import platform
  import time
  from math import factorial
  from scipy.special import gamma
  import scipy.integrate
  import warnings
  import numpy
  from numpy.testing import assert_almost_equal, assert_array_almost_equal, assert_equal, assert_, assert_raises
  import pytest
  from dipy.core.sphere_stats import angular_similarity
  from dipy.core.subdivide_octahedron import create_unit_sphere
  from dipy.data import get_gtab_taiwan_dsi, default_sphere
  from dipy.direction.peaks import peak_directions
  from dipy.reconst.mapmri import MapmriModel, mapmri_index_matrix
  from dipy.reconst import dti, mapmri
  from dipy.reconst.odf import gfa
  from dipy.reconst.tests.test_dsi import sticks_and_ball_dummies
  from dipy.reconst.shm import sh_to_sf, descoteaux07_legacy_msg
  from dipy.sims.voxel import multi_tensor, multi_tensor_pdf, add_noise, single_tensor, cylinders_and_ball_soderman
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 22 for calling a global function with example usage: test_laplacian_regularization(radial_order, rng) without return types