Package mvpa :: Package mappers :: Module ica
[hide private]
[frames] | no frames]

Source Code for Module mvpa.mappers.ica

 1  #emacs: -*- mode: python-mode; py-indent-offset: 4; indent-tabs-mode: nil -*- 
 2  #ex: set 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  """Data mapper""" 
10   
11  __docformat__ = 'restructuredtext' 
12   
13  import numpy as N 
14   
15  from mvpa.base.dochelpers import enhancedDocString 
16  from mvpa.mappers.base import ProjectionMapper 
17   
18  from mdp.nodes import FastICANode, CuBICANode 
19   
20   
21 -class ICAMapper(ProjectionMapper):
22 """Mapper to project data onto ICA components estimated from some dataset. 23 24 After the mapper has been instantiated, it has to be train first. The ICA 25 mapper only handles 2D data matrices. 26 """
27 - def __init__(self, algorithm='cubica', transpose=False, **kwargs):
28 ProjectionMapper.__init__(self, **kwargs) 29 30 self._algorithm = algorithm 31 self._transpose = transpose
32 33 __doc__ = enhancedDocString('ICAMapper', locals(), ProjectionMapper) 34 35
36 - def _train(self, dataset):
37 """Determine the projection matrix onto the components from 38 a 2D samples x feature data matrix. 39 """ 40 white_param = {} 41 42 # more features than samples? -> rank deficiancy 43 # if not tranposing the data, MDP has to do SVD prior to ICA 44 if dataset.samples.shape[1] > dataset.samples.shape[0] \ 45 and not self._transpose: 46 white_param['svd'] = True 47 48 if self._algorithm == 'fastica': 49 node = FastICANode(white_parm=white_param, 50 dtype=dataset.samples.dtype) 51 elif self._algorithm == 'cubica': 52 node = CuBICANode(white_parm=white_param, 53 dtype=dataset.samples.dtype) 54 else: 55 raise NotImplementedError 56 57 # node.train(dataset.samples.T) 58 # self._proj = dataset.samples.T * N.asmatrix(node.get_projmatrix()) 59 # print self._proj.shape 60 # else: 61 node.train(dataset.samples) 62 self._proj = N.asmatrix(node.get_projmatrix()) 63 self._recon = N.asmatrix(node.get_recmatrix())
64