code: def test_square_iter(rng):
      nclasses = 4
      beta = np.float64(0.0)
      max_iter = 10
  
      com = ConstantObservationModel()
      icm = IteratedConditionalModes()
  
      initial_segmentation = create_square()
      square_gauss = create_square_gauss(rng)
  
      mu, sigmasq = com.seg_stats(
          square_gauss, initial_segmentation, nclasses
      )
      npt.assert_(mu[0] >= 0.0)
      npt.assert_(mu[1] >= 0.0)
      npt.assert_(mu[2] >= 0.0)
      npt.assert_(mu[3] >= 0.0)
      npt.assert_(sigmasq[0] >= 0.0)
      npt.assert_(sigmasq[1] >= 0.0)
      npt.assert_(sigmasq[2] >= 0.0)
      npt.assert_(sigmasq[3] >= 0.0)
  
      final_segmentation = np.empty_like(square_gauss)
      seg_init = initial_segmentation
      energies = []
  
      for i in range(max_iter):
          print("\n")
          print(">> Iteration: " + str(i))
          print("\n")
  
          PLN = icm.prob_neighborhood(
              initial_segmentation, beta, nclasses
          )
          npt.assert_(np.all((PLN >= 0) & (PLN <= 1.0)))
  
          if beta == 0.0:
              npt.assert_(PLN[25, 25, 1, 0] == 0.25)
              npt.assert_(PLN[25, 25, 1, 1] == 0.25)
              npt.assert_(PLN[25, 25, 1, 2] == 0.25)
              npt.assert_(PLN[25, 25, 1, 3] == 0.25)
              npt.assert_(PLN[50, 50, 1, 0] == 0.25)
              npt.assert_(PLN[50, 50, 1, 1] == 0.25)
              npt.assert_(PLN[50, 50, 1, 2] == 0.25)
              npt.assert_(PLN[50, 50, 1, 3] == 0.25)
              npt.assert_(PLN[90, 90, 1, 0] == 0.25)
              npt.assert_(PLN[90, 90, 1, 1] == 0.25)
              npt.assert_(PLN[90, 90, 1, 2] == 0.25)
              npt.assert_(PLN[90, 90, 1, 3] == 0.25)
              npt.assert_(PLN[125, 125, 1, 0] == 0.25)
              npt.assert_(PLN[125, 125, 1, 1] == 0.25)
              npt.assert_(PLN[125, 125, 1, 2] == 0.25)
              npt.assert_(PLN[125, 125, 1, 3] == 0.25)
  
          PLY = com.prob_image(square_gauss, nclasses, mu, sigmasq, PLN)
          npt.assert_(np.all((PLY >= 0) & (PLY <= 1.0)))
          npt.assert_(PLY[25, 25, 1, 0] > PLY[25, 25, 1, 1])
          npt.assert_(PLY[25, 25, 1, 0] > PLY[25, 25, 1, 2])
          npt.assert_(PLY[25, 25, 1, 0] > PLY[25, 25, 1, 3])
          npt.assert_(PLY[125, 125, 1, 3] > PLY[125, 125, 1, 0])
          npt.assert_(PLY[125, 125, 1, 3] > PLY[125, 125, 1, 1])
          npt.assert_(PLY[125, 125, 1, 3] > PLY[125, 125, 1, 2])
  
          mu_upd, sigmasq_upd = com.update_param(
              square_gauss, PLY, mu, nclasses
          )
          npt.assert_(mu_upd[0] >= 0.0)
          npt.assert_(mu_upd[1] >= 0.0)
          npt.assert_(mu_upd[2] >= 0.0)
          npt.assert_(mu_upd[3] >= 0.0)
          npt.assert_(sigmasq_upd[0] >= 0.0)
          npt.assert_(sigmasq_upd[1] >= 0.0)
          npt.assert_(sigmasq_upd[2] >= 0.0)
          npt.assert_(sigmasq_upd[3] >= 0.0)
  
          negll = com.negloglikelihood(
              square_gauss, mu_upd, sigmasq_upd, nclasses
          )
          npt.assert_(negll[25, 25, 1, 0] < negll[25, 25, 1, 1])
          npt.assert_(negll[25, 25, 1, 0] < negll[25, 25, 1, 2])
          npt.assert_(negll[25, 25, 1, 0] < negll[25, 25, 1, 3])
          npt.assert_(negll[100, 100, 1, 3] < negll[125, 125, 1, 0])
          npt.assert_(negll[100, 100, 1, 3] < negll[125, 125, 1, 1])
          npt.assert_(negll[100, 100, 1, 3] < negll[125, 125, 1, 2])
  
          final_segmentation, energy = icm.icm_ising(
              negll, beta, initial_segmentation
          )
  
          energies.append(energy[energy > -np.inf].sum())
  
          initial_segmentation = final_segmentation
          mu = mu_upd
          sigmasq = sigmasq_upd
  
      difference_map = np.abs(seg_init - final_segmentation)
      npt.assert_(np.abs(np.sum(difference_map)) == 0.0)
  
file_path: dipy/dipy/segment/tests/test_mrf.py
imports: import numpy
  import numpy.testing
  from dipy.data import get_fnames
  from dipy.sims.voxel import add_noise
  from dipy.segment.mrf import ConstantObservationModel, IteratedConditionalModes
  from dipy.segment.tissue import TissueClassifierHMRF
  from dipy.testing.decorators import set_random_number_generator
label_desc: Use image node_id 7 for calling a global function with example usage: test_square_iter(rng) without return types