From: Matthew Brett Date: Thu, 10 Jan 2019 16:05:31 +0000 (+0000) Subject: BF: fix for division error gh-446 Thanks to @Amiiir for tracking down this error. X-Git-Tag: archive/raspbian/0.4.2-2+rpi1^2~6 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=9dc5b40fdd3d71e148148f803af18b244003a258;p=nipy.git BF: fix for division error gh-446 Thanks to @Amiiir for tracking down this error. Closes gh-446. Gbp-Pq: Name changeset_7529ffc4585ba67171219aa29a3f6c5df9963f1d.diff --- diff --git a/nipy/algorithms/clustering/tests/test_vmm.py b/nipy/algorithms/clustering/tests/test_vmm.py index 24f49c7..1223808 100644 --- a/nipy/algorithms/clustering/tests/test_vmm.py +++ b/nipy/algorithms/clustering/tests/test_vmm.py @@ -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] diff --git a/nipy/algorithms/clustering/von_mises_fisher_mixture.py b/nipy/algorithms/clustering/von_mises_fisher_mixture.py index 66b7872..a38511b 100644 --- a/nipy/algorithms/clustering/von_mises_fisher_mixture.py +++ b/nipy/algorithms/clustering/von_mises_fisher_mixture.py @@ -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])