

def testModelIdentification(self):
    ' generate VAR signals, mix them, and see if MVARICA can reconstruct the signals\n            do this for every backend '
    b0 = np.zeros((3, 6))
    b0[1:3, 2:6] = [[0.4, (- 0.2), 0.3, 0.0], [(- 0.7), 0.0, 0.9, 0.0]]
    m0 = b0.shape[0]
    (l, t) = (1000, 100)
    noisefunc = (lambda : ((np.random.normal(size=(1, m0)) ** 3) / 1000.0))
    var = VAR(2)
    var.coef = b0
    sources = var.simulate([l, t], noisefunc)
    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(np.transpose(mix), sources)
    for (backend_name, backend_gen) in scot.backend.items():
        api = scot.Workspace({
            'model_order': 2,
        }, backend=backend_gen(), reducedim=0.99)
        api.set_data(data)
        api.do_mvarica()
        permutations = np.array([[0, 1, 2, 3, 4, 5], [0, 1, 4, 5, 2, 3], [2, 3, 4, 5, 0, 1], [2, 3, 0, 1, 4, 5], [4, 5, 0, 1, 2, 3], [4, 5, 2, 3, 0, 1]])
        signperms = np.array([[1, 1, 1, 1, 1, 1], [1, 1, 1, 1, (- 1), (- 1)], [1, 1, (- 1), (- 1), 1, 1], [1, 1, (- 1), (- 1), (- 1), (- 1)], [(- 1), (- 1), 1, 1, 1, 1], [(- 1), (- 1), 1, 1, (- 1), (- 1)], [(- 1), (- 1), (- 1), (- 1), 1, 1], [(- 1), (- 1), (- 1), (- 1), (- 1), (- 1)]])
        (best, d) = (np.inf, None)
        for perm in permutations:
            b = api.var_.coef[(perm[::2] // 2), :]
            b = b[:, perm]
            for sgn in signperms:
                c = ((b * np.repeat([sgn], 3, 0)) * np.repeat([sgn[::2]], 6, 0).T)
                err = np.sum(((c - b0) ** 2))
                if (err < best):
                    best = err
                    d = c
        assert_allclose(d, b0, rtol=0.01, atol=0.02)

dataset/ETHPy150Open scot-dev/scot/scot/tests/test_ooapi.py TestMVARICA.testModelIdentification/original