Example #1
0
    def test_ve3d_transforms1(self):
        import VisionEgg.ThreeDeeMath as ve3d
        
        gl.glMatrixMode(gl.GL_PROJECTION)

        # identity
        M = ve3d.TransformMatrix()
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)
                                                
        self.failUnless( Numeric.allclose(ve3d_m, gl_m),
                         'identity matrix different')

        # translate
        args=(10,20,30)
        M = ve3d.TransformMatrix()
        M.translate(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glTranslatef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)
                                                
        self.failUnless( Numeric.allclose(ve3d_m, gl_m),
                         'translation matrix different')
        
        # rotate
        args=(-22.5,10,20,-30)
        M = ve3d.TransformMatrix()
        M.rotate(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glRotatef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)
                                                
        self.failUnless( Numeric.allclose(ve3d_m, gl_m),
                         'rotation matrix different')

        # scale
        args=(1,10.5,123.2)
        M = ve3d.TransformMatrix()
        M.scale(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glScalef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)
                                                
        self.failUnless( Numeric.allclose(ve3d_m, gl_m),
                         'scale matrix different')        
Example #2
0
    def test_ve3d_transforms1(self):
        import VisionEgg.ThreeDeeMath as ve3d

        gl.glMatrixMode(gl.GL_PROJECTION)

        # identity
        M = ve3d.TransformMatrix()
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)

        self.failUnless(Numeric.allclose(ve3d_m, gl_m),
                        'identity matrix different')

        # translate
        args = (10, 20, 30)
        M = ve3d.TransformMatrix()
        M.translate(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glTranslatef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)

        self.failUnless(Numeric.allclose(ve3d_m, gl_m),
                        'translation matrix different')

        # rotate
        args = (-22.5, 10, 20, -30)
        M = ve3d.TransformMatrix()
        M.rotate(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glRotatef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)

        self.failUnless(Numeric.allclose(ve3d_m, gl_m),
                        'rotation matrix different')

        # scale
        args = (1, 10.5, 123.2)
        M = ve3d.TransformMatrix()
        M.scale(*args)
        ve3d_m = M.matrix

        gl.glLoadIdentity()
        gl.glScalef(*args)
        gl_m = gl.glGetFloatv(gl.GL_PROJECTION_MATRIX)

        self.failUnless(Numeric.allclose(ve3d_m, gl_m),
                        'scale matrix different')
Example #3
0
 def copyTest (self):
     "Test how Numeric works with the copy module."
     import copy
     x = Numeric.array([1,2,3])
     y = [1, x, 3]
     c1 = copy.copy(x)
     assert Numeric.allclose(x,c1)
     x[1] = 4
     assert not Numeric.allclose(x,c1)
     c2 = copy.copy(y)
     assert id(c2[1]) == id(Texx)
     c3 = copy.deepcopy(y)
     assert id(c3[1]) != id(x)
     assert Numeric.allclose(c3[1], x)
Example #4
0
    def test_columnwise_fwt_b(self):
        """test thath columnwise fwt works"""

        X = Numeric.ones(8 * 4, Numeric.Float)
        X = Numeric.reshape(X, (8, 4))

        for i in range(8):
            X[i, 0] = i + 1
            X[i, 1] = 1
            X[i, 2] = i + 1
            X[i, 3] = 2

        # Numeric.transpose(X))
        Y = fwt(X)

        Y_ref = Numeric.array(
            [
                [12.72792206135786, sqrt(8), 12.72792206135786, sqrt(32)],
                [-4.38134139536131, 0.0, -4.38134139536131, 0.0],
                [0.36602540378444, 0.0, 0.36602540378444, 0.0],
                [-3.83012701892219, 0.0, -3.83012701892219, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [-2.82842712474619, 0.0, -2.82842712474619, 0.0],
            ]
        )

        Y -= Y_ref
        assert Numeric.allclose(Y, 0)
Example #5
0
    def test_fwt2c(self):

        X = Numeric.ones(8 * 4, Numeric.Float)
        X = Numeric.reshape(X, (8, 4))

        for i in range(8):
            X[i, 0] = 1
            X[i, 1] = 2
            X[i, 2] = 3
            X[i, 3] = 4

        Y_ref = Numeric.array(
            [
                [14.14213562373095, -4.89897948556636, 0.0, -4.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
            ]
        )

        Y = fwt2(X)

        Y -= Y_ref
        assert Numeric.allclose(Y, 0)
Example #6
0
    def test_fwt1Db(self):
        """test that fwt1D works on example vectors"""

        D = 4
        N = 8
        X = Numeric.zeros(N, Numeric.Float)

        for i in range(len(X)):
            X[i] = i + 1

        Y = fwt(X, D)

        Y = Y - Numeric.array(
            [
                12.72792206135786,
                -4.38134139536131,
                0.36602540378444,
                -3.83012701892219,
                0.0,
                0.0,
                0.0,
                -2.82842712474619,
            ]
        )
        assert Numeric.allclose(Y, 0)
Example #7
0
    def test_fwt1Dc8(self):
        """test that fwt1D works on a 'random' vector, D=8"""

        # Matlab random vector
        X = Numeric.array(
            [
                0.81797434083925,
                0.66022755644160,
                0.34197061827022,
                0.28972589585624,
                0.34119356941488,
                0.53407901762660,
                0.72711321692968,
                0.30929015979096,
            ]
        )

        # Result from fwt(X, 8) in Matlab
        Y_ref = Numeric.array(
            [
                1.42184125586417,
                -0.27774330567583,
                0.26539391030148,
                0.02521137886213,
                0.13638973750197,
                0.31441497909028,
                -0.20260945655043,
                0.05934606703242,
            ]
        )

        Y = fwt(X, 8)
        assert Numeric.allclose(Y - Y_ref, 0)
Example #8
0
    def test_fwt1Dc6(self):
        """test that fwt1D works on a 'random' vector, D=6"""

        # Matlab random vector
        X = Numeric.array(
            [
                0.81797434083925,
                0.66022755644160,
                0.34197061827022,
                0.28972589585624,
                0.34119356941488,
                0.53407901762660,
                0.72711321692968,
                0.30929015979096,
            ]
        )

        # Result from fwt(X, 6) in Matlab
        Y_ref = Numeric.array(
            [
                1.42184125586417,
                -0.27979815817808,
                0.21836186329686,
                0.17939935114879,
                0.00345049516774,
                0.22893484261518,
                0.25762577687352,
                -0.18246978758220,
            ]
        )

        Y = fwt(X, 6)
        assert Numeric.allclose(Y - Y_ref, 0)
Example #9
0
    def test_fwt1Dc4(self):
        """test that fwt1D works on a 'random' vector, D=4"""

        # Matlab random vector
        X = Numeric.array(
            [
                0.81797434083925,
                0.66022755644160,
                0.34197061827022,
                0.28972589585624,
                0.34119356941488,
                0.53407901762660,
                0.72711321692968,
                0.30929015979096,
            ]
        )

        # Result from fwt(X, 4) in Matlab
        Y_ref = Numeric.array(
            [
                1.42184125586417,
                -0.15394808354817,
                0.05192707167183,
                0.37115044369886,
                -0.10770249228974,
                -0.08172091206233,
                0.29500215027890,
                0.20196258114742,
            ]
        )

        Y = fwt(X, 4)
        assert Numeric.allclose(Y - Y_ref, 0)
Example #10
0
    def test_fwt2d(self):

        X = Numeric.ones(8 * 4, Numeric.Float)
        X = Numeric.reshape(X, (8, 4))

        for i in range(8):
            X[i, 0] = i + 1
            X[i, 1] = 1
            X[i, 2] = i + 1
            X[i, 3] = 2

        Y_ref = Numeric.array(
            [
                [16.97056274847714, -1.93185165257814, 5.63397459621556, 6.3660254037844],
                [-4.38134139536131, 0.0, -3.09807621135332, -3.09807621135332],
                [0.36602540378444, 0.0, 0.25881904510252, 0.25881904510252],
                [-3.83012701892219, 0.0, -2.70830878788570, -2.70830878788570],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [0.0, 0.0, 0.0, 0.0],
                [-2.82842712474619, 0.0, -2.0, -2.0],
            ]
        )

        Y = fwt2(X)

        Y -= Y_ref
        assert Numeric.allclose(Y, 0)
Example #11
0
    def test_ifwt1D_basic(self):
        """test that ifwt1D works basically"""

        X = Numeric.ones(8, Numeric.Float)
        Y = fwt(X)
        X1 = ifwt(Y)
        assert Numeric.allclose(X - X1, 0)
Example #12
0
    def test_fwt1Dc(self):
        """test that fwt1D works as a 2D vector"""

        X = Numeric.ones(8, Numeric.Float)
        X = Numeric.reshape(X, (8, 1))

        Y = fwt(X)

        Y[0][0] -= sqrt(len(Y))
        assert Numeric.allclose(Y, 0)
Example #13
0
    def test_big(self):
        from RandomArray import seed, random

        seed(13, 17)

        X = random((1024, 512))

        Y = fwt2(X)
        X1 = ifwt2(Y)
        assert Numeric.allclose(X - X1, 0)
Example #14
0
    def test_fwt2b(self):
        """Simple 2D test.....
        """

        X = Numeric.ones(8 * 4, Numeric.Float)
        X = Numeric.reshape(X, (8, 4))

        Y = fwt2(X)

        Y[0][0] -= sqrt(Numeric.product(Y.shape))
        assert Numeric.allclose(Y, 0)
Example #15
0
    def test_ctor(self):
	self.assertRaises(AttributeError, PlotData, StringIO("0 0 0\n1 1 1"))
	self.assertEqual(self.o.data.shape, (5, 5), 'incorrect shape for data')
	i = 0;
	for expect in [[-3.0, -2.5, -2.0, -1.5, -1.0],
		       [-0.5,  0.0,  0.5,  1.0,  1.5],
		       [ 2.0,  2.5,  3.0,  3.5,  4.0],
		       [ 4.5,  5.0,  5.5,  6.0,  6.5],
		       [ 7.0,  7.5,  8.0,  8.5,  9.0]]:
	    self.failUnless(
		Numeric.allclose(self.o.data[i], expect),
		'incorrect values in row %d'%i)
	    i+=1
Example #16
0
    def test_ifwt1D_inverse_b(self):
        """test that fwt1D works as an inverse to ifwt"""

        for j in range(1, 9):
            N = 2 ** j
            for P in range(number_of_filters):
                D = 2 * (P + 1)

                X = Numeric.ones(N, Numeric.Float)
                Y = ifwt(X, D)

                X1 = fwt(Y, D)
                assert Numeric.allclose(X - X1, 0)
Example #17
0
    def test_fwt1Da(self):
        """test that fwt1D works on constant vector: ones"""

        for j in range(1, 9):
            N = 2 ** j
            for P in range(number_of_filters):
                D = 2 * (P + 1)

                X = Numeric.ones(N, Numeric.Float)
                Y = fwt(X, D)

                Y[0] -= sqrt(len(Y))
                assert Numeric.allclose(Y, 0)
Example #18
0
    def test_columnwise_fwt_a(self):
        """test thath columnwise fwt works"""

        X = Numeric.ones(8 * 4, Numeric.Float)
        X = Numeric.reshape(X, (8, 4))

        Y = fwt(X)

        rows, cols = Y.shape
        for i in range(cols):
            Y[0, i] -= sqrt(rows)

        assert Numeric.allclose(Y, 0)
Example #19
0
    def test_ifwt2c(self):

        from RandomArray import seed, random

        seed(13, 17)

        X = random((8, 4))

        Y = ifwt2(X)
        Y = ifwt2(Y)

        Y = fwt2(Y)
        X1 = fwt2(Y)
        assert Numeric.allclose(X - X1, 0)
Example #20
0
def eq (a, b):
    "Test if the two sequences are essentially equal"
    seq_a = has_length(a)
    seq_b = has_length(b)
    if (seq_a and not seq_b) or (not seq_a and seq_b):
        raise ValueError(
            "trying to compare a sequence and non-sequence: a=%r b=%r" %
            (a,b))
    aa = Numeric.asarray(a)
    ab = Numeric.asarray(b)
    if aa.shape != ab.shape:
        raise ValueError("sequences have different shapes:\na%s=%r\nb%s=%r" %
                         (aa.shape, a, ab.shape, b))
    return Numeric.allclose(aa,ab)
Example #21
0
    def test_scale_energy(self):
        D = 4
        N = 8
        d = 3

        X = Numeric.zeros(N, Numeric.Float)

        for i in range(len(X)):
            X[i] = i + 1

        Wx = fwt(X, D, d)

        Evec = scale_energy(Wx, d + 1)  # All details + avg

        Evec_ref = Numeric.array([0.03921568627451, 0.07256788028085, 0.09409878638582, 0.79411764705882])

        assert Numeric.allclose(Evec - Evec_ref, 0)
 def add_event(self, real, pred, n=1):
     c2m = self._class2matrix.copy()
     summed = self._sum
     if real == pred:  # hit; update the true positives
         c2m.pop(real)[0, 0] += n
         summed[0, 0] += n
     else:  # miss
         # update the false positives for the predicted category
         c2m.pop(pred)[0, 1] += n
         summed[0, 1] += n
         # update the false negatives for the real category
         c2m.pop(real)[1, 0] += n
         summed[1, 0] += n
     # update the true negative for all other categories
     for m in c2m.itervalues():
         m[1, 1] += n
     summed[1, 1] += n * len(c2m)
     assert Num.allclose(self._sum, sum(self._class2matrix.itervalues()))
 def add_event(self, real, pred, n=1):
     c2m = self._class2matrix.copy()
     summed = self._sum
     if real == pred:  # hit; update the true positives
         c2m.pop(real)[0, 0] += n
         summed[0, 0] += n
     else:  # miss
         # update the false positives for the predicted category
         c2m.pop(pred)[0, 1] += n
         summed[0, 1] += n
         # update the false negatives for the real category
         c2m.pop(real)[1, 0] += n
         summed[1, 0] += n
     # update the true negative for all other categories
     for m in c2m.itervalues():
         m[1, 1] += n
     summed[1, 1] += n * len(c2m)
     assert Num.allclose(self._sum, sum(self._class2matrix.itervalues()))
 def basetest(self):
     sasdata = csv_to_ds(os.path.join(thisdir, self.sasresults_file))
     summset = event_ds.summ('sex', 'region', zeros=True,
                             filterexpr=self.e_filterexpr)
     stdsumset = event_ds.summ('agegrp', 'sex', zeros=True,
                             filterexpr=self.s_filterexpr)
     ind = calc_ind(summset, pop_ds, stdsumset, pop_ds,
                 conflev=self.conflev, 
                 popset_popcol='pop', stdpopset_popcol='pop')
     sasct = CrossTab.from_summset(sasdata)
     indct = CrossTab.from_summset(ind, shaped_like=sasct)
     for colname in colnames:
         a = sasct[colname].data
         b = indct[colname].data.filled(0)
         if not Numeric.allclose(a, b):
             if 0:
                 print
                 print ind
                 print a
                 print b
             self.fail('%s not equal' % colname)
Example #25
0

if numproc > 1:
  # Test simple raw communication (arrays, strings and general)
  #
  N = 17 #Number of elements
  
  if myid == 0:
    # Integer arrays
    #
    A = Numeric.array(range(N))
    B = Numeric.zeros(N)    
    pypar.raw_send(A,1)
    pypar.raw_receive(B,numproc-1)
    
    assert Numeric.allclose(A, B)
    print "Raw communication of numeric integer arrays OK"

    # Real arrays
    #
    A = Numeric.array(range(N)).astype('f')
    B = Numeric.zeros(N).astype('f')    
    pypar.raw_send(A,1)
    pypar.raw_receive(B,numproc-1)
    
    assert Numeric.allclose(A, B)    
    print "Raw communication of numeric real arrays OK"

    # Strings (< 256 characters)
    #
    A = "and now to something completely different !"
Example #26
0
    def assertClose(self, result, expect, message='failed'):
	self.failUnless(Numeric.allclose(result, expect),
	    '%s: expected: %s, actual: %s'%(message, str(expect), str(result)))