lplo = LeavePLabelOut(session_id_fmri, p=2)
    for train_index, test_index in lplo:
        # Split into train and test sets
        fmri_train, fmri_test = fmri[train_index], fmri[test_index]
        design_train, design_test = design[train_index], design[test_index]
        stimuli_train, stimuli_test = stimuli[train_index], stimuli[test_index]

        # Feature selection
        fmri_train, fmri_test = de.feature_selection(
            fmri_train, fmri_test, np.argmax(stimuli_train, axis=1))

        # Fit a ridge regression to predict the design matrix
        prediction_test, prediction_train, score = de.fit_ridge(
            fmri_train,
            fmri_test,
            design_train,
            design_test,
            double_prediction=True,
            extra=fmri_train)

        # Fit a logistic regression for deconvolution
        accuracy = de.logistic_deconvolution(prediction_train,
                                             prediction_test,
                                             stimuli_train,
                                             stimuli_test,
                                             logistic_window,
                                             delay=delay)

        scores.append(accuracy)
        subjects.append(subject)
        models.append('logistic deconvolution')
            continue

        labels = np.hstack([[session] * 20 for session in range(4)])
        lplo2 = LeavePLabelOut(labels, p=1)
        for train_id, test_id in lplo2:
            fmri_train, fmri_test = fmri_isi[train_id], fmri_isi[test_id]
            design_train, design_test = (design_isi[train_id],
                                         design_isi[test_id])
            stimuli_train, stimuli_test = (stimuli_isi[train_id],
                                           stimuli_isi[test_id])
            # Feature selection
            fmri_train, fmri_test = de.feature_selection(
                fmri_train, fmri_test, np.argmax(stimuli_train, axis=1))

            # Fit a ridge regression to predict the design matrix
            prediction_test, prediction_train, score = de.fit_ridge(
                fmri_train, fmri_test, design_train, design_test,
                double_prediction=True, extra=fmri_train)

            # Fit a logistic regression for deconvolution
            accuracy = de.logistic_deconvolution(
                prediction_train, prediction_test, stimuli_train,
                stimuli_test, logistic_window, delay=delay)

            scores.append(accuracy)
            subjects.append(subject + 1)
            models.append('logistic deconvolution')
            isis.append(isi)

    print('finished subject ' + str(subject))
            isi = 4.8
            time_window = 3
            delay = 3

        else:
            continue

        # Time window + feature selection
        fmri_train, fmri_test, stimuli_train, stimuli_test = de.apply_time_window(
            fmri_train,
            fmri_test,
            stimuli_train,
            stimuli_test,
            delay=delay,
            time_window=time_window,
            k=k)

        # Fit ridge regression
        prediction, score = de.fit_ridge(fmri_train, fmri_test, stimuli_train,
                                         stimuli_test)

        # Fit a logistic regression for deconvolution
        accuracy = de.ridge_scoring(prediction, stimuli_test)

        scores.append(accuracy)
        subjects.append(subject + 1)
        models.append('time-delayed embedding')
        isis.append(isi)

    print('finished subject ' + str(subject))
Exemple #4
0
                       for session in range(len(fmri))]

    # Stack the BOLD signals and the design matrices
    fmri = np.vstack(fmri)
    stimuli = np.vstack(stimuli)
    session_id_fmri = np.hstack(session_id_fmri)

    lplo = LeavePLabelOut(session_id_fmri, p=1)
    for train_index, test_index in lplo:
        # Split into train and test sets
        fmri_train, fmri_test = fmri[train_index], fmri[test_index]
        stimuli_train, stimuli_test = stimuli[train_index], stimuli[test_index]

        # Time window + feature selection
        fmri_train, fmri_test, stimuli_train, stimuli_test = de.apply_time_window(
            fmri_train, fmri_test, stimuli_train, stimuli_test, delay=delay,
            time_window=time_window, k=k)

        # Fit ridge regression
        prediction, score = de.fit_ridge(fmri_train, fmri_test, stimuli_train,
                                         stimuli_test)

        # Fit a logistic regression for deconvolution
        accuracy = de.ridge_scoring(prediction[:, 1:], stimuli_test[:, 1:])

        scores.append(accuracy)
        subjects.append(subject + 1)
        models.append('time-delayed embedding')

    print('finished subject ' + str(subject))
    stimuli = np.vstack(stimuli)
    session_id_fmri = np.hstack(session_id_fmri)

    lplo = LeavePLabelOut(session_id_fmri, p=2)
    for train_index, test_index in lplo:
        # Split into train and test sets
        fmri_train, fmri_test = fmri[train_index], fmri[test_index]
        design_train, design_test = design[train_index], design[test_index]
        stimuli_train, stimuli_test = stimuli[train_index], stimuli[test_index]

        # Feature selection
        fmri_train, fmri_test = de.feature_selection(
            fmri_train, fmri_test, np.argmax(stimuli_train, axis=1))

        # Fit a ridge regression to predict the design matrix
        prediction_train, prediction_test, score = de.fit_ridge(
            fmri_train, fmri_test, design_train, design_test)

        # Fit a logistic regression for deconvolution
        accuracy = de.logistic_deconvolution(prediction_train, prediction_test,
                                             stimuli_train, stimuli_test,
                                             logistic_window)

        scores.append(accuracy)
        subjects.append(subject)

    print('finished subject ' + str(subject))

dict = {}
dict['subject'] = subjects
dict['accuracy'] = scores