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
42
43
44
45
46
47
48 if labels is None:
49 labels = dataset.labels
50
51 ul = N.unique(labels)
52
53 na = len(ul)
54 bign = float(dataset.nsamples)
55 alldata = dataset.samples
56
57
58 sostot = N.sum(alldata, axis=0)
59 sostot *= sostot
60 sostot /= bign
61
62
63 sstot = N.sum(alldata * alldata, axis=0) - sostot
64
65
66 ssbn = 0
67 for l in ul:
68
69 d = alldata[labels == l]
70 sos = N.sum(d, axis=0)
71 sos *= sos
72 ssbn += sos / float(len(d))
73
74 ssbn -= sostot
75
76 sswn = sstot - ssbn
77
78
79 dfbn = na-1
80 dfwn = bign - na
81
82
83 msb = ssbn / float(dfbn)
84 msw = sswn / float(dfwn)
85 f = msb / msw
86
87
88
89
90
91 f[N.isnan(f)] = 0
92
93 return f
94
95
96
97
98
99
101 """Compound comparisons via univariate ANOVA.
102
103 Provides F-scores per each label if compared to the other labels.
104 """
105
106 - def _call(self, dataset):
107 """Computes featurewise f-scores using compound comparisons."""
108
109 orig_labels = dataset.labels
110 labels = orig_labels.copy()
111
112 results = []
113 for ul in dataset.uniquelabels:
114 labels[orig_labels == ul] = 1
115 labels[orig_labels != ul] = 2
116 results.append(OneWayAnova._call(self, dataset, labels))
117
118
119 return N.array(results).T
120