To provide the most recent news and documentation www.pymvpa.org reflects the development 2.0 series (renamed 0.6 series) of PyMVPA. If you are interested in the documentation of the previous stable 0.4 series of PyMVPA, please visit v04.pymvpa.org.

Minimal Searchlight ExampleΒΆ

The term Searchlight refers to an algorithm that runs a scalar Measure on all possible spheres of a certain size within a dataset (that provides information about distances between feature locations). The measure typically computed is a cross-validation of a classifier performance (see CrossValidation section in the tutorial). The idea to use a searchlight as a sensitivity analyzer on fMRI datasets stems from Kriegeskorte et al. (2006).

A searchlight analysis is can be easily performed. This examples shows a minimal draft of a complete analysis.

First import a necessary pieces of PyMVPA – this time each bit individually.

import numpy as np

from mvpa2.generators.partition import OddEvenPartitioner
from mvpa2.clfs.svm import LinearCSVMC
from mvpa2.measures.base import CrossValidation
from mvpa2.measures.searchlight import sphere_searchlight
from mvpa2.testing.datasets import datasets
from mvpa2.mappers.fx import mean_sample

For the sake of simplicity, let’s use a small artificial dataset.

# Lets just use our tiny 4D dataset from testing battery
dataset = datasets['3dlarge']

Now it only takes three lines for a searchlight analysis.

# setup measure to be computed in each sphere (cross-validated
# generalization error on odd/even splits)
cv = CrossValidation(LinearCSVMC(), OddEvenPartitioner())

# setup searchlight with 2 voxels radius and measure configured above
sl = sphere_searchlight(cv, radius=2, space='myspace',
                        postproc=mean_sample())

# run searchlight on dataset
sl_map = sl(dataset)

print 'Best performing sphere error:', np.min(sl_map.samples)

If this analysis is done on a fMRI dataset using NiftiDataset the resulting searchlight map (sl_map) can be mapped back into the original dataspace and viewed as a brain overlay. Another example shows a typical application of this algorithm.

See also

The full source code of this example is included in the PyMVPA source distribution (doc/examples/searchlight_minimal.py).

Previous topic

Efficient cross-validation using a cached kernel

Next topic

Searchlight on fMRI data

NeuroDebian

NITRC-listed