예제 #1
0
 def testInterface(self):
     self.assertRaises(TypeError, plainica.plainica)
     # simply pass in different data shapes and see if the functions runs without error
     plainica.plainica(np.sin(np.arange(30)).reshape(
         (10, 3)))  # 10 samples, 3 channels
     plainica.plainica(np.sin(np.arange(30)).reshape(
         (5, 3, 2)))  # 5 samples, 3 channels, 2 trials
예제 #2
0
    def testModelIdentification(self):
        """ generate independent signals, mix them, and see if ICA can reconstruct the mixing matrix
            do this for every backend """

        # original model coefficients
        b0 = np.zeros((3, 3))  # no connectivity
        m0 = b0.shape[0]
        l, t = 100, 100

        # generate VAR sources with non-gaussian innovation process, otherwise ICA won't work
        noisefunc = lambda: np.random.normal(size=(1, m0))**3

        var = VAR(1)
        var.coef = b0
        sources = var.simulate([l, t], noisefunc)

        # simulate volume conduction... 3 sources measured with 7 channels
        mix = [[0.5, 1.0, 0.5, 0.2, 0.0, 0.0, 0.0],
               [0.0, 0.2, 0.5, 1.0, 0.5, 0.2, 0.0],
               [0.0, 0.0, 0.0, 0.2, 0.5, 1.0, 0.5]]
        data = datatools.dot_special(sources, mix)

        backend_modules = [import_module('scot.' + b) for b in scot.backends]

        for bm in backend_modules:

            result = plainica.plainica(data, backend=bm.backend)

            i = result.mixing.dot(result.unmixing)
            self.assertTrue(
                np.allclose(i, np.eye(i.shape[0]), rtol=1e-6, atol=1e-7))

            permutations = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0],
                            [2, 0, 1], [2, 1, 0]]

            bestdiff = np.inf
            bestmix = None

            absmix = np.abs(result.mixing)
            absmix /= np.max(absmix)

            for p in permutations:
                estmix = absmix[p, :]
                diff = np.sum((np.abs(estmix) - np.abs(mix))**2)

                if diff < bestdiff:
                    bestdiff = diff
                    bestmix = estmix

            self.assertTrue(np.allclose(bestmix, mix, rtol=1e-1, atol=1e-1))
예제 #3
0
    def testModelIdentification(self):
        """ generate independent signals, mix them, and see if ICA can reconstruct the mixing matrix
            do this for every backend """

        # original model coefficients
        b0 = np.zeros((3, 3))    # no connectivity
        m0 = b0.shape[0]
        l, t = 100, 100

        # generate VAR sources with non-gaussian innovation process, otherwise ICA won't work
        noisefunc = lambda: np.random.normal(size=(1, m0)) ** 3

        var = VAR(1)
        var.coef = b0
        sources = var.simulate([l, t], noisefunc)

        # simulate volume conduction... 3 sources measured with 7 channels
        mix = [[0.5, 1.0, 0.5, 0.2, 0.0, 0.0, 0.0],
               [0.0, 0.2, 0.5, 1.0, 0.5, 0.2, 0.0],
               [0.0, 0.0, 0.0, 0.2, 0.5, 1.0, 0.5]]
        data = datatools.dot_special(sources, mix)

        backend_modules = [import_module('scot.backend.' + b) for b in scot.backend.__all__]

        for bm in backend_modules:

            result = plainica.plainica(data, backend=bm.backend)

            i = result.mixing.dot(result.unmixing)
            self.assertTrue(np.allclose(i, np.eye(i.shape[0]), rtol=1e-6, atol=1e-7))

            permutations = [[0, 1, 2], [0, 2, 1], [1, 0, 2], [1, 2, 0], [2, 0, 1], [2, 1, 0]]

            bestdiff = np.inf
            bestmix = None

            absmix = np.abs(result.mixing)
            absmix /= np.max(absmix)

            for p in permutations:
                estmix = absmix[p, :]
                diff = np.sum((np.abs(estmix) - np.abs(mix)) ** 2)

                if diff < bestdiff:
                    bestdiff = diff
                    bestmix = estmix

            self.assertTrue(np.allclose(bestmix, mix, rtol=1e-1, atol=1e-1))
예제 #4
0
파일: test_plainica.py 프로젝트: cbrnr/scot
 def testInterface(self):
     self.assertRaises(TypeError, plainica.plainica)
     # simply pass in different data shapes and see if the functions runs without error
     plainica.plainica(np.sin(np.arange(30)).reshape((10, 3)))    # 10 samples, 3 channels
     plainica.plainica(np.sin(np.arange(30)).reshape((5, 3, 2)))  # 5 samples, 3 channels, 2 trials