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

Source Code for Module mvpa.tests.test_icamapper

 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 ICA mapper""" 
10   
11   
12  import unittest 
13  from mvpa.support.copy import deepcopy 
14  import numpy as N 
15  from mvpa.mappers.ica import ICAMapper 
16   
17  from mvpa.datasets import Dataset 
18   
19 -class ICAMapperTests(unittest.TestCase):
20
21 - def setUp(self):
22 # data: 40 sample feature line in 2d space (40x2; samples x features) 23 samples = N.vstack([N.arange(40.) for i in range(2)]).T 24 samples -= samples.mean() 25 samples += N.random.normal(size=samples.shape, scale=0.1) 26 self.ndlin = Dataset(samples=samples, labels=1, chunks=1) 27 28 # data: 40 sample feature line in 50d space (40x50; samples x features) 29 samples = N.vstack([N.arange(40.) for i in range(50)]).T 30 samples -= samples.mean() 31 samples += N.random.normal(size=samples.shape, scale=0.1) 32 self.largefeat = Dataset(samples=samples, labels=1, chunks=1) 33 34 self.pm = ICAMapper()
35 36
37 - def testSimpleICA(self):
38 # train 39 self.pm.train(self.ndlin) 40 41 self.failUnlessEqual(self.pm.proj.shape, (2, 2)) 42 43 # now project data into ICA space 44 p = self.pm.forward(self.ndlin.samples) 45 46 self.failUnlessEqual(p.shape, (40, 2)) 47 48 # check that the mapped data can be fully recovered by 'reverse()' 49 self.failUnless(N.abs(self.pm.reverse(p) - self.ndlin.samples).mean() \ 50 < 0.0001)
51 52 53 # def testAutoOptimzeICA(self): 54 # # train 55 # self.pm.train(self.largefeat) 56 # 57 # self.failUnlessEqual(self.pm.proj.shape, (50, 40)) 58 # 59 # # now project data into ICA space 60 ## p = self.pm.forward(self.largefeat.samples) 61 # 62 # self.failUnless(p.shape[1] == 40) 63 # print self.pm.proj 64 # print self.pm.recon 65 # print p 66 67 # P.scatter(p[:20,0], p[:20,1],color='green') 68 # P.scatter(p[20:,0], p[20:,1], color='red') 69 # P.show() 70 # self.failUnless(N.abs(self.pm.reverse(p) - self.largefeat.samples).mean() \ 71 # < 0.0001) 72
73 -def suite():
74 return unittest.makeSuite(ICAMapperTests)
75 76 77 if __name__ == '__main__': 78 import runner 79