1
2
3
4
5
6
7
8
9 """FeaturewiseDatasetMeasure performing a univariate ANOVA."""
10
11 __docformat__ = 'restructuredtext'
12
13 import numpy as N
14
15 from mvpa.measures.base import FeaturewiseDatasetMeasure
16
17
18
19
20
21
22
23
24
25
26
27
29 """`FeaturewiseDatasetMeasure` that performs a univariate ANOVA.
30
31 F-scores are computed for each feature as the standard fraction of between
32 and within group variances. Groups are defined by samples with unique
33 labels.
34
35 No statistical testing is performed, but raw F-scores are returned as a
36 sensitivity map. As usual F-scores have a range of [0,inf] with greater
37 values indicating higher sensitivity.
38 """
39
40 - def _call(self, dataset, labels=None):
41 """Computes featurewise f-scores using simple comparisons."""
42
43 means = []
44
45 vars_ = []
46
47
48 if labels is None:
49 labels = dataset.labels
50
51
52 for ul in N.unique(labels):
53 ul_samples = dataset.samples[labels == ul]
54 means.append(ul_samples.mean(axis=0))
55 vars_.append(ul_samples.var(axis=0))
56
57
58 mvw = N.array(vars_).mean(axis=0)
59
60 vgm = N.array(means).var(axis=0)
61
62
63
64
65
66
67
68
69
70
71
72
73
74 vgm0 = vgm.nonzero()
75 vgm[vgm0] /= mvw[vgm0]
76
77 return vgm
78
79
81 """Compound comparisons via univariate ANOVA.
82
83 Provides F-scores per each label if compared to the other labels.
84 """
85
86 - def _call(self, dataset):
87 """Computes featurewise f-scores using compound comparisons."""
88
89 orig_labels = dataset.labels
90 labels = orig_labels.copy()
91
92 results = []
93 for ul in dataset.uniquelabels:
94 labels[orig_labels == ul] = 1
95 labels[orig_labels != ul] = 2
96 results.append(OneWayAnova._call(self, dataset, labels))
97
98
99 return N.array(results).T
100