Package mvpa :: Package tests :: Module test_perturbsensana
[hide private]
[frames] | no frames]

Source Code for Module mvpa.tests.test_perturbsensana

 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 perturbation sensitivity analyzer.""" 
10   
11  from mvpa.datasets.masked import MaskedDataset 
12  from mvpa.measures.noiseperturbation import NoisePerturbationSensitivity 
13  from mvpa.datasets.splitters import NFoldSplitter 
14  from mvpa.algorithms.cvtranserror import CrossValidatedTransferError 
15  from mvpa.clfs.transerror import TransferError 
16   
17  from tests_warehouse import * 
18  from tests_warehouse_clfs import * 
19   
20 -class PerturbationSensitivityAnalyzerTests(unittest.TestCase):
21
22 - def setUp(self):
23 data = N.random.standard_normal(( 100, 3, 4, 2 )) 24 labels = N.concatenate( ( N.repeat( 0, 50 ), 25 N.repeat( 1, 50 ) ) ) 26 chunks = N.repeat( range(5), 10 ) 27 chunks = N.concatenate( (chunks, chunks) ) 28 mask = N.ones( (3, 4, 2) ) 29 mask[0,0,0] = 0 30 mask[1,3,1] = 0 31 self.dataset = MaskedDataset(samples=data, labels=labels, 32 chunks=chunks, mask=mask)
33 34
36 # compute N-1 cross-validation as datameasure 37 cv = CrossValidatedTransferError( 38 TransferError(sample_clf_lin), 39 NFoldSplitter(cvtype=1)) 40 # do perturbation analysis using gaussian noise 41 pa = NoisePerturbationSensitivity(cv, noise=N.random.normal) 42 43 # run analysis 44 map = pa(self.dataset) 45 46 # check for correct size of map 47 self.failUnless(len(map) == 22) 48 49 # dataset is noise -> mean sensitivity should be zero 50 self.failUnless(-0.2 < map.mean() < 0.2)
51 52
53 -def suite():
54 return unittest.makeSuite(PerturbationSensitivityAnalyzerTests)
55 56 57 if __name__ == '__main__': 58 import runner 59