BF: fix for division error gh-446 Thanks to @Amiiir for tracking down this error.
authorMatthew Brett <matthew.brett@gmail.com>
Thu, 10 Jan 2019 16:05:31 +0000 (16:05 +0000)
committerYaroslav Halchenko <debian@onerussian.com>
Thu, 10 Jan 2019 16:05:31 +0000 (16:05 +0000)
Closes gh-446.

Gbp-Pq: Name changeset_7529ffc4585ba67171219aa29a3f6c5df9963f1d.diff

nipy/algorithms/clustering/tests/test_vmm.py
nipy/algorithms/clustering/von_mises_fisher_mixture.py

index 24f49c727352dd0e934e4663fb54bce5a0b72f8e..1223808f5b8ac212fb6f9a62acea1214ef6d2dfe 100644 (file)
@@ -12,8 +12,13 @@ from ..von_mises_fisher_mixture import (VonMisesMixture,
                                         select_vmm,
                                         select_vmm_cv)
 
-
 from nose.tools import assert_true, assert_equal
+from numpy.testing import decorators
+
+from nibabel.optpkg import optional_package
+
+matplotlib, HAVE_MPL, _ = optional_package('matplotlib')
+needs_mpl = decorators.skipif(not HAVE_MPL, "Test needs matplotlib")
 
 
 def test_spherical_area():
@@ -38,6 +43,18 @@ def test_von_mises_fisher_density():
                             < 1e-2)
 
 
+@needs_mpl
+def test_von_mises_fisher_show():
+    # Smoke test for VonMisesMixture.show
+    x = np.random.randn(100, 3)
+    x = (x.T/np.sqrt(np.sum(x**2, 1))).T
+    vmd = VonMisesMixture(1, 1)
+    # Need to estimate to avoid error in show
+    vmd.estimate(x)
+    # Check that show does not raise an error
+    vmd.show(x)
+
+
 def test_dimension_selection_bic():
     # Tests whether dimension selection yields correct results
     x1 = [0.6, 0.48, 0.64]
index 66b78724331ee0c9c69b2117cc63902593fcec76..a38511b295e574a34f71be8de37292830458941e 100644 (file)
@@ -233,8 +233,13 @@ class VonMisesMixture(object):
 
         Parameters
         ----------
-        x: array fo shape(n,3)
+        x: array of shape (n, 3)
            should be on the unit sphere
+
+        Notes
+        -----
+
+        Uses ``matplotlib``.
         """
         # label the data
         z = np.argmax(self.responsibilities(x), 1)
@@ -243,7 +248,7 @@ class VonMisesMixture(object):
         fig = pylab.figure()
         ax = p3.Axes3D(fig)
         colors = (['b', 'g', 'r', 'c', 'm', 'y', 'k', 'w'] * \
-                      (1 + (1 + self.k) / 8))[:self.k + 1]
+                      (1 + (1 + self.k) // 8))[:self.k + 1]
         if (self.null_class) and (z == 0).any():
             ax.plot3D(x[z == 0, 0], x[z == 0, 1], x[z == 0, 2], '.',
                       color=colors[0])