Beispiel #1
0
 def testMethodFatorizationPriorBound(self):
     tes = np.array([0.07, 0.13])
     tes = tes[:, np.newaxis]
     t2 = np.array([0.1, 2])
     f = np.array([0.7, 0.3])
     (A, _) = utils.build_A(t2, tes, f)
     b = 1000*np.ones(31)
     b[0] = 0
     Scsf = np.exp(np.dot(-b, 3e-3))
     S = np.random.random(31)
     S[0] = 1
     S = np.stack((S, Scsf))
     X = np.dot(A,S)
     
     mask = 1
     params = {'max_iters': 10, 'max_sources': 2, 'tolfun': 1e-8, 'tolx': 1e-8 }
     t2_bounds = {'1': [0, 0.2], '2': [1.5, 2.5]}
     s_prior = {'2': Scsf}
     
     r = c = s = 1
     result = self.__create_result_object()
     
     obss = bss_cals.BssCals()
     obss._method_factorization(X, tes, mask, params, result, r, c, s, s_prior, t2_bounds)
     np.testing.assert_array_almost_equal(result.T2[r,c,s,:], t2, 6, 'Unexpected T2 values')
     np.testing.assert_array_almost_equal(result.f[r,c,s,:], f, 6, 'Unexpected f values')
     self.assertEqual(result.pd[r,c,s], 1, 'Unexpected S0 values')
     np.testing.assert_array_almost_equal(result.sources[r,c,s,:,:], S, 3, 'Unexpected sources')
     self.assertAlmostEqual(result.rel_error[r,c,s], 0, 6, 'Unexpected S0 values')
Beispiel #2
0
 def testBoundAFourTes(self):
     t2_bounds = {'1':[0, 0.15], '2':[0, 0.3], '3':[0, 0.5], '4':[0, 2]}
     
     t2  = np.array([0.075, 0.15, 0.25, 1])
     tes = np.array([0.04, 0.07, 0.13, 0.2])
     tes = tes[:, np.newaxis]
     f = np.array([0.25, 0.25, 0.25, 0.25])
     (_, Aref) = utils.build_A(t2,tes,f)
     
     A = np.ones((4, 4))
     obss = bss_cals.BssCals()
     A = obss._bound_A(A, t2_bounds, tes)
     A = A / np.linalg.norm(A, None, 0)
     self.assertIsNotNone(A, 'Missing bounded A')
     np.testing.assert_array_almost_equal(A, Aref, 6,'Wrong A')
Beispiel #3
0
    def testComputeActualA3ExisitingSources(self):
        t2 = np.array([0.075, 0.15, 2])
        tes = np.array([0.07, 0.13, 0.2])
        tes = tes[:, np.newaxis]
        f = np.array([0.5, 0.3, 0.2])
        (A, _) = utils.build_A(t2, tes, f)

        S = np.random.random((3, 30))
        S[:, 0] = 1
        X = np.dot(A, S)

        params = {'max_sources': 3}
        obss = bss.BSS()
        result = obss._compute_actual_A(X, A, tes, params)
        np.testing.assert_array_almost_equal(result['t2'], t2, 6,
                                             'Wrong T2 values')
        np.testing.assert_array_almost_equal(result['f'], f, 6,
                                             'Wrong f values')
        self.assertEqual(result['s0'], 1, 'Wrong S0 value')
Beispiel #4
0
    def testComputeActualAwithZero(self):
        t2 = np.array([0.075, 2])
        tes = np.array([0.07, 0.13])
        tes = tes[:, np.newaxis]
        f = np.array([1, 0])
        (A, _) = utils.build_A(t2, tes, f)

        S = np.random.random((2, 30))
        S[:, 0] = 1
        X = np.dot(A, S)

        params = {'max_sources': 2}
        obss = bss.BSS()
        result = obss._compute_actual_A(X, A, tes, params)
        np.testing.assert_array_almost_equal(result['t2'], [0.075, 0], 6,
                                             'Wrong T2 values')
        np.testing.assert_array_almost_equal(result['f'], [1, 0], 6,
                                             'Wrong f values')
        np.testing.assert_array_almost_equal(result['s0'], 1, 6,
                                             'Wrong S0 value')