Example #1
0
 def __init__(self, identifier):
     regression = linear_regression(xarray_kwargs=dict(stimulus_coord='stimulus_id'))  # word
     correlation = pearsonr_correlation(xarray_kwargs=dict(correlation_coord='stimulus_id'))
     metric = CrossRegressedCorrelation(regression=regression, correlation=correlation,
                                        crossvalidation_kwargs=dict(splits=5, kfold=True, split_coord='stimulus_id',
                                                                    stratification_coord='sentence_id'))
     super(Fedorenko2016Encoding, self).__init__(identifier=identifier, metric=metric)
Example #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
Example #3
0
def ToliasCadena2017PLS():
    loader = AssemblyLoader()
    assembly_repetition = loader(average_repetition=False)
    assembly = loader(average_repetition=True)
    assembly.stimulus_set.name = assembly.stimulus_set_name

    similarity_metric = CrossRegressedCorrelation(
        regression=pls_regression(),
        correlation=pearsonr_correlation(),
        crossvalidation_kwargs={'stratification_coord': None})
    identifier = f'tolias.Cadena2017-pls'
    ceiler = InternalConsistency(split_coord='repetition_id')

    def ceiling():
        # This assembly has many stimuli that are only shown to a subset of the neurons.
        # When the loader runs with `average_repetition=True`, it automatically drops nan cells,
        # but for the `assembly_repetition`, it keeps all the rows.
        # If we now use the usual ceiling approach, the two halves will end up with NaN values
        # due to stimuli not being shown to neurons, which doesn't let us correlate.
        # Instead, we here drop all NaN cells and their corresponding stimuli,
        # which keeps only 43% of the original presentation rows, but lets us correlate again.
        assembly_nonan, stimuli = loader.dropna(assembly_repetition, assembly_repetition.attrs['stimulus_set'])
        return ceiler(assembly_nonan)

    return NeuralBenchmark(identifier=identifier, version=1,
                           assembly=assembly, similarity_metric=similarity_metric, visual_degrees=VISUAL_DEGREES,
                           ceiling_func=ceiling)
Example #4
0
 def __init__(self,
              identifier,
              split_coord='word',
              unique_split_values=False):
     self._logger = logging.getLogger(fullname(self))
     self._identifier = identifier
     assembly = LazyLoad(self._load_assembly)
     self._target_assembly = assembly
     regression = linear_regression(xarray_kwargs=dict(
         stimulus_coord='word_id',
         neuroid_coord='subject_id'))  # used for sorting -- keep at word_id
     correlation = pearsonr_correlation(xarray_kwargs=dict(
         correlation_coord='word_id',
         neuroid_coord='subject_id'))  # used for sorting -- keep at word_id
     self._metric = CrossRegressedCorrelation(
         regression=regression,
         correlation=correlation,
         crossvalidation_kwargs=dict(
             splits=5,
             kfold=True,
             split_coord=split_coord,
             stratification_coord='sentence_id',
             unique_split_values=unique_split_values))
     self._cross_subject = CartesianProduct(dividers=['subject_id'])
     self._ceiler = self.ManySubjectExtrapolationCeiling(
         subject_column='subject_id')
Example #5
0
    def __init__(self):
        ceiling = Score([1, np.nan],
                        coords={'aggregation': ['center', 'error']},
                        dims=['aggregation'])
        assembly_repetition = get_assembly()
        assert len(np.unique(assembly_repetition['region'])) == 1
        assert hasattr(assembly_repetition, 'repetition')
        self.region = 'IT'
        self.assembly = average_repetition(assembly_repetition)
        self._assembly = self.assembly
        self.timebins = timebins_from_assembly(self.assembly)

        self._similarity_metric = CrossRegressedCorrelation(
            regression=pls_regression(),
            correlation=pearsonr_correlation(),
            crossvalidation_kwargs=dict(
                stratification_coord=Split.Defaults.stratification_coord
                if hasattr(self.assembly, Split.Defaults.stratification_coord
                           ) else None))
        identifier = f'{assembly_repetition.name}-layer_selection'
        ceiler = InternalConsistency()
        super(_MockBenchmark,
              self).__init__(identifier=identifier,
                             ceiling_func=lambda: ceiler(assembly_repetition),
                             version='1.0')
Example #6
0
 def __init__(self, **kwargs):
     metric = CrossRegressedCorrelation(
         regression=linear_regression(xarray_kwargs=dict(stimulus_coord='stimulus_id')),
         correlation=pearsonr_correlation(xarray_kwargs=dict(correlation_coord='stimulus_id')),
         crossvalidation_kwargs=dict(split_coord='stimulus_id', stratification_coord=None))
     metric = Invert(metric)
     super(PereiraDecoding, self).__init__(metric=metric, **kwargs)
Example #7
0
def DicarloMajaj2015V4MaskParams(*regression_args, **regression_kwargs):
    return _DicarloMajaj2015Region('V4', identifier_metric_suffix='param_mask',
                                   similarity_metric=ScaledCrossRegressedCorrelation(
                                       regression=mask_regression_with_params(
                                           *regression_args, **regression_kwargs), 
                                       correlation=pearsonr_correlation(),
                                       crossvalidation_kwargs=dict(splits=4, stratification_coord='object_name')),
                                   ceiler=InternalConsistency())
Example #8
0
def DicarloSanghavi2020ITPLS():
    return _DicarloSanghavi2020Region(
        'IT',
        identifier_metric_suffix='pls',
        similarity_metric=CrossRegressedCorrelation(
            regression=pls_regression(),
            correlation=pearsonr_correlation(),
            crossvalidation_kwargs=dict(stratification_coord='object_name')),
        ceiler=InternalConsistency())
Example #9
0
def MovshonFreemanZiemba2013V2PLS():
    return _MovshonFreemanZiemba2013Region(
        'V2',
        identifier_metric_suffix='pls',
        similarity_metric=CrossRegressedCorrelation(
            regression=pls_regression(),
            correlation=pearsonr_correlation(),
            crossvalidation_kwargs=dict(stratification_coord='texture_type')),
        ceiler=InternalConsistency())
Example #10
0
 def __init__(self, bold_shift=None):
     assembly = load_Fedorenko2016() 
     self._target_assembly = assembly
     
     self._regression = pls_regression(xarray_kwargs=dict(stimulus_coord='stimulus_id')) # word
     self._correlation = pearsonr_correlation(xarray_kwargs=dict(correlation_coord='stimulus_id'))
     self._metric = CrossRegressedCorrelation(
         regression=self._regression, correlation=self._correlation,
         # crossvalidation_kwargs=dict(split_coord='sentence_id', stratification_coord=None))
         crossvalidation_kwargs=dict(split_coord='stimulus_id', stratification_coord='sentence_id', train_size=.8))
Example #11
0
def DicarloMajaj2015ITMask():
    return _DicarloMajaj2015Region(
        'IT',
        identifier_metric_suffix='mask',
        similarity_metric=ScaledCrossRegressedCorrelation(
            regression=mask_regression(),
            correlation=pearsonr_correlation(),
            crossvalidation_kwargs=dict(splits=2,
                                        stratification_coord='object_name')),
        ceiler=InternalConsistency())
Example #12
0
    def __init__(self, *args, **kwargs):
        super(Blank2014fROIEncoding, self).__init__(*args, **kwargs)

        regression = linear_regression(xarray_kwargs=dict(
            stimulus_coord='stimulus_id', neuroid_coord='fROI_area'))
        correlation = pearsonr_correlation(xarray_kwargs=dict(
            correlation_coord='stimulus_id', neuroid_coord='fROI_area'))
        self._metric = CrossRegressedCorrelation(
            regression=regression, correlation=correlation,
            crossvalidation_kwargs=dict(splits=5, kfold=True, split_coord='stimulus_id', stratification_coord='story'))
Example #13
0
 def test_small(self):
     assembly = NeuroidAssembly((np.arange(30 * 25) + np.random.standard_normal(30 * 25)).reshape((30, 25)),
                                coords={'image_id': ('presentation', np.arange(30)),
                                        'object_name': ('presentation', ['a', 'b', 'c'] * 10),
                                        'neuroid_id': ('neuroid', np.arange(25)),
                                        'region': ('neuroid', ['some_region'] * 25)},
                                dims=['presentation', 'neuroid'])
     metric = CrossRegressedCorrelation(regression=pls_regression(), correlation=pearsonr_correlation())
     score = metric(source=assembly, target=assembly)
     assert score.sel(aggregation='center') == approx(1, abs=.00001)
Example #14
0
def DicarloMajaj2015TransRegHighVar(*regression_args, **regression_kwargs):
    return _DicarloMajaj2015RegHighVar(
            identifier_metric_suffix='var6_trans',
            coord_list=['ty', 'tz'],
            similarity_metric=ScaledCrossRegressedCorrelation(
                regression=XarrayRegression(
                    MultiOutputRegressor(LinearSVR(
                        *regression_args, **regression_kwargs))), 
                correlation=pearsonr_correlation(),
                crossvalidation_kwargs=dict(
                    splits=4, stratification_coord='object_name')))
Example #15
0
def DicarloMajaj2015RotSemRegLowMidVar(*regression_args, **regression_kwargs):
    return _DicarloMajaj2015RegLowMidVar(
            identifier_metric_suffix='var03_rotsem',
            coord_list=['rxy_semantic', 'ryz_semantic', 'rxz_semantic'],
            similarity_metric=ScaledCrossRegressedCorrelation(
                regression=XarrayRegression(
                    MultiOutputRegressor(LinearSVR(
                        *regression_args, **regression_kwargs))), 
                correlation=pearsonr_correlation(),
                crossvalidation_kwargs=dict(
                    splits=4, stratification_coord='object_name')))
Example #16
0
 def __init__(self, bold_shift=None):
     assembly = load_Fedorenko2016() 
     self._target_assembly = assembly
             
     # avg code 
     # packaging file, change the benchmark to include averaging. 
     
     self._regression = pls_regression(xarray_kwargs=dict(stimulus_coord='stimulus_id')) # word
     self._correlation = pearsonr_correlation(xarray_kwargs=dict(correlation_coord='stimulus_id'))
     self._metric = CrossRegressedCorrelation(
         regression=self._regression, correlation=self._correlation,
         crossvalidation_kwargs=dict(split_coord='stimulus_id', stratification_coord='stimulus_id'))
def _standard_benchmark(identifier, load_assembly, visual_degrees, number_of_trials, stratification_coord, bibtex):
    assembly_repetition = LazyLoad(lambda: load_assembly(average_repetitions=False))
    assembly = LazyLoad(lambda: load_assembly(average_repetitions=True))
    similarity_metric = CrossRegressedCorrelation(
        regression=pls_regression(), correlation=pearsonr_correlation(),
        crossvalidation_kwargs=dict(stratification_coord=stratification_coord))
    ceiler = InternalConsistency()
    return NeuralBenchmark(identifier=f"{identifier}-pls", version=1,
                           assembly=assembly, similarity_metric=similarity_metric,
                           visual_degrees=visual_degrees, number_of_trials=number_of_trials,
                           ceiling_func=lambda: ceiler(assembly_repetition),
                           parent=None,
                           bibtex=bibtex)
Example #18
0
    def __init__(self, identifier, bold_shift=4):
        self._identifier = identifier
        assembly = LazyLoad(lambda: self._load_assembly(bold_shift))
        self._target_assembly = assembly
        regression = linear_regression(xarray_kwargs=dict(
            stimulus_coord='stimulus_id', neuroid_coord='neuroid_id'))
        correlation = pearsonr_correlation(xarray_kwargs=dict(
            correlation_coord='stimulus_id', neuroid_coord='neuroid_id'))
        self._metric = CrossRegressedCorrelation(
            regression=regression, correlation=correlation,
            crossvalidation_kwargs=dict(splits=5, kfold=True, split_coord='stimulus_id', stratification_coord='story'))

        self._ceiler = ExtrapolationCeiling(subject_column='subject_UID', post_process=self.post_process_ceilings)
Example #19
0
 def __init__(self, *args, **kwargs):
     super(Futrell2018SentencesEncoding, self).__init__(*args, **kwargs)
     regression = linear_regression(xarray_kwargs=dict(
         stimulus_coord='word_id', neuroid_coord='subject_id'))
     correlation = pearsonr_correlation(xarray_kwargs=dict(
         correlation_coord='word_id', neuroid_coord='subject_id'))
     self._metric = CrossRegressedCorrelation(
         regression=regression,
         correlation=correlation,
         crossvalidation_kwargs=dict(splits=5,
                                     kfold=True,
                                     unique_split_values=True,
                                     split_coord='sentence_id',
                                     stratification_coord=None))
Example #20
0
def ToliasCadena2017Mask():
    loader = AssemblyLoader()
    assembly_repetition = loader(average_repetition=False)
    assembly = loader(average_repetition=True)
    assembly.stimulus_set.name = assembly.stimulus_set_name

    similarity_metric = CrossRegressedCorrelation(
        regression=mask_regression(),
        correlation=pearsonr_correlation(),
        crossvalidation_kwargs={'splits': 4, 'stratification_coord': None})
    identifier = f'tolias.Cadena2017-mask'
    ceiler = InternalConsistency(split_coord='repetition_id')
    return NeuralBenchmark(identifier=identifier, version=1,
                           assembly=assembly, similarity_metric=similarity_metric, visual_degrees=VISUAL_DEGREES,
                           ceiling_func=lambda: ceiler(assembly_repetition))
Example #21
0
 def __init__(self, identifier):
     self._logger = logging.getLogger(fullname(self))
     self._identifier = identifier
     assembly = LazyLoad(self._load_assembly)
     self._target_assembly = assembly
     regression = linear_regression(xarray_kwargs=dict(
         stimulus_coord='word_id', neuroid_coord='subject_id'))
     correlation = pearsonr_correlation(xarray_kwargs=dict(
         correlation_coord='word_id', neuroid_coord='subject_id'))
     self._metric = CrossRegressedCorrelation(
         regression=regression,
         correlation=correlation,
         crossvalidation_kwargs=dict(splits=5,
                                     kfold=True,
                                     split_coord='word_id',
                                     stratification_coord='sentence_id'))
def _standard_benchmark(identifier, load_assembly, stratification_coord):
    assembly_repetition = LazyLoad(
        lambda: load_assembly(average_repetitions=False))
    assembly = LazyLoad(lambda: load_assembly(average_repetitions=True))
    similarity_metric = CrossRegressedCorrelation(
        regression=pls_regression(),
        correlation=pearsonr_correlation(),
        crossvalidation_kwargs=dict(stratification_coord=stratification_coord))
    ceiler = InternalConsistency()
    return NeuralBenchmark(
        identifier=f"{identifier}-pls",
        version=1,
        assembly=assembly,
        similarity_metric=similarity_metric,
        ceiling_func=lambda: ceiler(assembly_repetition),
        parent=None,
        paper_link='http://www.jneurosci.org/content/35/39/13402.short')
Example #23
0
 def test_across_images(self):
     values = (np.arange(30 * 25 * 5) +
               np.random.standard_normal(30 * 25 * 5)).reshape((30, 25, 5))
     assembly = NeuroidAssembly(
         values,
         coords={
             'image_id': ('presentation', np.arange(30)),
             'object_name': ('presentation', ['a', 'b', 'c'] * 10),
             'neuroid_id': ('neuroid', np.arange(25)),
             'region': ('neuroid', ['some_region'] * 25),
             'time_bin_start': ('time_bin', list(range(5))),
             'time_bin_end': ('time_bin', list(range(1, 6))),
         },
         dims=['presentation', 'neuroid', 'time_bin'])
     correlation = TemporalCorrelationAcrossImages(pearsonr_correlation())
     score = correlation(assembly, assembly)
     np.testing.assert_array_equal(score.dims, ['neuroid'])
     np.testing.assert_array_equal(score['neuroid_id'].values,
                                   list(range(25)))
     np.testing.assert_array_almost_equal(score.values, [1.] * 25)
     assert set(score.raw.dims) == {'neuroid', 'time_bin'}
Example #24
0
def ToliasCadena2017MaskParams(*regression_args, **regression_kwargs):
    loader = AssemblyLoader()
    assembly_repetition = loader(average_repetition=False)
    assembly = loader(average_repetition=True)
    assembly.stimulus_set.name = assembly.stimulus_set_name

    similarity_metric = CrossRegressedCorrelation(
        regression=mask_regression_with_params(
            *regression_args, **regression_kwargs), 
        correlation=pearsonr_correlation(),
        crossvalidation_kwargs={'splits': 4, 'stratification_coord': None})
    identifier = f'tolias.Cadena2017-param-mask'
    ceiler = InternalConsistency(split_coord='repetition_id')

    def ceiling():
        assembly_nonan, stimuli = loader.dropna(
                assembly_repetition, 
                assembly_repetition.attrs['stimulus_set'])
        return ceiler(assembly_nonan)
    return NeuralBenchmark(identifier=identifier, version=1,
                           assembly=assembly, similarity_metric=similarity_metric,
                           ceiling_func=ceiling)