1
2
3
4
5
6
7
8
9 """Provide sensitivity measures for sg's SVM."""
10
11 __docformat__ = 'restructuredtext'
12
13 import numpy as N
14
15 import shogun.Classifier
16
17 from mvpa.misc.state import StateVariable
18 from mvpa.measures.base import Sensitivity
19
20 if __debug__:
21 from mvpa.base import debug
22
23
25 """`Sensitivity` that reports the weights of a linear SVM trained
26 on a given `Dataset`.
27 """
28
29 biases = StateVariable(enabled=True,
30 doc="Offsets of separating hyperplanes")
31
33 """Initialize the analyzer with the classifier it shall use.
34
35 :Parameters:
36 clf: LinearSVM
37 classifier to use. Only classifiers sub-classed from
38 `LinearSVM` may be used.
39 """
40
41 Sensitivity.__init__(self, clf, **kwargs)
42
43
45 """Helper function to compute sensitivity for a single given SVM"""
46 self.offsets = svm.get_bias()
47 svcoef = N.matrix(svm.get_alphas())
48 svnums = svm.get_support_vectors()
49 svs = self.clf.traindataset.samples[svnums,:]
50 res = (svcoef * svs).mean(axis=0).A1
51 return res
52
53
54 - def _call(self, dataset):
66