1
2
3
4
5
6
7
8
9 """Mapped dataset"""
10
11 __docformat__ = 'restructuredtext'
12
13 import copy
14
15 from mvpa.datasets import Dataset
16
17
19 """A `Dataset` which is created by applying a `Mapper` to the data.
20
21 It uses a mapper to transform samples from their original
22 dataspace into the feature space. Various mappers can be used. The
23 "easiest" one is `MaskMapper` which allows to select the features
24 (voxels) to be used in the analysis: see `MaskedDataset`
25 """
26
27 - def __init__(self, samples=None, mapper=None, dsattr=None, **kwargs):
28 """Initialize `MaskedDataset`
29
30 :Parameters:
31 - `mapper`: Instance of `Mapper` used to map input data
32
33 """
34
35
36
37
38
39 if dsattr is None:
40 dsattr = {}
41
42
43
44 if not mapper is None:
45
46
47 dsattr['mapper'] = mapper
48
49
50
51 if not samples is None:
52 if dsattr['mapper'] is None:
53 raise ValueError, \
54 "Constructor of MappedDataset requires a mapper " \
55 "if unmapped samples are provided."
56 Dataset.__init__(self,
57 samples=mapper.forward(samples),
58 dsattr=dsattr,
59 **(kwargs))
60 else:
61 Dataset.__init__(self, dsattr=dsattr, **(kwargs))
62
63
64
66 """Map data from the original dataspace into featurespace.
67 """
68 return self.mapper.forward(data)
69
70
72 """Reverse map data from featurespace into the original dataspace.
73 """
74 return self.mapper.reverse(data)
75
76
78 """Select features given their ids.
79
80 :Parameters:
81 - `ids`: iterable container to select ids
82 - `plain`: `bool`, if to return MappedDataset (or just Dataset)
83 - `sort`: `bool`, if to sort Ids. Order matters and selectFeatures
84 assumes incremental order. If not such, in non-optimized
85 code selectFeatures would verify the order and sort
86 """
87
88
89 if plain:
90 sdata = Dataset(self._data, self._dsattr, check_data=False,
91 copy_samples=False, copy_data=False,
92 copy_dsattr=False)
93 return sdata.selectFeatures(ids, sort)
94 else:
95 sdata = Dataset.selectFeatures(self, ids)
96
97 sdata._dsattr['mapper'] = copy.deepcopy(sdata._dsattr['mapper'])
98 sdata._dsattr['mapper'].selectOut(ids, sort)
99 return sdata
100
101
102
103 mapper = property(fget=lambda self: self._dsattr['mapper'])
104