~scipystats/+junk/skipper-revjp

« back to all changes in this revision

Viewing changes to nipy/fixes/scipy/stats/models/tests/test_tools.py

  • Committer: joep
  • Date: 2009-08-17 03:43:53 UTC
  • mfrom: (1799.1.26 skipper-working)
  • Revision ID: josef.pktd@gmail.com-20090817034353-ktg588ju3qhmruvq
merge from Skipper, trying to clear up move, keeping history

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
"""
 
2
Test functions for models.tools
 
3
"""
 
4
 
 
5
import numpy as np
 
6
import numpy.random as R
 
7
from numpy.testing import *
 
8
 
 
9
from models import tools
 
10
 
 
11
class TestTools(TestCase):
 
12
 
 
13
    def test_recipr(self):
 
14
        X = np.array([[2,1],[-1,0]])
 
15
        Y = tools.recipr(X)
 
16
        assert_almost_equal(Y, np.array([[0.5,1],[0,0]]))
 
17
 
 
18
    def test_recipr0(self):
 
19
        X = np.array([[2,1],[-4,0]])
 
20
        Y = tools.recipr0(X)
 
21
        assert_almost_equal(Y, np.array([[0.5,1],[-0.25,0]]))
 
22
 
 
23
    def test_rank(self):
 
24
        X = R.standard_normal((40,10))
 
25
        self.assertEquals(tools.rank(X), 10)
 
26
 
 
27
        X[:,0] = X[:,1] + X[:,2]
 
28
        self.assertEquals(tools.rank(X), 9)
 
29
 
 
30
    def test_fullrank(self):
 
31
        X = R.standard_normal((40,10))
 
32
        X[:,0] = X[:,1] + X[:,2]
 
33
 
 
34
        Y = tools.fullrank(X)
 
35
        self.assertEquals(Y.shape, (40,9))
 
36
        self.assertEquals(tools.rank(Y), 9)
 
37
 
 
38
        X[:,5] = X[:,3] + X[:,4]
 
39
        Y = tools.fullrank(X)
 
40
        self.assertEquals(Y.shape, (40,8))
 
41
        self.assertEquals(tools.rank(Y), 8)
 
42
 
 
43
    def test_StepFunction(self):
 
44
        x = np.arange(20)
 
45
        y = np.arange(20)
 
46
        f = tools.StepFunction(x, y)
 
47
        assert_almost_equal(f( np.array([[3.2,4.5],[24,-3.1]]) ), [[ 3, 4], [19, 0]])
 
48
 
 
49
    def test_StepFunctionBadShape(self):
 
50
        x = np.arange(20)
 
51
        y = np.arange(21)
 
52
        self.assertRaises(ValueError, tools.StepFunction, x, y)
 
53
        x = np.zeros((2, 2))
 
54
        y = np.zeros((2, 2))
 
55
        self.assertRaises(ValueError, tools.StepFunction, x, y)
 
56
 
 
57
 
 
58