Beispiel #1
0
 def test_compute_w(self):
     """ Computing W without computing H doesn't make much sense for chnmf..
     """
     mdl = CHNMF(self.data, num_bases=3)
     mdl.H = self.H
     mdl.factorize(niter=10, compute_h=False)
     assert_set_equal(mdl.W, self.W, decimal=2)
Beispiel #2
0
    def test_cnmf(self):
        mdl = BNMF(self.data, num_bases=2)

        mdl.factorize(niter=100)
        assert_set_equal(mdl.W, self.W, decimal=1)

        assert_set_equal(mdl.H.T, self.H, decimal=1)
        rec = mdl.frobenius_norm()
        assert(rec <= 0.1)
Beispiel #3
0
    def test_rnmf(self):
        mdl = RNMF(self.data, num_bases=2)

        # nmf forms a cone in the input space, but it is unlikely to hit the
        # cone exactly.
        mdl.factorize(niter=50)
        assert_set_equal(mdl.W.T / np.sum(mdl.W, axis=1), self.W, decimal=1)

        # the reconstruction quality should still be close to perfect
        rec = mdl.frobenius_norm()
        assert_almost_equal(0.0, rec, decimal=1)
Beispiel #4
0
    def test_nmf(self):
        mdl = NMF(self.data, num_bases=2)

        # nmf forms a cone in the input space, but it is unlikely to hit the
        # cone exactly.
        mdl.factorize(niter=50)
        assert_set_equal(mdl.W, self.W, decimal=1)

        # since the basis vector will be close to 1/0, the coefficients should
        # converge to the original data.
        assert_set_equal(mdl.H.T, self.data.T, decimal=1)

        # the reconstruction quality should still be close to perfect
        rec = mdl.frobenius_norm()
        assert_almost_equal(0.0, rec, decimal=1)
Beispiel #5
0
    def test_cnmf(self):
        mdl = CNMF(self.data, num_bases=2)

        # nmf forms a cone in the input space, but it is unlikely to hit the
        # cone exactly.
        mdl.factorize(niter=100)
        W = mdl.W/np.sum(mdl.W, axis=0)
        assert_set_equal(W, self.W, decimal=1)

        # since the basis vector will be close to 1/0, the coefficients should
        # converge to the original data.
        H = mdl.H/np.sum(mdl.H, axis=0)
        assert_set_equal(H.T, self.H, decimal=1)

        # the reconstruction quality should still be close to perfect
        rec = mdl.frobenius_norm()
        assert(rec <= 0.1)
Beispiel #6
0
 def test_compute_h(self):
     mdl = CHNMF(self.data, num_bases=3)
     mdl.W = self.W
     mdl.factorize(niter=10, compute_w=False)
     assert_set_equal(mdl.H, self.H, decimal=2)
Beispiel #7
0
 def test_compute_w(self):
     mdl = SIVM(self.data, num_bases=3)
     mdl.H = self.H
     mdl.factorize(niter=10, compute_h=False)
     assert_set_equal(mdl.W, self.W, decimal=2)