Package mvpa :: Package mappers :: Module ica

[hide private]
[frames] | no frames]

# Source Code for Module mvpa.mappers.ica

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