Package mvpa :: Package tests :: Module test_zscoremapper

[hide private]
[frames] | no frames]

# Source Code for Module mvpa.tests.test_zscoremapper

     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 ZScore mapper"""
    10
    11
    12  import unittest
    13
    14  from mvpa.base import externals
    15  externals.exists('scipy', raiseException=True)
    16
    17  from mvpa.support.copy import deepcopy
    18  import numpy as N
    19
    20  from mvpa.datasets import Dataset
    21  from mvpa.mappers.zscore import ZScoreMapper
    22  from mvpa.datasets.miscfx import zscore
    23
    24  from tests_warehouse import datasets
    25
    26 -class ZScoreMapperTests(unittest.TestCase):
    27      """Test simple ZScoreMapper
    28      """
    29
    30 -    def setUp(self):
    31          """Setup sample datasets
    32          """
    33          # data: 40 sample feature line in 20d space (40x20; samples x features)
    34          self.dss = [
    35              Dataset(samples=N.concatenate(
    36                  [N.arange(40) for i in range(20)]).reshape(20,-1).T,
    37                      labels=1, chunks=1),
    38              ] + datasets.values()
    39
    40
    41 -    def testCompareToZscore(self):
    42          """Test by comparing to results of elderly z-score function
    43          """
    44          for ds in self.dss:
    45              ds1 = deepcopy(ds)
    46              ds2 = deepcopy(ds)
    47
    48              zsm = ZScoreMapper()
    49              zsm.train(ds1)
    50              ds1z = zsm.forward(ds1.samples)
    51
    52              zscore(ds2, perchunk=False)
    53              self.failUnless(N.linalg.norm(ds1z - ds2.samples) < 1e-12)
    54              self.failUnless((ds1.samples == ds.samples).all(),
    55                              msg="It seems we modified original dataset!")
    56
    57              ds0 = zsm.reverse(ds1z)
    58              self.failUnless(N.linalg.norm(ds0 - ds.samples) < 1e-12,
    59                              msg="Can't reconstruct from z-scores")
    60
    61
    62 -def suite():
    63      return unittest.makeSuite(ZScoreMapperTests)
    64
    65
    66  if __name__ == '__main__':
    67      import runner
    68