Package mvpa :: Package tests :: Module test_gpr
[hide private]
[frames] | no frames]

Source Code for Module mvpa.tests.test_gpr

 1  # emacs: -*- mode: python; py-indent-offset: 4; indent-tabs-mode: nil -*- 
 2  # vi: set ft=python 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  """Unit tests for PyMVPA GPR.""" 
10   
11  import unittest 
12   
13  from mvpa.base import externals 
14   
15  from mvpa.misc import data_generators 
16  from mvpa.clfs.kernel import KernelLinear as GeneralizedLinearKernel 
17  from mvpa.clfs.gpr import GPR 
18   
19  from tests_warehouse import * 
20  from numpy.testing import assert_array_equal, assert_array_almost_equal 
21   
22  if __debug__: 
23      from mvpa.base import debug 
24       
25   
26 -class GPRTests(unittest.TestCase):
27
28 - def test_basic(self):
29 dataset = data_generators.linear1d_gaussian_noise() 30 k = GeneralizedLinearKernel() 31 clf = GPR(k) 32 clf.train(dataset) 33 y = clf.predict(dataset.samples) 34 assert_array_equal(y.shape, dataset.labels.shape)
35
36 - def test_linear(self):
37 pass
38
40 """Smoke test for running model selection while getting GPRWeights 41 """ 42 if not externals.exists('openopt'): 43 return 44 45 dataset = datasets['uni2small'] #data_generators.linear1d_gaussian_noise() 46 k = GeneralizedLinearKernel() 47 clf = GPR(k, enable_states=['log_marginal_likelihood']) 48 sa = clf.getSensitivityAnalyzer() # should be regular weights 49 sa_ms = clf.getSensitivityAnalyzer(flavor='model_select') # with model selection 50 def prints(): 51 print clf.states.log_marginal_likelihood, clf.kernel.Sigma_p, clf.kernel.sigma_0
52 53 sa(dataset) 54 lml = clf.states.log_marginal_likelihood 55 56 sa_ms(dataset) 57 lml_ms = clf.states.log_marginal_likelihood 58 59 self.failUnless(lml_ms > lml)
60 61 62
63 -def suite():
64 return unittest.makeSuite(GPRTests)
65 66 67 if __name__ == '__main__': 68 import runner 69