code: def test_gmm_bf(kmax=4, seed=1):
      """Perform a model selection procedure on a gmm
      with Bayes factor estimations
  
      Parameters
      ----------
      kmax : range of values that are tested
      seed=False:  int, optional
          If seed is not False, the random number generator is initialized
          at a certain value
  
      fixme : this one often fails. I don't really see why
      """
      n_samples, dim, niter = 30, 2, 1000
  
      if seed:
          nr = np.random.RandomState([seed])
      else:
          import numpy.random as nr
  
      x = nr.randn(n_samples, dim)
  
      bbf = -np.inf
      for k in range(1, kmax):
          b = BGMM(k, dim)
          b.guess_priors(x)
          b.initialize(x)
          b.sample(x, 100)
          w, cent, prec, pz = b.sample(x, niter=niter, mem=1)
          bplugin = BGMM(k, dim, cent, prec, w)
          bplugin.guess_priors(x)
          bfk = bplugin.bayes_factor(x, pz.astype(np.int_))
          if bfk > bbf:
              bestk = k
              bbf = bfk
      assert bestk < 3
  
file_path: nipy/nipy/algorithms/clustering/tests/test_bgmm.py
imports: import numpy
  import numpy.random
  from ..bgmm import BGMM, VBGMM, dirichlet_eval, dkl_gaussian, multinomial
label_desc: Use image node_id 7 for calling a global function with example usage: test_gmm_bf(kmax, seed) without return types