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

Source Code for Module mvpa.mappers.base

 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  from mvpa.misc.vproperty import VProperty 
14  from mvpa.base.dochelpers import enhancedDocString 
15   
16   
17 -class Mapper(object):
18 """Interface to provide mapping between two spaces: in and out. 19 Methods are prefixed correspondingly. forward/reverse operate 20 on the entire dataset. get(In|Out)Id[s] operate per element:: 21 22 forward 23 in ---------> out 24 <--------/ 25 reverse 26 27 Subclasses should define 'dsshape' and 'nfeatures' properties that point to 28 `getInShape` and `getOutSize` respectively. This cannot be 29 done in the baseclass as standard Python properties would still point to 30 the baseclass methods. 31 """
32 - def __init__(self):
33 """Does nothing.""" 34 pass
35 36 37 __doc__ = enhancedDocString('Mapper', locals()) 38 39
40 - def forward(self, data):
41 """Map data from the original dataspace into featurespace. 42 """ 43 raise NotImplementedError
44 45
46 - def __call__(self, data):
47 """Calls the mappers forward() method. 48 """ 49 return self.forward(data)
50 51
52 - def reverse(self, data):
53 """Reverse map data from featurespace into the original dataspace. 54 """ 55 raise NotImplementedError
56 57
58 - def train(self, dataset):
59 """Sub-classes have to override this method if the mapper need 60 training. 61 """ 62 pass
63 64
65 - def getInShape(self):
66 """Returns the dimensionality specification of the original dataspace. 67 68 XXX -- should be deprecated and might be substituted 69 with functions like getEmptyFrom / getEmptyTo 70 """ 71 raise NotImplementedError
72 73
74 - def getOutShape(self):
75 """ 76 Returns the shape (or other dimensionality speicification) 77 of the destination dataspace. 78 """ 79 raise NotImplementedError
80 81
82 - def getInSize(self):
83 """Returns the size of the entity in input space""" 84 raise NotImplementedError
85 86
87 - def getOutSize(self):
88 """Returns the size of the entity in output space""" 89 raise NotImplementedError
90 91
92 - def selectOut(self, outIds):
93 """Remove some elements and leave only ids in 'out'/feature space""" 94 raise NotImplementedError
95 96 97 nfeatures = VProperty(fget=getOutSize)
98