Package mvpa :: Package tests :: Module test_splitsensana

[hide private]
[frames] | no frames]

# Source Code for Module mvpa.tests.test_splitsensana

     1  # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*-
     2  # vi: set ft=python sts=4 ts=4 sw=4 et:
     3  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
     4  #
     5  #   See COPYING file distributed along with the PyMVPA package for the
     6  #   copyright and license terms.
     7  #
     8  ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ### ##
     9  """Unit tests for PyMVPA SplittingSensitivityAnalyzer"""
    10
    11  from mvpa.datasets.splitters import NFoldSplitter
    12  from mvpa.measures.splitmeasure import SplitFeaturewiseMeasure, \
    13          TScoredFeaturewiseMeasure
    14  from mvpa.misc.data_generators import normalFeatureDataset
    15  from mvpa.misc.transformers import Absolute
    16  from tests_warehouse import *
    17  from tests_warehouse_clfs import *
    18
    19
    20 -class SplitSensitivityAnalyserTests(unittest.TestCase):
    21
    22      # XXX meta should work TODO
    23      @sweepargs(svm=clfswh['linear', 'svm', '!meta'])
    24 -    def testAnalyzer(self, svm):
    25          dataset = datasets['uni2small']
    26
    27          svm_weigths = svm.getSensitivityAnalyzer()
    28
    29          sana = SplitFeaturewiseMeasure(
    30                      svm_weigths,
    31                      NFoldSplitter(cvtype=1),
    32                      enable_states=['maps'])
    33
    34          maps = sana(dataset)
    35          nchunks = len(dataset.uniquechunks)
    36          nfeatures = dataset.nfeatures
    37          self.failUnless(len(maps) == nfeatures,
    38              msg='Lengths of the map %d is different from number of features %d'
    39                   % (len(maps), nfeatures))
    40          self.failUnless(sana.states.isKnown('maps'))
    41          allmaps = N.array(sana.maps)
    42          self.failUnless(allmaps[:,0].mean() == maps[0])
    43          self.failUnless(allmaps.shape == (nchunks, nfeatures))
    44
    45
    46      @sweepargs(svm=clfswh['linear', 'svm', '!meta'])
    47 -    def testTScoredAnalyzer(self, svm):
    48          self.dataset = normalFeatureDataset(perlabel=100,
    49                                              nlabels=2,
    50                                              nchunks=20,
    51                                              nonbogus_features=[0,1],
    52                                              nfeatures=4,
    53                                              snr=10)
    54          svm_weigths = svm.getSensitivityAnalyzer()
    55
    56          sana = TScoredFeaturewiseMeasure(
    57                      svm_weigths,
    58                      NFoldSplitter(cvtype=1),
    59                      enable_states=['maps'])
    60
    61          t = sana(self.dataset)
    62
    63          # correct size?
    64          self.failUnlessEqual(t.shape, (4,))
    65
    66          # check reasonable sensitivities
    67          t = Absolute(t)
    68          self.failUnless(N.mean(t[:2]) > N.mean(t[2:]))
    69
    70          # check whether SplitSensitivityAnalyzer 'maps' state is accessible
    71          self.failUnless(sana.states.isKnown('maps'))
    72          self.failUnless(N.array(sana.maps).shape == (20,4))
    73
    74
    75
    76 -def suite():
    77      return unittest.makeSuite(SplitSensitivityAnalyserTests)
    78
    79
    80  if __name__ == '__main__':
    81      import runner
    82