Exemplo n.º 1
0
def test_SRM():
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2], align='SRM')
    assert np.allclose(result[0], result[1], rtol=1)
Exemplo n.º 2
0
def test_procrustes():
    data1 = load('spiral')
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2])
    assert np.allclose(result[0], result[1])
Exemplo n.º 3
0
def test_hyper():
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
                    [-0.43426149, 0.87492975, -0.21427761],
                    [-0.10761949, 0.18578133, 0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1, data2], align='hyper')
    assert np.allclose(
        result[0], result[1], rtol=1
    )  #note: this tolerance is probably too high, but fails at anything lower
Exemplo n.º 4
0
def test_procrustes():
    data = sio.loadmat('examples/sample_data/test_data.mat')
    data1 = data['spiral']
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
           [-0.43426149,  0.87492975, -0.21427761],
           [-0.10761949,  0.18578133,  0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1,data2])
    assert np.allclose(result[0],result[1])
Exemplo n.º 5
0
def test_srm():
    data = sio.loadmat('examples/sample_data/test_data.mat')
    data1 = data['spiral']
    rot = np.array([[-0.89433495, -0.44719485, -0.01348182],
           [-0.43426149,  0.87492975, -0.21427761],
           [-0.10761949,  0.18578133,  0.97667976]])
    data2 = np.dot(data1, rot)
    result = align([data1,data2], method='SRM')
    assert np.allclose(result[0],result[1], rtol=1) #note: this tolerance is probably too high, but fails at anything lower
Exemplo n.º 6
0
def test_align_shapes():
    # Should return data with the same shape as input data
    aligned = align(weights)
    assert all(al.shape == wt.shape for al, wt in zip(aligned, weights))
Exemplo n.º 7
0
def test_align_geo():
    aligned = align(geo)
    assert np.allclose(aligned[0], aligned[1])
Exemplo n.º 8
0
def main():

    print('\nRUNNNING ANALYSIS \n')
    print('\tRunning Alignment: ', ALIGN)

    # Get list of available files
    #  Note: this currently excludes first subject, because they are weird.
    dat_files = [file for file in os.listdir(DAT_PATH)[1:] if 'epo.fif' in file]

    # Create time definition vector
    times = np.arange(-1, 1, 1/100)

    ###################################################################################################

    for filter_setting in FILTER_SETTINGS:

        # Load (or reload) all subject data
        all_subjs = [read_epochs(os.path.join(DAT_PATH, f_name),
                             preload=True, verbose=None) for f_name in dat_files]

        print('\tRunning across {:1d} subjects.'.format(len(all_subjs)))

        f_label, f_low, f_high = filter_setting
        print('\t\tRunning filters:', f_label)

        all_data, all_labels = [], []

        for subj in all_subjs:

            # Enforce a minimum number of trials - skip subj if not met
            if len(subj) < N_EPOCHS:
                continue

            t_data, t_labels = extract_data(subj, l_freq=f_low, h_freq=f_high, resample=True)
            all_data.append(t_data)
            all_labels.append(t_labels)

        ###################################################################################################

        ## HYPERALIGNMENT

        # Data organization - extract matrices, and flatten to continuous data
        all_data_2d = [make_2d(dat) for dat in all_data]

        # Do alignment
        #   Note: this also switches orientation (takes the transpose) to match hypertools
        #     This is beacause align assumes data in orientation of [n_samples x n_channels]
        aligned_data = align([dat.T for dat in all_data_2d], align=ALIGN)
        aligned_data = [dat.T for dat in aligned_data]
        aligned_data = [make_3d(dat, N_EPOCHS) for dat in aligned_data]

        ###################################################################################################

        ## CLASSIFICATION

        # Run within subject classification - non time resolved
        within_scores = within_subj_classification(all_data, all_labels)

        # Get average results - within and across subjects
        within_subj_avgs = np.mean(within_scores, 1)
        within_glob_avg = np.mean(within_subj_avgs)

        # Within subject classification - time resolved
        ts_within_scores = time_within_subj_classification(all_data, all_labels)

        # Collapse across k-folds
        ts_within_scores = np.mean(ts_within_scores, 2)

        # Run prediction between subjects - on unaligned data
        btwn_scores = btwn_subj_classication(all_data, all_labels)

        # Get average results
        avg_btwn_scores = np.mean(btwn_scores)

        # Run prediction between subjects - on unaligned data and time-resolved
        ts_btwn_scores = time_btwn_subj_classification(all_data, all_labels)

        # Check within subject prediction of aligned data
        within_al1_scores = within_subj_classification(aligned_data, all_labels)

        # Run prediction between subjects - on aligned data
        btwn_al_scores = btwn_subj_classication(aligned_data, all_labels)

        # Get average results
        avg_btwn_al_scores = np.mean(btwn_al_scores)

        # Run prediction between subjects - on aligned data, across time points
        ts_btwn_al_scores = time_btwn_subj_classification(aligned_data, all_labels)

        # Calculate average across time points
        avg_time_class_btwn_al = np.mean(ts_btwn_al_scores, 0)

        # Set up data for plotting
        results = [ts_within_scores, ts_btwn_scores, ts_btwn_al_scores]
        labels = ['Within', 'Between', 'Aligned']

        # Make an amazing plot
        plot_results(times, results, labels, save_fig=True, save_name=f_label + '_' + ALIGN)
Exemplo n.º 9
0
def test_align_reduce5d_shape():
    # Should return data with same rowcnt but reduced to 5 columns
    aligned = align(weights, ndims=5)
    assert all(al.shape == (wt.shape[0], 5)
               for al, wt in zip(aligned, weights))