code: def test_em_gmm_cv():
      # Comparison of different GMMs using cross-validation
  
      # generate some data
      dim = 2
      xtrain = np.concatenate(
          (nr.randn(100, dim), 3 + 2 * nr.randn(100, dim))
      )
      xtest = np.concatenate(
          (nr.randn(1000, dim), 3 + 2 * nr.randn(1000, dim))
      )
  
      # estimate different GMMs for xtrain, and test it on xtest
      prec_type = "full"
      k, maxiter, delta = 2, 300, 1.0e-4
      ll = []
  
      # model 1
      lgmm = GMM(k, dim, prec_type)
      lgmm.initialize(xtrain)
      bic = lgmm.estimate(xtrain, maxiter, delta)
      ll.append(lgmm.test(xtest).mean())
  
      # model 2
      prec_type = "diag"
      lgmm = GMM(k, dim, prec_type)
      lgmm.initialize(xtrain)
      bic = lgmm.estimate(xtrain, maxiter, delta)
      ll.append(lgmm.test(xtest).mean())
  
      for k in [1, 3, 10]:
          lgmm = GMM(k, dim, prec_type)
          lgmm.initialize(xtrain)
          ll.append(lgmm.test(xtest).mean())
  
      assert ll[4] < ll[1]
  
file_path: nipy/nipy/algorithms/clustering/tests/test_gmm.py
imports: import numpy
  from ..gmm import GMM, best_fitting_GMM
label_desc: Use image node_id 14 for calling a global function with example usage: test_em_gmm_cv() without return types