Exemplo n.º 1
0
 def test_nan_flag_equals_noflag(self):
     assert_almost_equal(
         sum_tc(self.a,
                nans=True,
                standardize_subs=False,
                standardize_out=False),
         sum_tc(self.a,
                nans=False,
                standardize_subs=False,
                standardize_out=False))
Exemplo n.º 2
0
 def test_nan_misflag_returns_nan(self):
     ts_nan = self.a.copy()
     ts_nan[:, 0] = np.nan
     assert any(
         np.isnan(
             sum_tc(ts_nan,
                    nans=False,
                    standardize_subs=False,
                    standardize_out=False)))
Exemplo n.º 3
0
def crosscor_full(A, B=None, nan_thresh=None):
    """From data (dims sub x seg x vox) calculate sub against others pattern cor

    Parameters:
        A: sub x seg x vox matrix
        B: (optional) seg x vox matrix

    Returns:
        seg x seg correlation matrix
    """
    # standardize all along last dim, so don't need to in correlation
    A = standardize(A)

    all_cors = []
    # Within group correlations
    if B is None:
        others = sum_tc(A)
        for sub in A:
            # check for nan
            to_remove = np.any(np.isnan(sub), axis=0)
            if np.any(to_remove):
                tmp_sub = sub[..., to_remove]
                tmp_others = others[..., to_remove]
            else:
                tmp_sub, tmp_others = sub, others
            # cross correlate (1 x seg x seg)
            if nan_thresh is not None and to_remove.mean() > nan_thresh:
                cormat = np.empty(sub.shape[0:1] * 2) * np.nan
            else:
                cormat = crosscor(tmp_sub,
                                  standardize(tmp_others - tmp_sub),
                                  standardized=True)
            all_cors.append(cormat)
        return np.array(all_cors)
    # Between group correlations
    else:
        B = standardize(B)
        for sub in A:
            cormat = crosscor(sub, B, standardized=True)
            all_cors.append(cormat)
        return np.array(all_cors)
Exemplo n.º 4
0
def crosscor_full(A, B=None, nan_thresh=None):
    """From data (dims sub x seg x vox) calculate sub against others pattern cor

    Parameters:
        A: sub x seg x vox matrix
        B: (optional) seg x vox matrix

    Returns:
        seg x seg correlation matrix
    """
    # standardize all along last dim, so don't need to in correlation
    A = standardize(A)

    all_cors = []
    # Within group correlations
    if B is None:
        others = sum_tc(A)
        for sub in A:
            # check for nan
            to_remove = np.any(np.isnan(sub), axis=0)
            if np.any(to_remove):
                tmp_sub = sub[...,to_remove]
                tmp_others = others[..., to_remove]
            else:
                tmp_sub, tmp_others = sub, others
            # cross correlate (1 x seg x seg)
            if nan_thresh is not None and to_remove.mean() > nan_thresh:
                cormat = np.empty(sub.shape[0:1]*2) * np.nan
            else:
                cormat = crosscor(tmp_sub, standardize(tmp_others - tmp_sub), standardized=True)
            all_cors.append(cormat)
        return np.array(all_cors)
    # Between group correlations
    else:
        B = standardize(B)
        for sub in A:
            cormat = crosscor(sub, B, standardized=True)
            all_cors.append(cormat)
        return np.array(all_cors)
Exemplo n.º 5
0
 def test_standardize_in_equal_standardize_func(self):
     stand_a = standardize(self.a)
     assert_almost_equal(sum_tc(self.a, standardize_subs=True),
                         sum_tc(stand_a, standardize_subs=False))
Exemplo n.º 6
0
 def test_standardize_out_equal_standardize_func(self):
     summed = sum_tc(self.a, standardize_out=True)
     assert_almost_equal(summed, standardize(summed))
Exemplo n.º 7
0
 def test_standardize_out_var(self):
     sd = np.std(sum_tc(self.a, standardize_out=True), axis=-1, ddof=1)
     assert_almost_equal(1, sd)
Exemplo n.º 8
0
 def test_standardize_out_mean(self):
     mew = np.mean(sum_tc(self.a, standardize_out=True), axis=-1)
     assert_almost_equal(0, mew)
Exemplo n.º 9
0
 def test_standardize_not_inplace(self):
     assert sum_tc(self.a, standardize_subs=True) is not self.a
Exemplo n.º 10
0
 def test_nan_flag_equals_noflag(self):
     assert_almost_equal(sum_tc(self.a, nans = True, standardize_subs=False, standardize_out=False), 
                         sum_tc(self.a, nans=False, standardize_subs=False, standardize_out=False))
Exemplo n.º 11
0
 def test_nan_misflag_returns_nan(self):
     ts_nan = self.a.copy()
     ts_nan[:,0] = np.nan
     assert any(np.isnan(sum_tc(ts_nan, nans=False, standardize_subs=False, standardize_out=False)))
Exemplo n.º 12
0
 def test_standardize_in_equal_standardize_func(self):
     stand_a = standardize(self.a)
     assert_almost_equal(sum_tc(self.a, standardize_subs=True),
                         sum_tc(stand_a, standardize_subs=False))
Exemplo n.º 13
0
 def test_standardize_out_equal_standardize_func(self):
     summed = sum_tc(self.a, standardize_out=True)
     assert_almost_equal(summed, standardize(summed))
Exemplo n.º 14
0
 def test_standardize_out_var(self):
     sd = np.std(sum_tc(self.a, standardize_out=True), axis=-1, ddof=1)
     assert_almost_equal(1, sd)
Exemplo n.º 15
0
 def test_standardize_out_mean(self):
     mew = np.mean(sum_tc(self.a, standardize_out=True), axis=-1)
     assert_almost_equal(0, mew)
Exemplo n.º 16
0
 def test_standardize_not_inplace(self):
     assert sum_tc(self.a, standardize_subs=True) is not self.a
Exemplo n.º 17
0
 def test_3d(self):
     solution = [[24., 28.], [32., 36.]]
     assert_almost_equal(sum_tc(self.ts_3d), solution)
Exemplo n.º 18
0
 def test_3d(self):
     solution= [[ 24.,  28.],
                [ 32.,  36.]]
     assert_almost_equal(sum_tc(self.ts_3d), solution)