Skip to content

Commit

Permalink
add Kar2018{hvm,cocogray} benchmarks
Browse files Browse the repository at this point in the history
not all unit tests pass. Precomputed features don't work yet because the StimulusSet differs (see brain-score/brainio_contrib#24), and the later numbers have not yet been run
  • Loading branch information
mschrimpf committed Feb 21, 2020
1 parent 44f28e8 commit 157dbe3
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
41 changes: 41 additions & 0 deletions brainscore/benchmarks/kar2018.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import brainscore
from brainscore.benchmarks._neural_common import NeuralBenchmark, average_repetition
from brainscore.metrics.ceiling import InternalConsistency
from brainscore.metrics.regression import CrossRegressedCorrelation, pls_regression, pearsonr_correlation
from brainscore.utils import LazyLoad


def DicarloKar2018hvmPLS():
assembly_repetition = LazyLoad(lambda: load_assembly(stimuli='hvm', average_repetitions=False))
assembly = LazyLoad(lambda: load_assembly(stimuli='hvm', average_repetitions=True))
similarity_metric = CrossRegressedCorrelation(
regression=pls_regression(), correlation=pearsonr_correlation(),
crossvalidation_kwargs=dict(stratification_coord='object_name'))
ceiler = InternalConsistency()
return NeuralBenchmark(identifier=f'dicarlo.Kar2018hvm-pls', version=1,
assembly=assembly, similarity_metric=similarity_metric,
ceiling_func=lambda: ceiler(assembly_repetition),
parent='IT', paper_link=None)


def DicarloKar2018cocoPLS():
assembly_repetition = LazyLoad(lambda: load_assembly(stimuli='cocogray', average_repetitions=False))
assembly = LazyLoad(lambda: load_assembly(stimuli='cocogray', average_repetitions=True))
similarity_metric = CrossRegressedCorrelation(
regression=pls_regression(), correlation=pearsonr_correlation(),
crossvalidation_kwargs=dict(stratification_coord='label'))
ceiler = InternalConsistency()
return NeuralBenchmark(identifier=f'dicarlo.Kar2018coco-pls', version=1,
assembly=assembly, similarity_metric=similarity_metric,
ceiling_func=lambda: ceiler(assembly_repetition),
parent='IT', paper_link=None)


def load_assembly(stimuli, average_repetitions):
assembly = brainscore.get_assembly(name=f'dicarlo.Kar2018{stimuli}')
assembly = assembly.squeeze("time_bin")
assembly.load()
assembly = assembly.transpose('presentation', 'neuroid')
if average_repetitions:
assembly = average_repetition(assembly)
return assembly
18 changes: 18 additions & 0 deletions tests/test_benchmarks/test___init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ class TestStandardized:
marks=pytest.mark.memory_intense),
pytest.param('dicarlo.Majaj2015.IT-rdm', approx(.887618, abs=.001),
marks=pytest.mark.memory_intense),
pytest.param('dicarlo.Kar2018hvm-pls', approx(.842015, abs=.001),
marks=pytest.mark.memory_intense),
pytest.param('dicarlo.Kar2018coco-pls', approx(.795665, abs=.001),
marks=pytest.mark.memory_intense),
])
def test_ceilings(self, benchmark, expected):
benchmark = benchmark_pool[benchmark]
Expand All @@ -45,6 +49,10 @@ def test_ceilings(self, benchmark, expected):
marks=pytest.mark.memory_intense),
pytest.param('dicarlo.Majaj2015.IT-pls', approx(.823433, abs=.001),
marks=pytest.mark.memory_intense),
pytest.param('dicarlo.Kar2018hvm-pls', approx(.823433, abs=.001),
marks=pytest.mark.memory_intense),
pytest.param('dicarlo.Kar2018coco-pls', approx(.856989, abs=.001),
marks=pytest.mark.memory_intense),
])
def test_self_regression(self, benchmark, expected):
benchmark = benchmark_pool[benchmark]
Expand Down Expand Up @@ -94,6 +102,16 @@ def test_FreemanZiemba2013(self, benchmark, expected):
def test_Majaj2015(self, benchmark, expected):
self.run_test(benchmark=benchmark, file='alexnet-majaj2015.private-features.12.pkl', expected=expected)

@pytest.mark.memory_intense
def test_Kar2018hvm(self):
self.run_test(benchmark='dicarlo.Kar2018hvm-pls', file='alexnet-hvm-features.12.pkl',
expected=approx(.490236, abs=.005))

@pytest.mark.memory_intense
def test_Kar2018coco(self):
self.run_test(benchmark='dicarlo.Kar2018coco-pls', file='alexnet-cocogray-features.12.pkl',
expected=approx(.490236, abs=.005))

@pytest.mark.memory_intense
@pytest.mark.requires_gpu
def test_IT_mask_alexnet(self):
Expand Down

0 comments on commit 157dbe3

Please sign in to comment.