[pymvpa] spatial normalization for each searchlight

Yaroslav Halchenko debian at onerussian.com
Fri Sep 21 18:01:52 UTC 2012


;-)

Easy... and multiple ways to achieve

1. you can create a 'MappedClassifier' with any "mapper" which
would preprocess your data somehow.  E.g. I could create a mapper which
would zscore each pattern:

    class ZScoreFeaturesMapper(Mapper):
        """Very basic mapper which would take care about standardizing
        all features within each sample separately
        """
        def _forward_data(self, data):
            return (data - np.mean(data, axis=1)[:, None])/np.std(data, axis=1)[:, None]

(adjust above one for your needs ;) ) and then create classifier which
would use it

    clf = MappedClassifier(clf, ZScoreFeaturesMapper())

BUT it is a bit wastefull though since in this case it doesn't need to be done
within cross-validation fold since you are operating on each sample separately
anyways and without any regard to the labels, so I think you could simply:

2.  Rely on the fact that CrossValidation is also a 'Mapper' you can
chain the two together ;):

       cv_chained = ChainMapper([ZScoreFeaturesMapper(auto_train=True),
                                 CrossValidation(sample_clf_lin, NFoldPartitioner())])

I am committing a unittest which tests that both provide the same results (just to make sure ;) ):

        from mvpa2.clfs.gnb import GNB
        from mvpa2.mappers.base import Mapper
        from mvpa2.clfs.meta import MappedClassifier

        sample_clf = GNB()              # fast and deterministic

        class ZScoreFeaturesMapper(Mapper):
            """Very basic mapper which would take care about standardizing
            all features within each sample separately
            """
            def _forward_data(self, data):
                return (data - np.mean(data, axis=1)[:, None])/np.std(data, axis=1)[:, None]

        # only do partial to save time
        sl_kwargs = dict(radius=2, center_ids=[3, 50])
        clf_mapped = MappedClassifier(sample_clf, ZScoreFeaturesMapper())
        cv = CrossValidation(clf_mapped, NFoldPartitioner())
        sl = sphere_searchlight(cv, **sl_kwargs)
        results_mapped = sl(self.dataset)

        cv_chained = ChainMapper([ZScoreFeaturesMapper(auto_train=True),
                                  CrossValidation(sample_clf, NFoldPartitioner())])
        sl_chained = sphere_searchlight(cv_chained, **sl_kwargs)
        results_chained = sl_chained(self.dataset)

        assert_array_equal(results_mapped, results_chained)


Cheers,

On Fri, 21 Sep 2012, Konatsu Miyamoto wrote:

>    Dear PyMVPA experts,

>    I'd like to do spatial rather than temporal normalization for each
>    classification sample to equalize the mean intensity among samples at each
>    time point.

>    It's relatively straightforward to do so for self-defined, static ROI
>    masks but less trivial for searchlight analyses. Is there a 'preproc'
>    argument for sphere_searchlight() like postproc=mean_sample()? If not, how
>    can I demean patterns within these dynamically running searchlights?

>    Thanks!
>    Konatsu

> _______________________________________________
> Pkg-ExpPsy-PyMVPA mailing list
> Pkg-ExpPsy-PyMVPA at lists.alioth.debian.org
> http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-exppsy-pymvpa


-- 
Yaroslav O. Halchenko
Postdoctoral Fellow,   Department of Psychological and Brain Sciences
Dartmouth College, 419 Moore Hall, Hinman Box 6207, Hanover, NH 03755
Phone: +1 (603) 646-9834                       Fax: +1 (603) 646-1419
WWW:   http://www.linkedin.com/in/yarik        



More information about the Pkg-ExpPsy-PyMVPA mailing list