code: def test_von_mises_fisher_density():
      # test that a density is indeed computed on the unit sphere for a
      # one-component and three-component model (k == 1, 3)
      x = np.random.randn(100, 3)
      x = (x.T / np.sqrt(np.sum(x**2, 1))).T
      s, area = sphere_density(100)
      for k in (1, 3):
          for precision in [0.1, 1.0, 10.0, 100.0]:
              for null_class in (False, True):
                  vmd = VonMisesMixture(
                      k, precision, null_class=null_class
                  )
                  vmd.estimate(x)
                  # check that it sums to 1
                  assert (
                      np.abs((vmd.mixture_density(s) * area).sum() - 1)
                      < 1e-2
                  )
  
file_path: nipy/nipy/algorithms/clustering/tests/test_vmm.py
imports: from unittest import skipIf
  import numpy
  from nibabel.optpkg import optional_package
  from ..von_mises_fisher_mixture import VonMisesMixture, select_vmm, select_vmm_cv, sphere_density
label_desc: Use image node_id 2 for calling a global function with example usage: test_von_mises_fisher_density() without return types