Exemple #1
0
def decode_voxels():
    assembly = load_voxels()
    cross_validation = CrossValidationSingle(splits=1,
                                             split_coord='stimulus_id',
                                             stratification_coord='story')

    subjects = list(sorted(set(assembly['subject_UID'].values)))
    scores = []
    for subject in subjects:
        subject_index = [
            subject == coord_subject
            for coord_subject in assembly['subject_UID'].values
        ]
        subject_assembly = assembly[{'neuroid': subject_index}]
        subject_score = cross_validation(subject_assembly, apply=fit_decode)
        subject_score = subject_score.sel(
            aggregation='center')  # since we're only doing one split
        print(
            f"subject {subject}: "
            f"{subject_score.sel(accuracy_aggregation='center', train_test='train').values:.2f} train, "
            f"{subject_score.sel(accuracy_aggregation='center', train_test='test').values:.2f} test"
        )
        subject_score = subject_score.expand_dims('subject')
        subject_score['subject'] = [subject]
        scores.append(subject_score)
    scores = Score.merge(*scores)
    return scores
Exemple #2
0
def fROI_correlation():
    assembly = load_voxels()

    stories = list(sorted(set(assembly['story'].values)))
    subjects = list(sorted(set(assembly['subject_UID'].values)))
    split_scores = []
    correlate = pearsonr_correlation(xarray_kwargs=dict(correlation_coord='stimulus_id', neuroid_coord='fROI_area'))
    cross_stories_subjects = list(itertools.product(stories, subjects))
    for story, heldout_subject in tqdm(cross_stories_subjects, desc='cross-{story,subject}'):
        story_assembly = assembly[{'presentation': [coord_story == story for coord_story in assembly['story'].values]}]
        subject_pool = story_assembly[{'neuroid': [subject != heldout_subject
                                                   for subject in story_assembly['subject_UID'].values]}]
        subject_pool = average_subregions(subject_pool)
        heldout = story_assembly[{'neuroid': [subject == heldout_subject
                                              for subject in story_assembly['subject_UID'].values]}]
        heldout = average_subregions(heldout)
        split_score = correlate(subject_pool, heldout)
        split_score = type(split_score)(split_score.values, coords={
            coord: (dims, values) for coord, dims, values in walk_coords(split_score)
            if not coord.startswith('subject_') and coord != 'neuroid_id'}, dims=split_score.dims)

        split_score = split_score.expand_dims('heldout_subject').expand_dims('story')
        split_score['heldout_subject'], split_score['story'] = [heldout_subject], [story]
        split_scores.append(split_score)
    correlation = Score.merge(*split_scores)

    correlation = apply_aggregate(lambda scores: scores.mean('neuroid').mean('story'), correlation)
    center = correlation.mean('heldout_subject')
    error = correlation.std('heldout_subject')
    score = Score([center, error], coords={**{'aggregation': ['center', 'error']},
                                           **{coord: (dims, values) for coord, dims, values in walk_coords(center)}},
                  dims=('aggregation',) + center.dims)
    score.attrs[Score.RAW_VALUES_KEY] = correlation.attrs[Score.RAW_VALUES_KEY]
    return score
Exemple #3
0
def decode_fROI():
    assembly = load_voxels()
    assembly = average_subregions(assembly)
    cross_validation = CrossValidationSingle(splits=10,
                                             split_coord='stimulus_id',
                                             stratification_coord='story')
    score = cross_validation(assembly, apply=fit_decode)
    return score
Exemple #4
0
 def _load_assembly(self, bold_shift):
     assembly = load_voxels(bold_shift_seconds=bold_shift)
     return assembly