Package mvpa :: Package measures :: Module splitmeasure
[hide private]
[frames] | no frames]

Source Code for Module mvpa.measures.splitmeasure

 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  """This is a `FeaturewiseDatasetMeasure` that uses another 
10  `FeaturewiseDatasetMeasure` and runs it multiple times on differents splits of 
11  a `Dataset`. 
12  """ 
13   
14  __docformat__ = 'restructuredtext' 
15   
16  from mvpa.measures.base import FeaturewiseDatasetMeasure 
17  from mvpa.datasets.splitter import NoneSplitter 
18  from mvpa.misc.state import StateVariable 
19  from mvpa.misc.transformers import FirstAxisMean 
20   
21 -class SplitFeaturewiseMeasure(FeaturewiseDatasetMeasure):
22 """This is a `FeaturewiseDatasetMeasure` that uses another 23 `FeaturewiseDatasetMeasure` and runs it multiple times on differents 24 splits of a `Dataset`. 25 26 When called with a `Dataset` it returns the mean sensitivity maps of all 27 data splits. 28 29 Additonally this class supports the `State` interface. Several 30 postprocessing functions can be specififed to the constructor. The results 31 of the functions specified in the `postproc` dictionary will be available 32 via their respective keywords. 33 """ 34 35 maps = StateVariable(enabled=False, 36 doc="To store maps per each split") 37
38 - def __init__(self, sensana, 39 splitter=NoneSplitter, 40 combiner=FirstAxisMean, 41 **kwargs):
42 """Cheap initialization. 43 44 :Parameters: 45 sensana : FeaturewiseDatasetMeasure 46 that shall be run on the `Dataset` splits. 47 splitter : Splitter 48 used to split the `Dataset`. By convention the first dataset 49 in the tuple returned by the splitter on each iteration is used 50 to compute the sensitivity map. 51 combiner 52 This functor will be called on an array of sensitivity maps 53 and the result will be returned by __call__(). The result of 54 a combiner must be an 1d ndarray. 55 """ 56 # init base classes first 57 FeaturewiseDatasetMeasure.__init__(self, **kwargs) 58 59 self.__sensana = sensana 60 """Sensitivity analyzer used to compute the sensitivity maps. 61 """ 62 self.__splitter = splitter 63 """Splitter instance used to split the datasets.""" 64 self.__combiner = combiner 65 """Function to combine sensitivities to serve a result of 66 __call__()"""
67 68
69 - def _call(self, dataset):
70 """Compute sensitivity maps for all dataset splits and run the 71 postprocessing functions afterward (if any). 72 73 Returns a list of all computed sensitivity maps. Postprocessing results 74 are available via the objects `State` interface. 75 """ 76 77 maps = [] 78 79 # splitter 80 for split in self.__splitter(dataset): 81 # compute sensitivity using first dataset in split 82 sensitivity = self.__sensana(split[0]) 83 84 maps.append(sensitivity) 85 86 self.maps = maps 87 """Store the maps across splits""" 88 89 # return all maps 90 return self.__combiner(maps)
91